diff --git a/exif-read-tool/main.go b/exif-read-tool/main.go index c01e415..2e6d3f0 100644 --- a/exif-read-tool/main.go +++ b/exif-read-tool/main.go @@ -26,8 +26,8 @@ import ( ) var ( - filepathArgument = "" - printAsJsonArgument = false + filepathArg = "" + printAsJsonArg = false ) @@ -52,17 +52,17 @@ func main() { } }() - flag.StringVar(&filepathArgument, "filepath", "", "File-path of image") - flag.BoolVar(&printAsJsonArgument, "json", false, "Print JSON") + flag.StringVar(&filepathArg, "filepath", "", "File-path of image") + flag.BoolVar(&printAsJsonArg, "json", false, "Print JSON") flag.Parse() - if filepathArgument == "" { + if filepathArg == "" { fmt.Printf("Please provide a file-path for an image.\n") os.Exit(1) } - f, err := os.Open(filepathArgument) + f, err := os.Open(filepathArg) log.PanicIf(err) data, err := ioutil.ReadAll(f) @@ -146,7 +146,7 @@ func main() { _, err = e.Visit(data[foundAt:], visitor) log.PanicIf(err) - if printAsJsonArgument == true { + if printAsJsonArg == true { data, err := json.MarshalIndent(entries, "", " ") log.PanicIf(err) diff --git a/ifd_enumerate.go b/ifd_enumerate.go index 0b2c111..81f4b22 100644 --- a/ifd_enumerate.go +++ b/ifd_enumerate.go @@ -271,6 +271,11 @@ func (ie *IfdEnumerate) Scan(ifdOffset uint32, visitor TagVisitor) (err error) { type Ifd struct { + // This is just for convenience, just so that we can easily get the values + // and not involve other projects in semantics that they won't otherwise + // need to know. + addressableData []byte + ByteOrder binary.ByteOrder Ii IfdIdentity @@ -289,6 +294,19 @@ type Ifd struct { NextIfd *Ifd } +func (ifd *Ifd) TagValue(ite *IfdTagEntry) (value interface{}, err error) { + defer func() { + if state := recover(); state != nil { + err = log.Wrap(state.(error)) + } + }() + + value, err = ite.Value(ifd.addressableData, ifd.ByteOrder) + log.PanicIf(err) + + return value, nil +} + // FindTagWithId returns a list of tags (usually just zero or one) that match // the given tag ID. This is efficient. func (ifd Ifd) FindTagWithId(tagId uint16) (results []*IfdTagEntry, err error) { @@ -550,6 +568,8 @@ func (ie *IfdEnumerate) Collect(rootIfdOffset uint32) (index IfdIndex, err error } ifd := Ifd{ + addressableData: ie.exifData[ExifAddressableAreaStart:], + ByteOrder: ie.byteOrder, Ii: ii, Id: id,