From 4686c99e3c35a6f2e57196cf3433705e48b5edef Mon Sep 17 00:00:00 2001 From: Dustin Oprea Date: Mon, 18 May 2020 01:16:27 -0400 Subject: [PATCH] exif-read-tool/main.go: Just use GetFlatExifData() instead of our own visitor process --- v2/exif-read-tool/main.go | 84 ++++++++------------------------------- 1 file changed, 17 insertions(+), 67 deletions(-) diff --git a/v2/exif-read-tool/main.go b/v2/exif-read-tool/main.go index ac7190e..7379127 100644 --- a/v2/exif-read-tool/main.go +++ b/v2/exif-read-tool/main.go @@ -25,7 +25,6 @@ import ( "github.com/dsoprea/go-exif/v2" "github.com/dsoprea/go-exif/v2/common" - "github.com/dsoprea/go-exif/v2/undefined" ) const ( @@ -106,75 +105,16 @@ func main() { // Run the parse. - im := exif.NewIfdMappingWithStandard() - ti := exif.NewTagIndex() - - entries := make([]IfdEntry, 0) - visitor := func(fqIfdPath string, ifdIndex int, ite *exif.IfdTagEntry) (err error) { - defer func() { - if state := recover(); state != nil { - err = log.Wrap(state.(error)) - log.Panic(err) - } - }() - - tagId := ite.TagId() - tagType := ite.TagType() - - ifdPath, err := im.StripPathPhraseIndices(fqIfdPath) - log.PanicIf(err) - - it, err := ti.Get(ifdPath, tagId) - if err != nil { - if log.Is(err, exif.ErrTagNotFound) { - mainLogger.Warningf(nil, "Unknown tag: [%s] (0x%04x)", ifdPath, tagId) - return nil - } else { - log.Panic(err) - } - } - - value, err := ite.Value() - if err != nil { - if log.Is(err, exifcommon.ErrUnhandledUndefinedTypedTag) == true { - mainLogger.Warningf(nil, "Skipping non-standard undefined tag: [%s] (%04x)", ifdPath, tagId) - return nil - } else if err == exifundefined.ErrUnparseableValue { - mainLogger.Warningf(nil, "Skipping unparseable undefined tag: [%s] (%04x)", ifdPath, tagId) - return nil - } - - log.Panic(err) - } - - valueString, err := ite.FormatFirst() - log.PanicIf(err) - - entry := IfdEntry{ - IfdPath: ifdPath, - FqIfdPath: fqIfdPath, - IfdIndex: ifdIndex, - TagId: tagId, - TagName: it.Name, - TagTypeId: tagType, - TagTypeName: tagType.String(), - UnitCount: ite.UnitCount(), - Value: value, - ValueString: valueString, - } - - entries = append(entries, entry) - - return nil - } - - _, furthestOffset, err := exif.Visit(exifcommon.IfdStandard, im, ti, rawExif, visitor) + entries, err := exif.GetFlatExifData(rawExif) log.PanicIf(err) - mainLogger.Debugf(nil, "EXIF blob is approximately (%d) bytes.", furthestOffset) + // Write the thumbnail is requested and present. thumbnailOutputFilepath := arguments.ThumbnailOutputFilepath if thumbnailOutputFilepath != "" { + im := exif.NewIfdMappingWithStandard() + ti := exif.NewTagIndex() + _, index, err := exif.Collect(im, ti, rawExif) log.PanicIf(err) @@ -206,12 +146,22 @@ func main() { fmt.Println(string(data)) } else { + thumbnailTags := 0 for _, entry := range entries { - fmt.Printf("IFD-PATH=[%s] ID=(0x%04x) NAME=[%s] COUNT=(%d) TYPE=[%s] VALUE=[%s]\n", entry.IfdPath, entry.TagId, entry.TagName, entry.UnitCount, entry.TagTypeName, entry.ValueString) + if (entry.TagId == exif.ThumbnailOffsetTagId || entry.TagId == exif.ThumbnailSizeTagId) && entry.IfdPath == exif.ThumbnailFqIfdPath { + thumbnailTags++ + continue + } + + fmt.Printf("IFD-PATH=[%s] ID=(0x%04x) NAME=[%s] COUNT=(%d) TYPE=[%s] VALUE=[%s]\n", entry.IfdPath, entry.TagId, entry.TagName, entry.UnitCount, entry.TagTypeName, entry.Formatted) } fmt.Printf("\n") - fmt.Printf("EXIF blob is approximately (%d) bytes.\n", furthestOffset) + + if thumbnailTags == 2 { + fmt.Printf("There is a thumbnail.\n") + fmt.Printf("\n") + } } } }