rawparser

package module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2022 License: MIT Imports: 11 Imported by: 1

README

RawParser Build Status GoDoc Go Walker status

Overview

RawParser is a GO library for extracting: the embedded JPEGs from a camera RAW file and metadata. It's current incarnation parses TIFF-based RAW files. There are existing tools that perform this or similar functionality; however, the reasons for creating this tool:

  1. I have many RAW files that are processed using commercial software, yet on occassion, I would like the camera-produced JPEG for comparison.
  2. To utilize the concurrency model provided by the GO language to process multiple files without any explicit "traditional" locking (e.g, mutexes)
  3. Experiment with GO's "C" package and interfacing with existing C libraries.

My jpegextract utility utilizes this library and may serve as a usage example.

Dependencies

  • GO 1.2 (maybe older GO 1.1.2? but not tested)
  • Optional (highly-recommended):

Usage

  • Obtain the library:

go get github.com/jeremytorres/rawparser

  • Execute the tests
cd $GOPATH/src/github.com/jeremytorres/rawparser

Test with GO's image/jpeg library:

go test

Test with libjpeg library:

go test -tags jpeg

Test with turbojpeg library:

go test -tags turbojpeg

Test with standalone c++ library:

go test -tags jpegcpp

Current Development Status
  • I consider the current status a beta version as there is a laundry list of this I will like to support:
    • Add performance benchmarks
    • Add additional camera RAW file support
    • Create a "better" parser interface

Documentation

Overview

Package rawparser provides a basic parsing interface for camera raw files. The current incarnation supports TIFF-based RAW files (e.g., Canon CR2, Nikon NEF...).

TIFF specification: http://partners.adobe.com/public/developer/en/tiff/TIFF6.pdf

Index

Constants

View Source
const Cr2ParserKey = "CR2"

Cr2ParserKey is a unique identifier for the CR2 raw file parser. This key may be used as a key the RawParsers map.

View Source
const NefParserKey = "NEF"

NefParserKey is a unique identifier for the NEF raw file parser. This key may be used as a key the RawParsers map.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cr2Parser

type Cr2Parser struct {
	// contains filtered or unexported fields
}

Cr2Parser is the struct defining the state of the RawFile concept. Implements the RawParser interface. This parser provides basic parsing functionaity for the Canon Raw Format 2 (CR2). For a specified CR2, the EXIF create time and orientation are parsed and the embedded JPEG is extracted. The following are resources on CR2 file details:

CR2-specific information: http://lclevy.free.fr/cr2 TIFF specification: http://partners.adobe.com/public/developer/en/tiff/TIFF6.pdf

func (Cr2Parser) IsHostLittleEndian

func (r Cr2Parser) IsHostLittleEndian() bool

IsHostLittleEndian is a function to get the host's endianness specified for the given instance of the RawParser. Returns true if the host is a little endian machine.

func (Cr2Parser) ProcessFile

func (n Cr2Parser) ProcessFile(info *RawFileInfo) (CR2 *RawFile, err error)

ProcessFile is the entry point into the Cr2Parser. For a specified CR2, via RawFileInfo, the file shall be processed, JPEG extracted, and processed details returned to the caller. Returns a pointer the RawFile data structure or error.

func (Cr2Parser) SetHostIsLittleEndian

func (r Cr2Parser) SetHostIsLittleEndian(hostIsLe bool)

SetHostIsLittleEndian is a function to set the host's endianness for the given instance of the RawParser. Set to true if host is a little endian machine; false otherwise.

type NefParser

type NefParser struct {
	// contains filtered or unexported fields
}

NefParser is the struct defining the state of the RawFile concept. Implements the RawParser interface. This parser provides basic parsing functionaity for the Nikon Electronic Format (NEF). For a specified NEF, the EXIF create time and orientation are parsed and the embedded JPEG is extracted. The following are resources on NEF file details:

NEF-specific information: http://lclevy.free.fr/nef/ TIFF specification: http://partners.adobe.com/public/developer/en/tiff/TIFF6.pdf

func (NefParser) IsHostLittleEndian

func (r NefParser) IsHostLittleEndian() bool

IsHostLittleEndian is a function to get the host's endianness specified for the given instance of the RawParser. Returns true if the host is a little endian machine.

func (NefParser) ProcessFile

func (n NefParser) ProcessFile(info *RawFileInfo) (nef *RawFile, err error)

ProcessFile is the entry point into the NefParser. For a specified NEF, via RawFileInfo, the file shall be processed, JPEG extracted, and processed details returned to the caller. Returns a pointer the RawFile data structure or error.

func (NefParser) SetHostIsLittleEndian

func (r NefParser) SetHostIsLittleEndian(hostIsLe bool)

SetHostIsLittleEndian is a function to set the host's endianness for the given instance of the RawParser. Set to true if host is a little endian machine; false otherwise.

type RawFile

type RawFile struct {
	// Note: additional EXIF metadata may be added in future release.
	CreateDate         time.Time
	FileName, JpegPath string
	JpegOrientation    float64
}

RawFile is a struct representing parsed results for a specific raw file.

type RawFileInfo

type RawFileInfo struct {
	File    string
	DestDir string
	Quality int
}

RawFileInfo is a struct defining key information for parsing a RawFile.

type RawParser

type RawParser interface {
	// ProcessFile processes a raw file per the implementation of this parser.
	// Return a pointer to a RawFile struct or error.
	ProcessFile(i *RawFileInfo) (r *RawFile, e error)

	// SetHostIsLittleEndian is a function to set the RawParser host's
	// endianness.
	// Set to true if host is a little endian machine; false otherwise.
	SetHostIsLittleEndian(b bool)

	// IsLittleEndian is a function to get the value of the specified host
	// endianness.
	// Returns true if the host is a little endian machine.
	IsHostLittleEndian() bool
}

RawParser is the defining interface of a raw file parser. Camera-specific parsers shall implement this interface.

func NewCr2Parser

func NewCr2Parser(hostIsLittleEndian bool) (RawParser, string)

NewCr2Parser creates an instance of Cr2Parser. Returns a pointer to a Cr2Parser instance.

func NewNefParser

func NewNefParser(hostIsLittleEndian bool) (RawParser, string)

NewNefParser creates an instance of NEF-specific RawParser. Returns an instance of a NEF-specific RawParser.

type RawParsers

type RawParsers struct {
	// contains filtered or unexported fields
}

RawParsers is a structure containing a mapping of registered raw file parsers. The key is the lower-case file extension of the raw file type; the value is the pointer to the RawParser implementation.

func NewRawParsers

func NewRawParsers() *RawParsers

NewRawParsers creates an instance of RawParsers.

func (*RawParsers) DeleteParser

func (p *RawParsers) DeleteParser(key string)

DeleteParser removes the specified RawParser.

func (RawParsers) GetParser

func (p RawParsers) GetParser(key string) *RawParser

GetParser returns a RawParser for a given raw file type or nil if not found.

func (*RawParsers) Register

func (p *RawParsers) Register(key string, parser *RawParser)

Register maps the implementation of the RawParser interface to the key.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL