pull/86/merge
kawata 2024-03-16 02:52:46 +09:00 committed by GitHub
commit 7f82e88851
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 53 additions and 0 deletions

View File

@ -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)

View File

@ -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 {