mirror of https://github.com/dsoprea/go-exif.git
Removed concept of ITEVRs
This was from a time long past, from the beginning of the project, and was just an ineffective bandaid that made things complicated.for/master
parent
9441507683
commit
82afccee6b
|
@ -318,9 +318,7 @@ func NewIfdBuilderWithExistingIfd(ifd *Ifd) (ib *IfdBuilder) {
|
||||||
|
|
||||||
// NewIfdBuilderFromExistingChain creates a chain of IB instances from an
|
// NewIfdBuilderFromExistingChain creates a chain of IB instances from an
|
||||||
// IFD chain generated from real data.
|
// IFD chain generated from real data.
|
||||||
func NewIfdBuilderFromExistingChain(rootIfd *Ifd, itevr *IfdTagEntryValueResolver) (firstIb *IfdBuilder) {
|
func NewIfdBuilderFromExistingChain(rootIfd *Ifd) (firstIb *IfdBuilder) {
|
||||||
// OBSOLETE(dustin): Support for `itevr` is now obsolete. This parameter will be removed in the future.
|
|
||||||
|
|
||||||
var lastIb *IfdBuilder
|
var lastIb *IfdBuilder
|
||||||
i := 0
|
i := 0
|
||||||
for thisExistingIfd := rootIfd; thisExistingIfd != nil; thisExistingIfd = thisExistingIfd.NextIfd {
|
for thisExistingIfd := rootIfd; thisExistingIfd != nil; thisExistingIfd = thisExistingIfd.NextIfd {
|
||||||
|
@ -331,7 +329,7 @@ func NewIfdBuilderFromExistingChain(rootIfd *Ifd, itevr *IfdTagEntryValueResolve
|
||||||
lastIb.SetNextIb(newIb)
|
lastIb.SetNextIb(newIb)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := newIb.AddTagsFromExisting(thisExistingIfd, nil, nil, nil)
|
err := newIb.AddTagsFromExisting(thisExistingIfd, nil, nil)
|
||||||
log.PanicIf(err)
|
log.PanicIf(err)
|
||||||
|
|
||||||
lastIb = newIb
|
lastIb = newIb
|
||||||
|
@ -1028,15 +1026,13 @@ func (ib *IfdBuilder) NewBuilderTagFromBuilder(childIb *IfdBuilder) (bt *Builder
|
||||||
// AddTagsFromExisting does a verbatim copy of the entries in `ifd` to this
|
// AddTagsFromExisting does a verbatim copy of the entries in `ifd` to this
|
||||||
// builder. It excludes child IFDs. These must be added explicitly via
|
// builder. It excludes child IFDs. These must be added explicitly via
|
||||||
// `AddChildIb()`.
|
// `AddChildIb()`.
|
||||||
func (ib *IfdBuilder) AddTagsFromExisting(ifd *Ifd, itevr *IfdTagEntryValueResolver, includeTagIds []uint16, excludeTagIds []uint16) (err error) {
|
func (ib *IfdBuilder) AddTagsFromExisting(ifd *Ifd, includeTagIds []uint16, excludeTagIds []uint16) (err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if state := recover(); state != nil {
|
if state := recover(); state != nil {
|
||||||
err = log.Wrap(state.(error))
|
err = log.Wrap(state.(error))
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// OBSOLETE(dustin): Support for `itevr` is now obsolete. This parameter will be removed in the future.
|
|
||||||
|
|
||||||
thumbnailData, err := ifd.Thumbnail()
|
thumbnailData, err := ifd.Thumbnail()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = ib.SetThumbnail(thumbnailData)
|
err = ib.SetThumbnail(thumbnailData)
|
||||||
|
@ -1111,7 +1107,7 @@ func (ib *IfdBuilder) AddTagsFromExisting(ifd *Ifd, itevr *IfdTagEntryValueResol
|
||||||
log.Panicf("could not find child IFD for child ITE: IFD-PATH=[%s] TAG-ID=(0x%04x) CURRENT-TAG-POSITION=(%d) CHILDREN=%v", ite.IfdPath, ite.TagId, i, childTagIds)
|
log.Panicf("could not find child IFD for child ITE: IFD-PATH=[%s] TAG-ID=(0x%04x) CURRENT-TAG-POSITION=(%d) CHILDREN=%v", ite.IfdPath, ite.TagId, i, childTagIds)
|
||||||
}
|
}
|
||||||
|
|
||||||
childIb := NewIfdBuilderFromExistingChain(childIfd, nil)
|
childIb := NewIfdBuilderFromExistingChain(childIfd)
|
||||||
bt = ib.NewBuilderTagFromBuilder(childIb)
|
bt = ib.NewBuilderTagFromBuilder(childIb)
|
||||||
} else {
|
} else {
|
||||||
// Non-IFD tag.
|
// Non-IFD tag.
|
||||||
|
|
|
@ -197,7 +197,7 @@ func TestIfdBuilder_AddTagsFromExisting(t *testing.T) {
|
||||||
|
|
||||||
ib := NewIfdBuilder(im, ti, exifcommon.IfdPathStandard, exifcommon.TestDefaultByteOrder)
|
ib := NewIfdBuilder(im, ti, exifcommon.IfdPathStandard, exifcommon.TestDefaultByteOrder)
|
||||||
|
|
||||||
err = ib.AddTagsFromExisting(index.RootIfd, nil, nil, nil)
|
err = ib.AddTagsFromExisting(index.RootIfd, nil, nil)
|
||||||
log.PanicIf(err)
|
log.PanicIf(err)
|
||||||
|
|
||||||
expected := []uint16{
|
expected := []uint16{
|
||||||
|
@ -233,7 +233,7 @@ func TestIfdBuilder_AddTagsFromExisting__Includes(t *testing.T) {
|
||||||
|
|
||||||
ib := NewIfdBuilder(im, ti, exifcommon.IfdPathStandard, exifcommon.TestDefaultByteOrder)
|
ib := NewIfdBuilder(im, ti, exifcommon.IfdPathStandard, exifcommon.TestDefaultByteOrder)
|
||||||
|
|
||||||
err = ib.AddTagsFromExisting(index.RootIfd, nil, []uint16{0x00ff}, nil)
|
err = ib.AddTagsFromExisting(index.RootIfd, []uint16{0x00ff}, nil)
|
||||||
log.PanicIf(err)
|
log.PanicIf(err)
|
||||||
|
|
||||||
expected := []uint16{
|
expected := []uint16{
|
||||||
|
@ -266,7 +266,7 @@ func TestIfdBuilder_AddTagsFromExisting__Excludes(t *testing.T) {
|
||||||
|
|
||||||
ib := NewIfdBuilder(im, ti, exifcommon.IfdPathStandard, exifcommon.TestDefaultByteOrder)
|
ib := NewIfdBuilder(im, ti, exifcommon.IfdPathStandard, exifcommon.TestDefaultByteOrder)
|
||||||
|
|
||||||
err = ib.AddTagsFromExisting(index.RootIfd, nil, nil, []uint16{0xff})
|
err = ib.AddTagsFromExisting(index.RootIfd, nil, []uint16{0xff})
|
||||||
log.PanicIf(err)
|
log.PanicIf(err)
|
||||||
|
|
||||||
expected := []uint16{
|
expected := []uint16{
|
||||||
|
@ -1306,7 +1306,7 @@ func TestIfdBuilder_CreateIfdBuilderFromExistingChain(t *testing.T) {
|
||||||
_, index, err := Collect(im, ti, rawExif)
|
_, index, err := Collect(im, ti, rawExif)
|
||||||
log.PanicIf(err)
|
log.PanicIf(err)
|
||||||
|
|
||||||
ib := NewIfdBuilderFromExistingChain(index.RootIfd, nil)
|
ib := NewIfdBuilderFromExistingChain(index.RootIfd)
|
||||||
|
|
||||||
actual := ib.DumpToStrings()
|
actual := ib.DumpToStrings()
|
||||||
|
|
||||||
|
@ -1410,7 +1410,7 @@ func TestIfdBuilder_CreateIfdBuilderFromExistingChain_RealData(t *testing.T) {
|
||||||
|
|
||||||
ibe := NewIfdByteEncoder()
|
ibe := NewIfdByteEncoder()
|
||||||
|
|
||||||
rootIb := NewIfdBuilderFromExistingChain(originalIndex.RootIfd, nil)
|
rootIb := NewIfdBuilderFromExistingChain(originalIndex.RootIfd)
|
||||||
|
|
||||||
updatedExif, err := ibe.EncodeToExif(rootIb)
|
updatedExif, err := ibe.EncodeToExif(rootIb)
|
||||||
log.PanicIf(err)
|
log.PanicIf(err)
|
||||||
|
@ -1575,7 +1575,7 @@ func TestIfdBuilder_CreateIfdBuilderFromExistingChain_RealData(t *testing.T) {
|
||||||
|
|
||||||
// ibe := NewIfdByteEncoder()
|
// ibe := NewIfdByteEncoder()
|
||||||
|
|
||||||
// rootIb := NewIfdBuilderFromExistingChain(originalIndex.RootIfd, nil)
|
// rootIb := NewIfdBuilderFromExistingChain(originalIndex.RootIfd)
|
||||||
|
|
||||||
// // Update a tag,.
|
// // Update a tag,.
|
||||||
|
|
||||||
|
@ -1729,7 +1729,7 @@ func ExampleBuilderTag_SetValue() {
|
||||||
|
|
||||||
// Create builder.
|
// Create builder.
|
||||||
|
|
||||||
rootIb := NewIfdBuilderFromExistingChain(index.RootIfd, nil)
|
rootIb := NewIfdBuilderFromExistingChain(index.RootIfd)
|
||||||
|
|
||||||
// Find tag to update.
|
// Find tag to update.
|
||||||
|
|
||||||
|
@ -1784,7 +1784,7 @@ func ExampleIfdBuilder_SetStandardWithName() {
|
||||||
_, index, err := Collect(im, ti, rawExif)
|
_, index, err := Collect(im, ti, rawExif)
|
||||||
log.PanicIf(err)
|
log.PanicIf(err)
|
||||||
|
|
||||||
ib := NewIfdBuilderFromExistingChain(index.RootIfd, nil)
|
ib := NewIfdBuilderFromExistingChain(index.RootIfd)
|
||||||
|
|
||||||
// Read the IFD whose tag we want to change.
|
// Read the IFD whose tag we want to change.
|
||||||
|
|
||||||
|
|
|
@ -159,58 +159,3 @@ func (ite *IfdTagEntry) Value(addressableData []byte, byteOrder binary.ByteOrder
|
||||||
|
|
||||||
return value, nil
|
return value, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// IfdTagEntryValueResolver instances know how to resolve the values for any
|
|
||||||
// tag for a particular EXIF block.
|
|
||||||
type IfdTagEntryValueResolver struct {
|
|
||||||
addressableData []byte
|
|
||||||
byteOrder binary.ByteOrder
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewIfdTagEntryValueResolver(exifData []byte, byteOrder binary.ByteOrder) (itevr *IfdTagEntryValueResolver) {
|
|
||||||
return &IfdTagEntryValueResolver{
|
|
||||||
addressableData: exifData[ExifAddressableAreaStart:],
|
|
||||||
byteOrder: byteOrder,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ValueBytes will resolve embedded or allocated data from the tag and return the raw bytes.
|
|
||||||
func (itevr *IfdTagEntryValueResolver) ValueBytes(ite *IfdTagEntry) (value []byte, err error) {
|
|
||||||
defer func() {
|
|
||||||
if state := recover(); state != nil {
|
|
||||||
err = log.Wrap(state.(error))
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// OBSOLETE(dustin): This is now redundant. Use `(*ValueContext).readRawEncoded()` instead of this method.
|
|
||||||
|
|
||||||
valueContext := newValueContextFromTag(
|
|
||||||
ite,
|
|
||||||
itevr.addressableData,
|
|
||||||
itevr.byteOrder)
|
|
||||||
|
|
||||||
rawBytes, err := valueContext.ReadRawEncoded()
|
|
||||||
log.PanicIf(err)
|
|
||||||
|
|
||||||
return rawBytes, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (itevr *IfdTagEntryValueResolver) Value(ite *IfdTagEntry) (value interface{}, err error) {
|
|
||||||
defer func() {
|
|
||||||
if state := recover(); state != nil {
|
|
||||||
err = log.Wrap(state.(error))
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// OBSOLETE(dustin): This is now redundant. Use `(*ValueContext).Values()` instead of this method.
|
|
||||||
|
|
||||||
valueContext := newValueContextFromTag(
|
|
||||||
ite,
|
|
||||||
itevr.addressableData,
|
|
||||||
itevr.byteOrder)
|
|
||||||
|
|
||||||
values, err := valueContext.Values()
|
|
||||||
log.PanicIf(err)
|
|
||||||
|
|
||||||
return values, nil
|
|
||||||
}
|
|
||||||
|
|
|
@ -188,33 +188,3 @@ func TestIfdTagEntry_String(t *testing.T) {
|
||||||
t.Fatalf("string representation not expected: [%s] != [%s]", ite.String(), expected)
|
t.Fatalf("string representation not expected: [%s] != [%s]", ite.String(), expected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIfdTagEntryValueResolver_ValueBytes(t *testing.T) {
|
|
||||||
allocatedData := []byte{0x11, 0x22, 0x33, 0x44, 0x55, 0x66}
|
|
||||||
|
|
||||||
ite := IfdTagEntry{
|
|
||||||
TagId: 0x1,
|
|
||||||
TagIndex: 0,
|
|
||||||
TagType: exifcommon.TypeByte,
|
|
||||||
UnitCount: uint32(len(allocatedData)),
|
|
||||||
ValueOffset: 0x8,
|
|
||||||
RawValueOffset: []byte{0x0, 0x0, 0x0, 0x0},
|
|
||||||
IfdPath: exifcommon.IfdPathStandard,
|
|
||||||
}
|
|
||||||
|
|
||||||
headerBytes, err := BuildExifHeader(exifcommon.TestDefaultByteOrder, uint32(0))
|
|
||||||
log.PanicIf(err)
|
|
||||||
|
|
||||||
exifData := make([]byte, len(headerBytes)+len(allocatedData))
|
|
||||||
copy(exifData[0:], headerBytes)
|
|
||||||
copy(exifData[len(headerBytes):], allocatedData)
|
|
||||||
|
|
||||||
itevr := NewIfdTagEntryValueResolver(exifData, exifcommon.TestDefaultByteOrder)
|
|
||||||
|
|
||||||
value, err := itevr.ValueBytes(&ite)
|
|
||||||
log.PanicIf(err)
|
|
||||||
|
|
||||||
if bytes.Compare(value, allocatedData) != 0 {
|
|
||||||
t.Fatalf("bytes not expected: %v != %v", value, allocatedData)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue