use exif-terminator

This commit is contained in:
tsmethurst 2022-01-23 14:41:31 +01:00
commit 7d024ce74d
117 changed files with 3873 additions and 8725 deletions

View file

@ -1,21 +0,0 @@
language: go
go:
- master
- stable
- "1.14"
- "1.13"
- "1.12"
env:
- GO111MODULE=on
install:
- go get -t ./...
script:
# v1
- go test -v .
# v2
- cd v2
- go test -v ./... -coverprofile=coverage.txt -covermode=atomic
- cd ..
after_success:
- cd v2
- curl -s https://codecov.io/bash | bash

View file

@ -1,5 +1,5 @@
[![Build Status](https://travis-ci.org/dsoprea/go-jpeg-image-structure.svg?branch=master)](https://travis-ci.org/dsoprea/go-jpeg-image-structure)
[![codecov](https://codecov.io/gh/dsoprea/go-jpeg-image-structure/branch/master/graph/badge.svg?token=Twxyx7kpAa)](https://codecov.io/gh/dsoprea/go-jpeg-image-structure)
[![Build Status](https://travis-ci.org/dsoprea/go-jpeg-image-structure/v2.svg?branch=master)](https://travis-ci.org/dsoprea/go-jpeg-image-structure/v2)
[![codecov](https://codecov.io/gh/dsoprea/go-jpeg-image-structure/branch/master/graph/badge.svg)](https://codecov.io/gh/dsoprea/go-jpeg-image-structure)
[![Go Report Card](https://goreportcard.com/badge/github.com/dsoprea/go-jpeg-image-structure/v2)](https://goreportcard.com/report/github.com/dsoprea/go-jpeg-image-structure/v2)
[![GoDoc](https://godoc.org/github.com/dsoprea/go-jpeg-image-structure/v2?status.svg)](https://godoc.org/github.com/dsoprea/go-jpeg-image-structure/v2)

View file

@ -3,11 +3,14 @@ package jpegstructure
import (
"bufio"
"bytes"
"image"
"io"
"os"
"image/jpeg"
"github.com/dsoprea/go-logging"
"github.com/dsoprea/go-utility/image"
"github.com/dsoprea/go-utility/v2/image"
)
// JpegMediaParser is a `riimage.MediaParser` that knows how to parse JPEG
@ -122,6 +125,14 @@ func (jmp *JpegMediaParser) LooksLikeFormat(data []byte) bool {
return true
}
// GetImage returns an image.Image-compatible struct.
func (jmp *JpegMediaParser) GetImage(r io.Reader) (img image.Image, err error) {
img, err = jpeg.Decode(r)
log.PanicIf(err)
return img, nil
}
var (
// Enforce interface conformance.
_ riimage.MediaParser = new(JpegMediaParser)

View file

@ -8,11 +8,12 @@ import (
"crypto/sha1"
"encoding/hex"
"github.com/dsoprea/go-exif/v2"
"github.com/dsoprea/go-exif/v3"
"github.com/dsoprea/go-exif/v3/common"
"github.com/dsoprea/go-iptc"
"github.com/dsoprea/go-logging"
"github.com/dsoprea/go-photoshop-info-format"
"github.com/dsoprea/go-utility/image"
"github.com/dsoprea/go-utility/v2/image"
)
const (
@ -125,7 +126,9 @@ func (s *Segment) Exif() (rootIfd *exif.Ifd, data []byte, err error) {
jpegLogger.Debugf(nil, "Attempting to parse (%d) byte EXIF blob (Exif).", len(rawExif))
im := exif.NewIfdMappingWithStandard()
im, err := exifcommon.NewIfdMappingWithStandard()
log.PanicIf(err)
ti := exif.NewTagIndex()
_, index, err := exif.Collect(im, ti, rawExif)
@ -150,7 +153,7 @@ func (s *Segment) FlatExif() (exifTags []exif.ExifTag, err error) {
jpegLogger.Debugf(nil, "Attempting to parse (%d) byte EXIF blob (FlatExif).", len(rawExif))
exifTags, err = exif.GetFlatExifData(rawExif)
exifTags, _, err = exif.GetFlatExifData(rawExif, nil)
log.PanicIf(err)
return exifTags, nil

View file

@ -8,7 +8,8 @@ import (
"crypto/sha1"
"encoding/binary"
"github.com/dsoprea/go-exif/v2"
"github.com/dsoprea/go-exif/v3"
"github.com/dsoprea/go-exif/v3/common"
"github.com/dsoprea/go-iptc"
"github.com/dsoprea/go-logging"
)
@ -241,11 +242,31 @@ func (sl *SegmentList) ConstructExifBuilder() (rootIb *exif.IfdBuilder, err erro
}()
rootIfd, _, err := sl.Exif()
log.PanicIf(err)
if log.Is(err, exif.ErrNoExif) == true {
// No EXIF. Just create a boilerplate builder.
ib := exif.NewIfdBuilderFromExistingChain(rootIfd)
im := exifcommon.NewIfdMapping()
return ib, nil
err := exifcommon.LoadStandardIfds(im)
log.PanicIf(err)
ti := exif.NewTagIndex()
rootIb :=
exif.NewIfdBuilder(
im,
ti,
exifcommon.IfdStandardIfdIdentity,
exifcommon.EncodeDefaultByteOrder)
return rootIb, nil
} else if err != nil {
log.Panic(err)
}
rootIb = exif.NewIfdBuilderFromExistingChain(rootIfd)
return rootIb, nil
}
// DumpExif returns an unstructured list of tags (useful when just reviewing).