Rawkit is a CGO wrapper around LibRaw that lets Go programs open and manipulate RAW image files without needing a C compiler or external dependencies.
Install rawkit using Go tooling:
go get github.com/tlaceby/rawkit@latest
package main
import (
"fmt"
"github.com/tlaceby/rawkit"
)
func main() {
img, err := rawkit.LoadRAW("example.ARW")
if err != nil {
panic(err)
}
fmt.Printf("Image: %dx%d | Channels: %d | Buffer Size: %d\n",
img.Width, img.Height, img.Colors, len(img.Buffer))
fmt.Println("Camera:", img.CameraMake, img.CameraModel)
fmt.Println("Lens:", img.FocalLength, "mm f/", img.Aperature)
fmt.Println("Exposure:", img.ShutterSpeed, "sec ISO", img.ISO)
fmt.Println("Artist:", img.Artist)
}
View the API Documentation to see all avbailable types and methods which Rawkit provides.
Rawkit aims to be full of useful features which make working with RAW and Non-RAW Images easier. Below are some of the additional functions/methods you can use to work with Images in Rawkit.
// Get luminance histogram data from RAW image
img, _ := rawkit.GetUnderlyingImageFromFile("my-image.ARW", true) // with with most common and (RAW) image types
h := histograms.HistogramFromImage(img)
// Create image
if err = h.CreateRGBHistogramImage("histogram-RGB.png", histograms.DefaultHistogramOptions()); err != nil {
panic(err)
}
// Using custom properties
opts := rawkit.DefaultHistogramOptions()
opts.LuminanceLineColor = color.RGBA{0, 255, 255, 255} // cyan
opts.GenerateLuminanceImage = true
opts.height = 1920
opts.Width = 1080
opts.ShowGrid = false
if err = h.CreateRGBHistogramImage("histogram-LuminancePeaks.png", opts); err != nil {
panic(err)
}
- Camera:
CameraMake
,CameraModel
- Exposure:
ShutterSpeed
,Aperature
,FocalLength
,ISO
- Image:
Width
,Height
,Colors
,Flip
- Other:
Artist
,DNGVersion
,RawCount
,AsShotWBApplied
Pixel data is accessible in img.Buffer
as []uint16
representing unpacked pixels in channel-major order.
- Bug reports - open an issue with steps to reproduce
- Pull requests - fork, branch, commit, ensure
go test ./...
passes - Code style - use idiomatic Go and minimal C++
To add new functionality:
- Bridge (
wrapper/
) - Addextern "C"
function towrapper.cpp/.h
- Expose (
rawkit/
) - Declare function in CGO preamble and wrap in Go - Test (
tests/
) - Add Go test with test files intests/testdata/
- Verify - Run
make release
to build, test, and bump version
make verify
make release
This builds LibRaw and the wrapper, runs tests, and bumps the version if tests pass.