go-libraw provides Go bindings to LibRaw
for reading and processing of RAW digicam images.
go-libraw targets Linux and macOS (amd64, arm64). Windows is out of
scope; see the Support Matrix for details.
- Go
1.26or newer, as declared bygo.mod - cgo enabled
- LibRaw
0.21or newer (libraw-devor equivalent) - a C/C++ toolchain for the target platform
Install LibRaw on common platforms:
# macOS
brew install libraw
# Debian/Ubuntu
sudo apt-get update
sudo apt-get install -y libraw-dev pkg-config
# Fedora
sudo dnf install LibRaw-devel pkgconf-pkg-configVerify local discovery:
make libraw-checkSee LibRaw Build Setup and the Support Matrix for platform details.
go get github.com/strawberryworks/go-libraw/pkg/librawpackage main
import (
"log"
libraw "github.com/strawberryworks/go-libraw/pkg/libraw"
)
func main() {
processor, err := libraw.NewProcessor()
if err != nil {
log.Fatal(err)
}
defer func() {
if err := processor.Close(); err != nil {
log.Fatal(err)
}
}()
if err := processor.OpenFile("input.cr2"); err != nil {
log.Fatal(err)
}
if err := processor.Unpack(); err != nil {
log.Fatal(err)
}
if err := processor.DcrawProcess(); err != nil {
log.Fatal(err)
}
if err := processor.WritePPMTiff("output.ppm"); err != nil {
log.Fatal(err)
}
}Run the bundled example on checked-in fixtures:
make examples
make cleanThe sample commands are mapped to upstream LibRaw samples in LibRaw Sample Parity Examples.
Processorowns one LibRaw handle. Create it withNewProcessor, then callClosewhen finished.- Opening input with
OpenFile,OpenBuffer, orOpenBayerprepares metadata and decoder state. - Processing follows LibRaw order: open, optionally set params,
Unpack,DcrawProcessor lower-level image operations, then write or copy output. Metadatareturns a Go snapshot of LibRaw metadata and maker-note summaries.- Raw image, thumbnail, and memory image helpers return Go-owned data.
- LibRaw error codes are returned as Go errors; use
ErrorCodeandStrErrorwhen you need to inspect an underlying LibRaw status.
- Lifecycle And Processing
- Memory And Cgo Safety
- API Coverage Guide
- Versioning Policy
- Release Checklist
- Upstream Sync
- LibRaw API Inventory
- Metadata Coverage
- Maker-Notes Coverage
- Output And Raw Params Coverage
The generated inventory in docs/libraw-api-inventory.md
tracks LibRaw symbols from the fixture headers and marks each as wrapped,
internal, deferred, unsupported, or unmapped. Run this before changing
coverage-related code:
make check-api-inventoryTo regenerate the inventory after updating the coverage map:
make api-inventoryThe Go binding code in this repository is licensed under the MIT License; see LICENSE. That license covers only this project's own code.
go-libraw links the third-party LibRaw library
(dual-licensed CDDL-1.0 OR LGPL-2.1-or-later) and checks in copies of LibRaw's
public headers under testdata/headers/libraw/, which remain under LibRaw's
license rather than MIT. Software you build and distribute from this binding
links LibRaw and must satisfy LibRaw's license. See
THIRD-PARTY-NOTICES.md for the full attribution and
distribution notes (including static-linking guidance), and licenses/ for the
complete LibRaw license texts.
