mirror of https://github.com/perkeep/perkeep.git
internal/images: broaden pattern that matches HEIC images
A bunch of mine had a larger initial ftyp box, which broke the second part of the pattern. But the second part of the pattern doesn't matter anyway. This only needs to casually recognize them. A later full parse will determine what they really are. This also adds some new debugging when CAMLI_DEBUG is true. Change-Id: Ib4adc9b5447a64ba4682624e42b55f1d65779ef7
This commit is contained in:
parent
576dabac82
commit
6b88e2a73f
|
@ -57,7 +57,7 @@ var ErrHEIC = errors.New("HEIC decoding not implemented yet")
|
|||
|
||||
func init() {
|
||||
image.RegisterFormat("heic",
|
||||
"????ftypheic????????????????meta????????hdlr????????pict",
|
||||
"????ftypheic",
|
||||
func(io.Reader) (image.Image, error) {
|
||||
return nil, ErrHEIC
|
||||
},
|
||||
|
@ -364,7 +364,7 @@ var debug, _ = strconv.ParseBool(os.Getenv("CAMLI_DEBUG_IMAGES"))
|
|||
|
||||
func imageDebug(msg string) {
|
||||
if debug {
|
||||
log.Print(msg)
|
||||
log.Print("internal/images: " + msg)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -396,7 +396,9 @@ func DecodeConfig(r io.Reader) (Config, error) {
|
|||
|
||||
conf, format, err := image.DecodeConfig(tr)
|
||||
if err != nil {
|
||||
imageDebug(fmt.Sprintf("Image Decoding failed: %v", err))
|
||||
if debug {
|
||||
log.Printf("internal/images: DecodeConfig failed after reading %d bytes: %v", buf.Len(), err)
|
||||
}
|
||||
return Config{}, err
|
||||
}
|
||||
c := Config{
|
||||
|
|
|
@ -18,6 +18,7 @@ package images
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"image"
|
||||
"image/jpeg"
|
||||
"io"
|
||||
|
@ -377,7 +378,7 @@ func TestIssue513(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestHEIF(t *testing.T) {
|
||||
func TestHEIFToJPEG(t *testing.T) {
|
||||
filename := filepath.Join("testdata", "IMG_8062.HEIC")
|
||||
f, err := os.Open(filename)
|
||||
if err != nil {
|
||||
|
@ -402,3 +403,22 @@ func TestHEIF(t *testing.T) {
|
|||
t.Fatalf("wrong width or height, wanted (%d, %d), got (%d, %d)", wantWidth, wantHeight, conf.Width, conf.Height)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodeHEIC_WithJPEGInHeader(t *testing.T) {
|
||||
filename := filepath.Join("testdata", "river-truncated.heic")
|
||||
f, err := os.Open(filename)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
conf, err := DecodeConfig(f)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := fmt.Sprintf("Width:%d Height:%d Format:%v HEIC:%d bytes", conf.Width, conf.Height, conf.Format, len(conf.HEICEXIF))
|
||||
want := "Width:6302 Height:3912 Format:heic HEIC:1046 bytes"
|
||||
if got != want {
|
||||
t.Errorf("Got:\n %s\nWant:\n %s", got, want)
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
|
@ -248,6 +248,9 @@ func (ix *Index) ReceiveBlob(ctx context.Context, blobRef blob.Ref, source io.Re
|
|||
}
|
||||
|
||||
mm, err := ix.populateMutationMap(ctx, fetcher, blobRef, sniffer)
|
||||
if debugEnv {
|
||||
log.Printf("index of %v: mm=%v, err=%v", blobRef, mm, err)
|
||||
}
|
||||
if err != nil {
|
||||
if err != errMissingDep {
|
||||
return blob.SizedRef{}, err
|
||||
|
@ -503,6 +506,8 @@ func (ix *Index) populateFile(ctx context.Context, fetcher blob.Fetcher, b *sche
|
|||
}
|
||||
if err := readPrefixOrFile(imageBuf.Bytes, fetcher, b, decodeConfig); err == nil {
|
||||
mm.Set(keyImageSize.Key(blobRef), keyImageSize.Val(fmt.Sprint(conf.Width), fmt.Sprint(conf.Height)))
|
||||
} else if debugEnv {
|
||||
log.Printf("index: WARNING: image decodeConfig: %v", err)
|
||||
}
|
||||
|
||||
exifData := imageBuf.Bytes
|
||||
|
@ -517,6 +522,9 @@ func (ix *Index) populateFile(ctx context.Context, fetcher blob.Fetcher, b *sche
|
|||
|
||||
if err = readPrefixOrFile(exifData, fetcher, b, fileTime); err == nil {
|
||||
times = append(times, ft)
|
||||
} else if debugEnv {
|
||||
log.Printf("index: WARNING: image fileTime: %v", err)
|
||||
|
||||
}
|
||||
if exifDebug {
|
||||
log.Printf("filename %q exif = %v, %v", b.FileName(), ft, err)
|
||||
|
|
Loading…
Reference in New Issue