mirror of https://github.com/perkeep/perkeep.git
Merge "pkg/index: read EXIF bytes when HEIC file"
This commit is contained in:
commit
b1e655219c
|
@ -145,6 +145,7 @@ type Config struct {
|
|||
Width, Height int
|
||||
Format string
|
||||
Modified bool // true if Decode actually rotated or flipped the image.
|
||||
HEICEXIF []byte // if not nil, the part of the HEIC file that contains EXIF metadata
|
||||
}
|
||||
|
||||
func (c *Config) setBounds(im image.Image) {
|
||||
|
@ -410,6 +411,7 @@ func DecodeConfig(r io.Reader) (Config, error) {
|
|||
if err != nil {
|
||||
return c, err
|
||||
}
|
||||
c.HEICEXIF = exifBytes
|
||||
mr = bytes.NewReader(exifBytes)
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
|
@ -342,7 +342,7 @@ func Index(t *testing.T, initIdx func() *index.Index) {
|
|||
}
|
||||
|
||||
// Upload some files.
|
||||
var jpegFileRef, exifFileRef, exifWholeRef, badExifWholeRef, nanExifWholeRef, mediaFileRef, mediaWholeRef blob.Ref
|
||||
var jpegFileRef, exifFileRef, exifWholeRef, badExifWholeRef, nanExifWholeRef, mediaFileRef, mediaWholeRef, heicEXIFWholeRef blob.Ref
|
||||
{
|
||||
camliRootPath, err := osutil.GoPackagePath("perkeep.org")
|
||||
if err != nil {
|
||||
|
@ -362,6 +362,7 @@ func Index(t *testing.T, initIdx func() *index.Index) {
|
|||
_, badExifWholeRef = uploadFile("bad-exif.jpg", time.Unix(1361248796, 0))
|
||||
_, nanExifWholeRef = uploadFile("nan-exif.jpg", time.Unix(1361248796, 0))
|
||||
mediaFileRef, mediaWholeRef = uploadFile("0s.mp3", noTime)
|
||||
_, heicEXIFWholeRef = uploadFile("black-seattle-truncated.heic", time.Unix(1361248796, 0))
|
||||
}
|
||||
|
||||
// Upload the dir containing the previous files.
|
||||
|
@ -411,6 +412,12 @@ func Index(t *testing.T, initIdx func() *index.Index) {
|
|||
t.Errorf("EXIF nan-exif.jpg key %q = %q; want %q", key, g, e)
|
||||
}
|
||||
|
||||
// Check that we can read EXIF from HEIC files too
|
||||
key = "exifgps|" + heicEXIFWholeRef.String()
|
||||
if g, e := id.Get(key), "47.6496056|-122.3512806"; g != e {
|
||||
t.Errorf("EXIF black-seattle-truncated.heic key %q = %q; want %q", key, g, e)
|
||||
}
|
||||
|
||||
key = "have:" + pn.String()
|
||||
pnSizeStr := strings.TrimSuffix(id.Get(key), "|indexed")
|
||||
if pnSizeStr == "" {
|
||||
|
|
|
@ -489,12 +489,17 @@ func (ix *Index) populateFile(ctx context.Context, fetcher blob.Fetcher, b *sche
|
|||
mm.Set(keyImageSize.Key(blobRef), keyImageSize.Val(fmt.Sprint(conf.Width), fmt.Sprint(conf.Height)))
|
||||
}
|
||||
|
||||
exifData := imageBuf.Bytes
|
||||
if conf.HEICEXIF != nil {
|
||||
exifData = conf.HEICEXIF
|
||||
}
|
||||
var ft time.Time
|
||||
fileTime := func(r filePrefixReader) error {
|
||||
ft, err = schema.FileTime(r)
|
||||
return err
|
||||
}
|
||||
if err = readPrefixOrFile(imageBuf.Bytes, fetcher, b, fileTime); err == nil {
|
||||
|
||||
if err = readPrefixOrFile(exifData, fetcher, b, fileTime); err == nil {
|
||||
times = append(times, ft)
|
||||
}
|
||||
if exifDebug {
|
||||
|
@ -505,7 +510,7 @@ func (ix *Index) populateFile(ctx context.Context, fetcher blob.Fetcher, b *sche
|
|||
indexEXIFData := func(r filePrefixReader) error {
|
||||
return indexEXIF(wholeRef, r, mm)
|
||||
}
|
||||
if err = readPrefixOrFile(imageBuf.Bytes, fetcher, b, indexEXIFData); err != nil {
|
||||
if err = readPrefixOrFile(exifData, fetcher, b, indexEXIFData); err != nil {
|
||||
if exifDebug {
|
||||
log.Printf("error parsing EXIF: %v", err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue