mirror of https://github.com/dsoprea/go-exif.git
set unitCount=1 for ThumbnailOffset
parent
6579e82b73
commit
c638d8d748
|
@ -241,6 +241,11 @@ func (ibe *IfdByteEncoder) encodeTagToBytes(ib *IfdBuilder, bt *BuilderTag, bw *
|
||||||
if remainder > 0 {
|
if remainder > 0 {
|
||||||
log.Panicf("tag (0x%04x) value of (%d) bytes not evenly divisible by type-size (%d)", bt.tagId, len_, typeSize)
|
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)
|
err = bw.WriteUint32(unitCount)
|
||||||
|
|
|
@ -702,6 +702,54 @@ func Test_IfdByteEncoder_EncodeToExif(t *testing.T) {
|
||||||
validateExifSimpleTestIb(exifData, 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) {
|
func Test_IfdByteEncoder_EncodeToExif_WithChildAndSibling(t *testing.T) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if state := recover(); state != nil {
|
if state := recover(); state != nil {
|
||||||
|
|
Loading…
Reference in New Issue