Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions v3/ifd_builder_encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ func (ibe *IfdByteEncoder) encodeTagToBytes(ib *IfdBuilder, bt *BuilderTag, bw *
if remainder > 0 {
log.Panicf("tag (0x%04x) value of (%d) bytes not evenly divisible by type-size (%d)", bt.tagId, len_, typeSize)
}

}
if bt.tagId == ThumbnailOffsetTagId {
// The thumbnail offset is store as a long and its unit count must be 1
unitCount = 1
}

err = bw.WriteUint32(unitCount)
Expand Down
48 changes: 48 additions & 0 deletions v3/ifd_builder_encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,54 @@ func Test_IfdByteEncoder_EncodeToExif(t *testing.T) {
validateExifSimpleTestIb(exifData, t)
}

func Test_IfdByteEncoder_encodeTagToBytes_bytes_thumbnailOffset(t *testing.T) {
defer func() {
if state := recover(); state != nil {
err := log.Wrap(state.(error))
log.PrintError(err)
t.Fatalf("Test failed.")
}
}()

ibe := NewIfdByteEncoder()

im, err := exifcommon.NewIfdMappingWithStandard()
log.PanicIf(err)

ti := NewTagIndex()
ib := NewIfdBuilder(im, ti, exifcommon.IfdStandardIfdIdentity, exifcommon.TestDefaultByteOrder)

log.PanicIf(err)

bt := &BuilderTag{
ifdPath: exifcommon.IfdStandardIfdIdentity.UnindexedString(),
tagId: ThumbnailOffsetTagId,
typeId: exifcommon.TypeLong,
value: NewIfdBuilderTagValueFromBytes([]byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09}),
}

b := new(bytes.Buffer)
bw := NewByteWriter(b, exifcommon.TestDefaultByteOrder)

addressableOffset := uint32(0x1234)
ida := newIfdDataAllocator(addressableOffset)

_, err = ibe.encodeTagToBytes(ib, bt, bw, ida, uint32(0))
log.PanicIf(err)

tagBytes := b.Bytes()
if len(tagBytes) != 12 {
t.Fatalf("Tag not encoded to the right number of bytes: (%d)", len(tagBytes))
} else if bytes.Compare(tagBytes, []byte{
0x02, 0x01,
0x00, 0x04,
0x00, 0x00, 0x00, 0x01, // unitCount = 1
0x00, 0x00, 0x12, 0x34,
}) != 0 {
t.Fatalf("encoded tag-entry not correct")
}
}

func Test_IfdByteEncoder_EncodeToExif_WithChildAndSibling(t *testing.T) {
defer func() {
if state := recover(); state != nil {
Expand Down