mirror of
https://github.com/dsoprea/go-exif.git
synced 2025-05-31 11:41:57 +00:00
ifd_builder: renamed builderTag to BuilderTag.
- It's probably a generally good idea. - These are usually created by other methods, but they're regularly interacted with when you want to make tag changes and by making them private we can't public official, testable examples. - Corrected names for new examples.
This commit is contained in:
parent
81b804b70d
commit
570c4d582c
101
ifd_builder.go
101
ifd_builder.go
@ -23,7 +23,6 @@ var (
|
||||
ErrTagEntryNotFound = errors.New("tag entry not found")
|
||||
)
|
||||
|
||||
|
||||
type IfdBuilderTagValue struct {
|
||||
valueBytes []byte
|
||||
ib *IfdBuilder
|
||||
@ -83,8 +82,7 @@ func (ibtv IfdBuilderTagValue) Ib() *IfdBuilder {
|
||||
return ibtv.ib
|
||||
}
|
||||
|
||||
|
||||
type builderTag struct {
|
||||
type BuilderTag struct {
|
||||
// ii is the IfdIdentity of the IFD that hosts this tag.
|
||||
ii IfdIdentity
|
||||
|
||||
@ -97,8 +95,8 @@ type builderTag struct {
|
||||
value *IfdBuilderTagValue
|
||||
}
|
||||
|
||||
func NewBuilderTag(ii IfdIdentity, tagId uint16, typeId uint16, value *IfdBuilderTagValue) *builderTag {
|
||||
return &builderTag{
|
||||
func NewBuilderTag(ii IfdIdentity, tagId uint16, typeId uint16, value *IfdBuilderTagValue) *BuilderTag {
|
||||
return &BuilderTag{
|
||||
ii: ii,
|
||||
tagId: tagId,
|
||||
typeId: typeId,
|
||||
@ -106,13 +104,13 @@ func NewBuilderTag(ii IfdIdentity, tagId uint16, typeId uint16, value *IfdBuilde
|
||||
}
|
||||
}
|
||||
|
||||
func NewStandardBuilderTag(ii IfdIdentity, tagId uint16, value *IfdBuilderTagValue) *builderTag {
|
||||
func NewStandardBuilderTag(ii IfdIdentity, tagId uint16, value *IfdBuilderTagValue) *BuilderTag {
|
||||
ti := NewTagIndex()
|
||||
|
||||
it, err := ti.Get(ii, tagId)
|
||||
log.PanicIf(err)
|
||||
|
||||
return &builderTag{
|
||||
return &BuilderTag{
|
||||
ii: ii,
|
||||
tagId: tagId,
|
||||
typeId: it.Type,
|
||||
@ -120,8 +118,8 @@ func NewStandardBuilderTag(ii IfdIdentity, tagId uint16, value *IfdBuilderTagVal
|
||||
}
|
||||
}
|
||||
|
||||
func NewChildIfdBuilderTag(ii IfdIdentity, tagId uint16, value *IfdBuilderTagValue) *builderTag {
|
||||
return &builderTag{
|
||||
func NewChildIfdBuilderTag(ii IfdIdentity, tagId uint16, value *IfdBuilderTagValue) *BuilderTag {
|
||||
return &BuilderTag{
|
||||
ii: ii,
|
||||
tagId: tagId,
|
||||
typeId: TypeLong,
|
||||
@ -129,22 +127,22 @@ func NewChildIfdBuilderTag(ii IfdIdentity, tagId uint16, value *IfdBuilderTagVal
|
||||
}
|
||||
}
|
||||
|
||||
func (bt *builderTag) Value() (value *IfdBuilderTagValue) {
|
||||
func (bt *BuilderTag) Value() (value *IfdBuilderTagValue) {
|
||||
return bt.value
|
||||
}
|
||||
|
||||
func (bt *builderTag) String() string {
|
||||
func (bt *BuilderTag) String() string {
|
||||
return fmt.Sprintf("BuilderTag<IFD=[%s] TAG-ID=(0x%04x) TAG-TYPE=[%s] VALUE=[%s]>", bt.ii, bt.tagId, TypeNames[bt.typeId], bt.value)
|
||||
}
|
||||
|
||||
func (bt *builderTag) SetValue(byteOrder binary.ByteOrder, value interface{}) (err error) {
|
||||
func (bt *BuilderTag) SetValue(byteOrder binary.ByteOrder, value interface{}) (err error) {
|
||||
defer func() {
|
||||
if state := recover(); state != nil {
|
||||
err = log.Wrap(state.(error))
|
||||
}
|
||||
}()
|
||||
|
||||
// TODO(dustin): !! Add test.
|
||||
// TODO(dustin): !! Add test.
|
||||
|
||||
tt := NewTagType(bt.typeId, byteOrder)
|
||||
ve := NewValueEncoder(byteOrder)
|
||||
@ -167,9 +165,9 @@ func (bt *builderTag) SetValue(byteOrder binary.ByteOrder, value interface{}) (e
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewStandardBuilderTagFromConfig constructs a `builderTag` instance. The type
|
||||
// NewStandardBuilderTagFromConfig constructs a `BuilderTag` instance. The type
|
||||
// is looked up. `ii` is the type of IFD that owns this tag.
|
||||
func NewStandardBuilderTagFromConfig(ii IfdIdentity, tagId uint16, byteOrder binary.ByteOrder, value interface{}) *builderTag {
|
||||
func NewStandardBuilderTagFromConfig(ii IfdIdentity, tagId uint16, byteOrder binary.ByteOrder, value interface{}) *BuilderTag {
|
||||
ti := NewTagIndex()
|
||||
|
||||
it, err := ti.Get(ii, tagId)
|
||||
@ -202,9 +200,9 @@ func NewStandardBuilderTagFromConfig(ii IfdIdentity, tagId uint16, byteOrder bin
|
||||
tagValue)
|
||||
}
|
||||
|
||||
// NewStandardBuilderTagFromConfig constructs a `builderTag` instance. The type is
|
||||
// NewStandardBuilderTagFromConfig constructs a `BuilderTag` instance. The type is
|
||||
// explicitly provided. `ii` is the type of IFD that owns this tag.
|
||||
func NewBuilderTagFromConfig(ii IfdIdentity, tagId uint16, typeId uint16, byteOrder binary.ByteOrder, value interface{}) *builderTag {
|
||||
func NewBuilderTagFromConfig(ii IfdIdentity, tagId uint16, typeId uint16, byteOrder binary.ByteOrder, value interface{}) *BuilderTag {
|
||||
tt := NewTagType(typeId, byteOrder)
|
||||
|
||||
ve := NewValueEncoder(byteOrder)
|
||||
@ -234,7 +232,7 @@ func NewBuilderTagFromConfig(ii IfdIdentity, tagId uint16, typeId uint16, byteOr
|
||||
// NewStandardBuilderTagFromConfigWithName allows us to easily generate solid, consistent tags
|
||||
// for testing with. `ii` is the type of IFD that owns this tag. This can not be
|
||||
// an IFD (IFDs are not associated with standardized, official names).
|
||||
func NewStandardBuilderTagFromConfigWithName(ii IfdIdentity, tagName string, byteOrder binary.ByteOrder, value interface{}) *builderTag {
|
||||
func NewStandardBuilderTagFromConfigWithName(ii IfdIdentity, tagName string, byteOrder binary.ByteOrder, value interface{}) *BuilderTag {
|
||||
ti := NewTagIndex()
|
||||
|
||||
it, err := ti.GetWithName(ii, tagName)
|
||||
@ -266,7 +264,6 @@ func NewStandardBuilderTagFromConfigWithName(ii IfdIdentity, tagName string, byt
|
||||
tagValue)
|
||||
}
|
||||
|
||||
|
||||
type IfdBuilder struct {
|
||||
// ifd is the IfdIdentity instance of the IFD that owns the current tag.
|
||||
ii IfdIdentity
|
||||
@ -277,7 +274,7 @@ type IfdBuilder struct {
|
||||
byteOrder binary.ByteOrder
|
||||
|
||||
// Includes both normal tags and IFD tags (which point to child IFDs).
|
||||
tags []*builderTag
|
||||
tags []*BuilderTag
|
||||
|
||||
// existingOffset will be the offset that this IFD is currently found at if
|
||||
// it represents an IFD that has previously been stored (or 0 if not).
|
||||
@ -302,7 +299,7 @@ func NewIfdBuilder(ii IfdIdentity, byteOrder binary.ByteOrder) (ib *IfdBuilder)
|
||||
ifdTagId: ifdTagId,
|
||||
|
||||
byteOrder: byteOrder,
|
||||
tags: make([]*builderTag, 0),
|
||||
tags: make([]*BuilderTag, 0),
|
||||
}
|
||||
|
||||
return ib
|
||||
@ -333,7 +330,7 @@ func NewIfdBuilderWithExistingIfd(ifd *Ifd) (ib *IfdBuilder) {
|
||||
// NewIfdBuilderFromExistingChain creates a chain of IB instances from an
|
||||
// IFD chain generated from real data.
|
||||
func NewIfdBuilderFromExistingChain(rootIfd *Ifd, itevr *IfdTagEntryValueResolver) (firstIb *IfdBuilder) {
|
||||
// TODO(dustin): !! When we actually write the code to flatten the IB to bytes, make sure to skip the tags that have a nil value (which will happen when we add-from-exsting without a resolver instance).
|
||||
// TODO(dustin): !! When we actually write the code to flatten the IB to bytes, make sure to skip the tags that have a nil value (which will happen when we add-from-exsting without a resolver instance).
|
||||
|
||||
var lastIb *IfdBuilder
|
||||
i := 0
|
||||
@ -360,14 +357,14 @@ func NewIfdBuilderFromExistingChain(rootIfd *Ifd, itevr *IfdTagEntryValueResolve
|
||||
func (ib *IfdBuilder) String() string {
|
||||
nextIfdPhrase := ""
|
||||
if ib.nextIb != nil {
|
||||
// TODO(dustin): We were setting this to ii.String(), but we were getting hex-data when printing this after building from an existing chain.
|
||||
// TODO(dustin): We were setting this to ii.String(), but we were getting hex-data when printing this after building from an existing chain.
|
||||
nextIfdPhrase = ib.nextIb.ii.IfdName
|
||||
}
|
||||
|
||||
return fmt.Sprintf("IfdBuilder<PARENT-IFD=[%s] IFD=[%s] TAG-ID=(0x%04x) COUNT=(%d) OFF=(0x%04x) NEXT-IFD=(0x%04x)>", ib.ii.ParentIfdName, ib.ii.IfdName, ib.ifdTagId, len(ib.tags), ib.existingOffset, nextIfdPhrase)
|
||||
}
|
||||
|
||||
func (ib *IfdBuilder) Tags() (tags []*builderTag) {
|
||||
func (ib *IfdBuilder) Tags() (tags []*BuilderTag) {
|
||||
return ib.tags
|
||||
}
|
||||
|
||||
@ -393,19 +390,19 @@ func (ib *IfdBuilder) SetThumbnail(data []byte) (err error) {
|
||||
log.Panicf("thumbnails can only go into a root Ifd (and only the second one)")
|
||||
}
|
||||
|
||||
// TODO(dustin): !! Add a test for this.
|
||||
// TODO(dustin): !! Add a test for this.
|
||||
|
||||
if data == nil || len(data) == 0 {
|
||||
|
||||
// TODO(dustin): !! Debugging.
|
||||
// fmt.Printf("Thumbnail empty.\n")
|
||||
// TODO(dustin): !! Debugging.
|
||||
// fmt.Printf("Thumbnail empty.\n")
|
||||
|
||||
log.Panic("thumbnail is empty")
|
||||
}
|
||||
|
||||
ib.thumbnailData = data
|
||||
|
||||
// fmt.Printf("SETTING THUMBNAIL.\n")
|
||||
// fmt.Printf("SETTING THUMBNAIL.\n")
|
||||
|
||||
ibtvfb := NewIfdBuilderTagValueFromBytes(ib.thumbnailData)
|
||||
offsetBt := NewBuilderTag(ib.ii, ThumbnailOffsetTagId, TypeLong, ibtvfb)
|
||||
@ -414,15 +411,13 @@ func (ib *IfdBuilder) SetThumbnail(data []byte) (err error) {
|
||||
err = ib.Set(offsetBt)
|
||||
log.PanicIf(err)
|
||||
|
||||
sizeBt := NewStandardBuilderTagFromConfig(ib.ii, ThumbnailSizeTagId, ib.byteOrder, []uint32 { uint32(len(ib.thumbnailData)) })
|
||||
sizeBt := NewStandardBuilderTagFromConfig(ib.ii, ThumbnailSizeTagId, ib.byteOrder, []uint32{uint32(len(ib.thumbnailData))})
|
||||
|
||||
err = ib.Set(sizeBt)
|
||||
log.PanicIf(err)
|
||||
|
||||
|
||||
// TODO(dustin): !! Debugging.
|
||||
// fmt.Printf("Set thumbnail into IB.\n")
|
||||
|
||||
// TODO(dustin): !! Debugging.
|
||||
// fmt.Printf("Set thumbnail into IB.\n")
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -432,7 +427,7 @@ func (ib *IfdBuilder) Thumbnail() []byte {
|
||||
}
|
||||
|
||||
func (ib *IfdBuilder) printTagTree(levels int) {
|
||||
indent := strings.Repeat(" ", levels * 2)
|
||||
indent := strings.Repeat(" ", levels*2)
|
||||
|
||||
ti := NewTagIndex()
|
||||
i := 0
|
||||
@ -496,7 +491,7 @@ func (ib *IfdBuilder) PrintTagTree() {
|
||||
}
|
||||
|
||||
func (ib *IfdBuilder) printIfdTree(levels int) {
|
||||
indent := strings.Repeat(" ", levels * 2)
|
||||
indent := strings.Repeat(" ", levels*2)
|
||||
|
||||
i := 0
|
||||
for currentIb := ib; currentIb != nil; currentIb = currentIb.nextIb {
|
||||
@ -505,7 +500,7 @@ func (ib *IfdBuilder) printIfdTree(levels int) {
|
||||
prefix = ">"
|
||||
}
|
||||
|
||||
fmt.Printf("%s%s%s\n", indent, prefix,currentIb)
|
||||
fmt.Printf("%s%s%s\n", indent, prefix, currentIb)
|
||||
|
||||
if len(currentIb.tags) > 0 {
|
||||
for _, tag := range currentIb.tags {
|
||||
@ -588,7 +583,7 @@ func (ib *IfdBuilder) DeleteN(tagId uint16, n int) (err error) {
|
||||
log.Panicf("N must be at least 1: (%d)", n)
|
||||
}
|
||||
|
||||
for ; n > 0; {
|
||||
for n > 0 {
|
||||
j := -1
|
||||
for i, bt := range ib.tags {
|
||||
if bt.tagId == tagId {
|
||||
@ -601,7 +596,7 @@ func (ib *IfdBuilder) DeleteN(tagId uint16, n int) (err error) {
|
||||
log.Panic(ErrTagEntryNotFound)
|
||||
}
|
||||
|
||||
ib.tags = append(ib.tags[:j], ib.tags[j + 1:]...)
|
||||
ib.tags = append(ib.tags[:j], ib.tags[j+1:]...)
|
||||
n--
|
||||
}
|
||||
|
||||
@ -642,7 +637,7 @@ func (ib *IfdBuilder) DeleteAll(tagId uint16) (n int, err error) {
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func (ib *IfdBuilder) ReplaceAt(position int, bt *builderTag) (err error) {
|
||||
func (ib *IfdBuilder) ReplaceAt(position int, bt *BuilderTag) (err error) {
|
||||
defer func() {
|
||||
if state := recover(); state != nil {
|
||||
err = log.Wrap(state.(error))
|
||||
@ -660,7 +655,7 @@ func (ib *IfdBuilder) ReplaceAt(position int, bt *builderTag) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ib *IfdBuilder) Replace(tagId uint16, bt *builderTag) (err error) {
|
||||
func (ib *IfdBuilder) Replace(tagId uint16, bt *BuilderTag) (err error) {
|
||||
defer func() {
|
||||
if state := recover(); state != nil {
|
||||
err = log.Wrap(state.(error))
|
||||
@ -676,7 +671,7 @@ func (ib *IfdBuilder) Replace(tagId uint16, bt *builderTag) (err error) {
|
||||
}
|
||||
|
||||
// Set will add a new entry or update an existing entry.
|
||||
func (ib *IfdBuilder) Set(bt *builderTag) (err error) {
|
||||
func (ib *IfdBuilder) Set(bt *BuilderTag) (err error) {
|
||||
defer func() {
|
||||
if state := recover(); state != nil {
|
||||
err = log.Wrap(state.(error))
|
||||
@ -734,7 +729,7 @@ func (ib *IfdBuilder) Find(tagId uint16) (position int, err error) {
|
||||
return found[0], nil
|
||||
}
|
||||
|
||||
func (ib *IfdBuilder) FindTag(tagId uint16) (bt *builderTag, err error) {
|
||||
func (ib *IfdBuilder) FindTag(tagId uint16) (bt *BuilderTag, err error) {
|
||||
defer func() {
|
||||
if state := recover(); state != nil {
|
||||
err = log.Wrap(state.(error))
|
||||
@ -753,7 +748,7 @@ func (ib *IfdBuilder) FindTag(tagId uint16) (bt *builderTag, err error) {
|
||||
return ib.tags[position], nil
|
||||
}
|
||||
|
||||
func (ib *IfdBuilder) FindTagWithName(tagName string) (bt *builderTag, err error) {
|
||||
func (ib *IfdBuilder) FindTagWithName(tagName string) (bt *BuilderTag, err error) {
|
||||
defer func() {
|
||||
if state := recover(); state != nil {
|
||||
err = log.Wrap(state.(error))
|
||||
@ -777,7 +772,7 @@ func (ib *IfdBuilder) FindTagWithName(tagName string) (bt *builderTag, err error
|
||||
return ib.tags[position], nil
|
||||
}
|
||||
|
||||
func (ib *IfdBuilder) add(bt *builderTag) (err error) {
|
||||
func (ib *IfdBuilder) add(bt *BuilderTag) (err error) {
|
||||
defer func() {
|
||||
if state := recover(); state != nil {
|
||||
err = log.Wrap(state.(error))
|
||||
@ -785,18 +780,18 @@ func (ib *IfdBuilder) add(bt *builderTag) (err error) {
|
||||
}()
|
||||
|
||||
if bt.ii == ZeroIi {
|
||||
log.Panicf("builderTag IfdIdentity is not set: %s", bt)
|
||||
log.Panicf("BuilderTag IfdIdentity is not set: %s", bt)
|
||||
} else if bt.typeId == 0x0 {
|
||||
log.Panicf("builderTag type-ID is not set: %s", bt)
|
||||
log.Panicf("BuilderTag type-ID is not set: %s", bt)
|
||||
} else if bt.value == nil {
|
||||
log.Panicf("builderTag value is not set: %s", bt)
|
||||
log.Panicf("BuilderTag value is not set: %s", bt)
|
||||
}
|
||||
|
||||
ib.tags = append(ib.tags, bt)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ib *IfdBuilder) Add(bt *builderTag) (err error) {
|
||||
func (ib *IfdBuilder) Add(bt *BuilderTag) (err error) {
|
||||
defer func() {
|
||||
if state := recover(); state != nil {
|
||||
err = log.Wrap(state.(error))
|
||||
@ -842,7 +837,7 @@ func (ib *IfdBuilder) AddChildIb(childIb *IfdBuilder) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ib *IfdBuilder) NewBuilderTagFromBuilder(childIb *IfdBuilder) (bt *builderTag) {
|
||||
func (ib *IfdBuilder) NewBuilderTagFromBuilder(childIb *IfdBuilder) (bt *BuilderTag) {
|
||||
defer func() {
|
||||
if state := recover(); state != nil {
|
||||
err := log.Wrap(state.(error))
|
||||
@ -914,7 +909,7 @@ func (ib *IfdBuilder) AddTagsFromExisting(ifd *Ifd, itevr *IfdTagEntryValueResol
|
||||
}
|
||||
}
|
||||
|
||||
var bt *builderTag
|
||||
var bt *BuilderTag
|
||||
|
||||
if ite.ChildIfdName != "" {
|
||||
// If we want to add an IFD tag, we'll have to build it first and
|
||||
@ -927,7 +922,7 @@ func (ib *IfdBuilder) AddTagsFromExisting(ifd *Ifd, itevr *IfdTagEntryValueResol
|
||||
// though, since its original offset will no longer be valid
|
||||
// (nor does it matter since this is just a temporary
|
||||
// placeholder, in this situation).
|
||||
value := NewIfdBuilderTagValueFromBytes([]byte { 0, 0, 0, 0 })
|
||||
value := NewIfdBuilderTagValueFromBytes([]byte{0, 0, 0, 0})
|
||||
bt = NewBuilderTag(ite.Ii, ite.TagId, ite.TagType, value)
|
||||
} else {
|
||||
// Figure out which of the child-IFDs that are associated with
|
||||
@ -1019,7 +1014,7 @@ func (ib *IfdBuilder) SetFromConfig(tagId uint16, value interface{}) (err error)
|
||||
}
|
||||
}()
|
||||
|
||||
// TODO(dustin): !! Add test.
|
||||
// TODO(dustin): !! Add test.
|
||||
|
||||
bt := NewStandardBuilderTagFromConfig(ib.ii, tagId, ib.byteOrder, value)
|
||||
|
||||
@ -1059,7 +1054,7 @@ func (ib *IfdBuilder) SetFromConfigWithName(tagName string, value interface{}) (
|
||||
}
|
||||
}()
|
||||
|
||||
// TODO(dustin): !! Add test.
|
||||
// TODO(dustin): !! Add test.
|
||||
|
||||
bt := NewStandardBuilderTagFromConfigWithName(ib.ii, tagName, ib.byteOrder, value)
|
||||
|
||||
|
@ -84,7 +84,6 @@ func (bw ByteWriter) WriteFourBytes(value []byte) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
// ifdOffsetIterator keeps track of where the next IFD should be written by
|
||||
// keeping track of where the offsets start, the data that has been added, and
|
||||
// bumping the offset *when* the data is added.
|
||||
@ -93,7 +92,7 @@ type ifdDataAllocator struct {
|
||||
b bytes.Buffer
|
||||
}
|
||||
|
||||
func newIfdDataAllocator(ifdDataAddressableOffset uint32) *ifdDataAllocator{
|
||||
func newIfdDataAllocator(ifdDataAddressableOffset uint32) *ifdDataAllocator {
|
||||
return &ifdDataAllocator{
|
||||
offset: ifdDataAddressableOffset,
|
||||
}
|
||||
@ -117,7 +116,6 @@ func (ida *ifdDataAllocator) Bytes() []byte {
|
||||
return ida.b.Bytes()
|
||||
}
|
||||
|
||||
|
||||
// IfdByteEncoder converts an IB to raw bytes (for writing) while also figuring
|
||||
// out all of the allocations and indirection that is required for extended
|
||||
// data.
|
||||
@ -142,7 +140,7 @@ func (ibe *IfdByteEncoder) TableSize(entryCount int) uint32 {
|
||||
}
|
||||
|
||||
func (ibe *IfdByteEncoder) pushToJournal(where, direction, format string, args ...interface{}) {
|
||||
event := [3]string {
|
||||
event := [3]string{
|
||||
direction,
|
||||
where,
|
||||
fmt.Sprintf(format, args...),
|
||||
@ -201,7 +199,7 @@ func (ibe *IfdByteEncoder) PrintJournal() {
|
||||
// (`nextIfdOffsetToWrite` is required in order for them to know where the its
|
||||
// IFD data will be written, in order for them to know the offset of where
|
||||
// their allocated-data block will start, which follows right behind).
|
||||
func (ibe *IfdByteEncoder) encodeTagToBytes(ib *IfdBuilder, bt *builderTag, bw *ByteWriter, ida *ifdDataAllocator, nextIfdOffsetToWrite uint32) (childIfdBlock []byte, err error) {
|
||||
func (ibe *IfdByteEncoder) encodeTagToBytes(ib *IfdBuilder, bt *BuilderTag, bw *ByteWriter, ida *ifdDataAllocator, nextIfdOffsetToWrite uint32) (childIfdBlock []byte, err error) {
|
||||
defer func() {
|
||||
if state := recover(); state != nil {
|
||||
err = log.Wrap(state.(error))
|
||||
@ -389,7 +387,7 @@ func (ibe *IfdByteEncoder) encodeIfdToBytes(ib *IfdBuilder, ifdAddressableOffset
|
||||
_, err = b.Write(dataBytes)
|
||||
log.PanicIf(err)
|
||||
|
||||
// TODO(dustin): !! Debugging.
|
||||
// TODO(dustin): !! Debugging.
|
||||
// if thumbnailOffset != uint32(0) {
|
||||
// currentRelativeOffset := thumbnailOffset - ifdAddressableOffset
|
||||
// currentBuffer := b.Bytes()
|
||||
@ -402,9 +400,9 @@ func (ibe *IfdByteEncoder) encodeIfdToBytes(ib *IfdBuilder, ifdAddressableOffset
|
||||
// log.Panicf("extracted thumbnail data was truncated; not enough data")
|
||||
// }
|
||||
|
||||
// // fmt.Printf("Re-extracted (%d) bytes of thumbnail data.\n", len(extractedThumbnailData))
|
||||
// // DumpBytes(extractedThumbnailData[:50])
|
||||
// }
|
||||
// // fmt.Printf("Re-extracted (%d) bytes of thumbnail data.\n", len(extractedThumbnailData))
|
||||
// // DumpBytes(extractedThumbnailData[:50])
|
||||
// }
|
||||
|
||||
// Append any child IFD blocks after our table and data blocks. These IFDs
|
||||
// were equipped with the appropriate offset information so it's expected
|
||||
@ -422,12 +420,12 @@ func (ibe *IfdByteEncoder) encodeIfdToBytes(ib *IfdBuilder, ifdAddressableOffset
|
||||
|
||||
ibe.pushToJournal("encodeIfdToBytes", "<", "%s", ib)
|
||||
|
||||
// if nextIfdOffsetToWrite > uint32(0) {
|
||||
// fmt.Printf("Encoded IB: %s ADDRESSABLE-OFFSET=(0x%08x; %d):\n", ib.ii, ifdAddressableOffset, ifdAddressableOffset)
|
||||
// fmt.Printf("\n")
|
||||
// DumpBytes(b.Bytes())
|
||||
// fmt.Printf("\n")
|
||||
// }
|
||||
// if nextIfdOffsetToWrite > uint32(0) {
|
||||
// fmt.Printf("Encoded IB: %s ADDRESSABLE-OFFSET=(0x%08x; %d):\n", ib.ii, ifdAddressableOffset, ifdAddressableOffset)
|
||||
// fmt.Printf("\n")
|
||||
// DumpBytes(b.Bytes())
|
||||
// fmt.Printf("\n")
|
||||
// }
|
||||
|
||||
return b.Bytes(), tableSize, dataSize, childIfdSizes, nil
|
||||
}
|
||||
@ -450,11 +448,10 @@ func (ibe *IfdByteEncoder) encodeAndAttachIfd(ib *IfdBuilder, ifdAddressableOffs
|
||||
|
||||
i := 0
|
||||
|
||||
// TODO(dustin): !! We suspect there's an issue with encoding sibling IFDs, here.
|
||||
// TODO(dustin): !! We suspect there's an issue with encoding sibling IFDs, here.
|
||||
|
||||
for thisIb := ib; thisIb != nil; thisIb = thisIb.nextIb {
|
||||
|
||||
|
||||
// Do a dry-run in order to pre-determine its size requirement.
|
||||
|
||||
ibe.pushToJournal("encodeAndAttachIfd", ">", "Beginning encoding process: (%d) [%s]", i, thisIb.ii.IfdName)
|
||||
@ -496,18 +493,18 @@ func (ibe *IfdByteEncoder) encodeAndAttachIfd(ib *IfdBuilder, ifdAddressableOffs
|
||||
totalChildIfdSize += childIfdSize
|
||||
}
|
||||
|
||||
if len(tableAndAllocated) != int(tableSize + allocatedDataSize + totalChildIfdSize) {
|
||||
log.Panicf("IFD table and data is not a consistent size: (%d) != (%d)", len(tableAndAllocated), tableSize + allocatedDataSize + totalChildIfdSize)
|
||||
if len(tableAndAllocated) != int(tableSize+allocatedDataSize+totalChildIfdSize) {
|
||||
log.Panicf("IFD table and data is not a consistent size: (%d) != (%d)", len(tableAndAllocated), tableSize+allocatedDataSize+totalChildIfdSize)
|
||||
}
|
||||
|
||||
// TODO(dustin): !! We might want to verify the original tableAndAllocated length, too.
|
||||
// TODO(dustin): !! We might want to verify the original tableAndAllocated length, too.
|
||||
|
||||
_, err = b.Write(tableAndAllocated)
|
||||
log.PanicIf(err)
|
||||
|
||||
// Advance past what we've allocated, thus far.
|
||||
|
||||
// TODO(dustin): !! If this doesn't work (or doesn't work easily), we may need to send a complex type for the addressable-offset instead of a simple integer.
|
||||
// TODO(dustin): !! If this doesn't work (or doesn't work easily), we may need to send a complex type for the addressable-offset instead of a simple integer.
|
||||
ifdAddressableOffset += allocatedDataSize + totalChildIfdSize
|
||||
|
||||
ibe.pushToJournal("encodeAndAttachIfd", "<", "Finishing encoding process: (%d) [%s] [FINAL:] NEXT-IFD-OFFSET-TO-WRITE=(0x%08x)", i, ib.ii.IfdName, nextIfdOffsetToWrite)
|
||||
|
@ -1,12 +1,12 @@
|
||||
package exif
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"reflect"
|
||||
"bytes"
|
||||
"path"
|
||||
"fmt"
|
||||
"path"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/dsoprea/go-logging"
|
||||
)
|
||||
@ -14,7 +14,7 @@ import (
|
||||
func TestAdd(t *testing.T) {
|
||||
ib := NewIfdBuilder(RootIi, TestDefaultByteOrder)
|
||||
|
||||
bt := &builderTag{
|
||||
bt := &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x11,
|
||||
@ -24,7 +24,7 @@ func TestAdd(t *testing.T) {
|
||||
err := ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x22,
|
||||
@ -34,7 +34,7 @@ func TestAdd(t *testing.T) {
|
||||
err = ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x33,
|
||||
@ -44,9 +44,9 @@ func TestAdd(t *testing.T) {
|
||||
err = ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
originalBytes := []byte { 0x11, 0x22, 0x33 }
|
||||
originalBytes := []byte{0x11, 0x22, 0x33}
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x44,
|
||||
@ -119,7 +119,7 @@ func TestAddChildIb(t *testing.T) {
|
||||
|
||||
ib := NewIfdBuilder(RootIi, TestDefaultByteOrder)
|
||||
|
||||
bt := &builderTag{
|
||||
bt := &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x11,
|
||||
@ -135,7 +135,7 @@ func TestAddChildIb(t *testing.T) {
|
||||
err = ib.AddChildIb(ibChild)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x22,
|
||||
@ -173,7 +173,7 @@ func TestAddTagsFromExisting(t *testing.T) {
|
||||
TagId: 0x11,
|
||||
TagType: TypeByte,
|
||||
UnitCount: 4,
|
||||
RawValueOffset: []byte { 0x12, 0, 0, 0 },
|
||||
RawValueOffset: []byte{0x12, 0, 0, 0},
|
||||
}
|
||||
|
||||
entries[1] = &IfdTagEntry{
|
||||
@ -188,7 +188,7 @@ func TestAddTagsFromExisting(t *testing.T) {
|
||||
TagId: 0x33,
|
||||
TagType: TypeByte,
|
||||
UnitCount: 4,
|
||||
RawValueOffset: []byte { 0x34, 0, 0, 0 },
|
||||
RawValueOffset: []byte{0x34, 0, 0, 0},
|
||||
}
|
||||
|
||||
ifd := &Ifd{
|
||||
@ -239,7 +239,7 @@ func TestAddTagsFromExisting__Includes(t *testing.T) {
|
||||
Entries: entries,
|
||||
}
|
||||
|
||||
err := ib.AddTagsFromExisting(ifd, nil, []uint16 { 0x33 }, nil)
|
||||
err := ib.AddTagsFromExisting(ifd, nil, []uint16{0x33}, nil)
|
||||
log.PanicIf(err)
|
||||
|
||||
if ib.tags[0].tagId != 0x33 {
|
||||
@ -278,7 +278,7 @@ func TestAddTagsFromExisting__Excludes(t *testing.T) {
|
||||
Entries: entries,
|
||||
}
|
||||
|
||||
err := ib.AddTagsFromExisting(ifd, nil, nil, []uint16 { 0x11 })
|
||||
err := ib.AddTagsFromExisting(ifd, nil, nil, []uint16{0x11})
|
||||
log.PanicIf(err)
|
||||
|
||||
if ib.tags[0].tagId != 0x22 {
|
||||
@ -291,7 +291,7 @@ func TestAddTagsFromExisting__Excludes(t *testing.T) {
|
||||
func TestFindN_First_1(t *testing.T) {
|
||||
ib := NewIfdBuilder(RootIi, TestDefaultByteOrder)
|
||||
|
||||
bt := &builderTag{
|
||||
bt := &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x11,
|
||||
@ -301,7 +301,7 @@ func TestFindN_First_1(t *testing.T) {
|
||||
err := ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x22,
|
||||
@ -311,7 +311,7 @@ func TestFindN_First_1(t *testing.T) {
|
||||
err = ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x33,
|
||||
@ -341,7 +341,7 @@ func TestFindN_First_1(t *testing.T) {
|
||||
func TestFindN_First_2_1Returned(t *testing.T) {
|
||||
ib := NewIfdBuilder(RootIi, TestDefaultByteOrder)
|
||||
|
||||
bt := &builderTag{
|
||||
bt := &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x11,
|
||||
@ -351,7 +351,7 @@ func TestFindN_First_2_1Returned(t *testing.T) {
|
||||
err := ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x22,
|
||||
@ -361,7 +361,7 @@ func TestFindN_First_2_1Returned(t *testing.T) {
|
||||
err = ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x33,
|
||||
@ -391,7 +391,7 @@ func TestFindN_First_2_1Returned(t *testing.T) {
|
||||
func TestFindN_First_2_2Returned(t *testing.T) {
|
||||
ib := NewIfdBuilder(RootIi, TestDefaultByteOrder)
|
||||
|
||||
bt := &builderTag{
|
||||
bt := &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x11,
|
||||
@ -401,7 +401,7 @@ func TestFindN_First_2_2Returned(t *testing.T) {
|
||||
err := ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x22,
|
||||
@ -411,7 +411,7 @@ func TestFindN_First_2_2Returned(t *testing.T) {
|
||||
err = ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x33,
|
||||
@ -421,7 +421,7 @@ func TestFindN_First_2_2Returned(t *testing.T) {
|
||||
err = ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x11,
|
||||
@ -431,7 +431,7 @@ func TestFindN_First_2_2Returned(t *testing.T) {
|
||||
err = ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x11,
|
||||
@ -468,7 +468,7 @@ func TestFindN_First_2_2Returned(t *testing.T) {
|
||||
func TestFindN_Middle_WithDuplicates(t *testing.T) {
|
||||
ib := NewIfdBuilder(RootIi, TestDefaultByteOrder)
|
||||
|
||||
bt := &builderTag{
|
||||
bt := &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x11,
|
||||
@ -478,7 +478,7 @@ func TestFindN_Middle_WithDuplicates(t *testing.T) {
|
||||
err := ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x22,
|
||||
@ -488,7 +488,7 @@ func TestFindN_Middle_WithDuplicates(t *testing.T) {
|
||||
err = ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x33,
|
||||
@ -498,7 +498,7 @@ func TestFindN_Middle_WithDuplicates(t *testing.T) {
|
||||
err = ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x11,
|
||||
@ -508,7 +508,7 @@ func TestFindN_Middle_WithDuplicates(t *testing.T) {
|
||||
err = ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x11,
|
||||
@ -518,7 +518,7 @@ func TestFindN_Middle_WithDuplicates(t *testing.T) {
|
||||
err = ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x33,
|
||||
@ -548,7 +548,7 @@ func TestFindN_Middle_WithDuplicates(t *testing.T) {
|
||||
func TestFindN_Middle_NoDuplicates(t *testing.T) {
|
||||
ib := NewIfdBuilder(RootIi, TestDefaultByteOrder)
|
||||
|
||||
bt := &builderTag{
|
||||
bt := &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x11,
|
||||
@ -558,7 +558,7 @@ func TestFindN_Middle_NoDuplicates(t *testing.T) {
|
||||
err := ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x22,
|
||||
@ -568,7 +568,7 @@ func TestFindN_Middle_NoDuplicates(t *testing.T) {
|
||||
err = ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x33,
|
||||
@ -578,7 +578,7 @@ func TestFindN_Middle_NoDuplicates(t *testing.T) {
|
||||
err = ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x11,
|
||||
@ -619,7 +619,7 @@ func TestFindN_Miss(t *testing.T) {
|
||||
func TestFind_Hit(t *testing.T) {
|
||||
ib := NewIfdBuilder(RootIi, TestDefaultByteOrder)
|
||||
|
||||
bt := &builderTag{
|
||||
bt := &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x11,
|
||||
@ -629,7 +629,7 @@ func TestFind_Hit(t *testing.T) {
|
||||
err := ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x22,
|
||||
@ -639,7 +639,7 @@ func TestFind_Hit(t *testing.T) {
|
||||
err = ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x33,
|
||||
@ -649,7 +649,7 @@ func TestFind_Hit(t *testing.T) {
|
||||
err = ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x11,
|
||||
@ -677,7 +677,7 @@ func TestFind_Hit(t *testing.T) {
|
||||
func TestFind_Miss(t *testing.T) {
|
||||
ib := NewIfdBuilder(RootIi, TestDefaultByteOrder)
|
||||
|
||||
bt := &builderTag{
|
||||
bt := &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x11,
|
||||
@ -687,7 +687,7 @@ func TestFind_Miss(t *testing.T) {
|
||||
err := ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x22,
|
||||
@ -697,7 +697,7 @@ func TestFind_Miss(t *testing.T) {
|
||||
err = ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x33,
|
||||
@ -707,7 +707,7 @@ func TestFind_Miss(t *testing.T) {
|
||||
err = ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x11,
|
||||
@ -728,7 +728,7 @@ func TestFind_Miss(t *testing.T) {
|
||||
func TestReplace(t *testing.T) {
|
||||
ib := NewIfdBuilder(RootIi, TestDefaultByteOrder)
|
||||
|
||||
bt := &builderTag{
|
||||
bt := &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x11,
|
||||
@ -738,7 +738,7 @@ func TestReplace(t *testing.T) {
|
||||
err := ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x22,
|
||||
@ -748,7 +748,7 @@ func TestReplace(t *testing.T) {
|
||||
err = ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x33,
|
||||
@ -763,11 +763,11 @@ func TestReplace(t *testing.T) {
|
||||
currentIds[i] = bt.tagId
|
||||
}
|
||||
|
||||
if reflect.DeepEqual([]uint16 { 0x11, 0x22, 0x33 }, currentIds) == false {
|
||||
if reflect.DeepEqual([]uint16{0x11, 0x22, 0x33}, currentIds) == false {
|
||||
t.Fatalf("Pre-replace tags are not correct.")
|
||||
}
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x99,
|
||||
@ -782,7 +782,7 @@ func TestReplace(t *testing.T) {
|
||||
currentIds[i] = bt.tagId
|
||||
}
|
||||
|
||||
if reflect.DeepEqual([]uint16 { 0x11, 0x99, 0x33 }, currentIds) == false {
|
||||
if reflect.DeepEqual([]uint16{0x11, 0x99, 0x33}, currentIds) == false {
|
||||
t.Fatalf("Post-replace tags are not correct.")
|
||||
}
|
||||
}
|
||||
@ -790,7 +790,7 @@ func TestReplace(t *testing.T) {
|
||||
func TestReplaceN(t *testing.T) {
|
||||
ib := NewIfdBuilder(RootIi, TestDefaultByteOrder)
|
||||
|
||||
bt := &builderTag{
|
||||
bt := &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x11,
|
||||
@ -800,7 +800,7 @@ func TestReplaceN(t *testing.T) {
|
||||
err := ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x22,
|
||||
@ -810,7 +810,7 @@ func TestReplaceN(t *testing.T) {
|
||||
err = ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x33,
|
||||
@ -825,11 +825,11 @@ func TestReplaceN(t *testing.T) {
|
||||
currentIds[i] = bt.tagId
|
||||
}
|
||||
|
||||
if reflect.DeepEqual([]uint16 { 0x11, 0x22, 0x33 }, currentIds) == false {
|
||||
if reflect.DeepEqual([]uint16{0x11, 0x22, 0x33}, currentIds) == false {
|
||||
t.Fatalf("Pre-replace tags are not correct.")
|
||||
}
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0xA9,
|
||||
@ -844,7 +844,7 @@ func TestReplaceN(t *testing.T) {
|
||||
currentIds[i] = bt.tagId
|
||||
}
|
||||
|
||||
if reflect.DeepEqual([]uint16 { 0x11, 0xA9, 0x33 }, currentIds) == false {
|
||||
if reflect.DeepEqual([]uint16{0x11, 0xA9, 0x33}, currentIds) == false {
|
||||
t.Fatalf("Post-replace tags are not correct.")
|
||||
}
|
||||
}
|
||||
@ -852,7 +852,7 @@ func TestReplaceN(t *testing.T) {
|
||||
func TestDeleteFirst(t *testing.T) {
|
||||
ib := NewIfdBuilder(RootIi, TestDefaultByteOrder)
|
||||
|
||||
bt := &builderTag{
|
||||
bt := &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x11,
|
||||
@ -862,7 +862,7 @@ func TestDeleteFirst(t *testing.T) {
|
||||
err := ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x22,
|
||||
@ -872,7 +872,7 @@ func TestDeleteFirst(t *testing.T) {
|
||||
err = ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x22,
|
||||
@ -882,7 +882,7 @@ func TestDeleteFirst(t *testing.T) {
|
||||
err = ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x33,
|
||||
@ -892,7 +892,6 @@ func TestDeleteFirst(t *testing.T) {
|
||||
err = ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
|
||||
if len(ib.Tags()) != 4 {
|
||||
t.Fatalf("Pre-delete tag count not correct.")
|
||||
}
|
||||
@ -902,11 +901,10 @@ func TestDeleteFirst(t *testing.T) {
|
||||
currentIds[i] = bt.tagId
|
||||
}
|
||||
|
||||
if reflect.DeepEqual([]uint16 { 0x11, 0x22, 0x22, 0x33 }, currentIds) == false {
|
||||
if reflect.DeepEqual([]uint16{0x11, 0x22, 0x22, 0x33}, currentIds) == false {
|
||||
t.Fatalf("Pre-delete tags not correct.")
|
||||
}
|
||||
|
||||
|
||||
err = ib.DeleteFirst(0x22)
|
||||
log.PanicIf(err)
|
||||
|
||||
@ -919,11 +917,10 @@ func TestDeleteFirst(t *testing.T) {
|
||||
currentIds[i] = bt.tagId
|
||||
}
|
||||
|
||||
if reflect.DeepEqual([]uint16 { 0x11, 0x22, 0x33 }, currentIds) == false {
|
||||
if reflect.DeepEqual([]uint16{0x11, 0x22, 0x33}, currentIds) == false {
|
||||
t.Fatalf("Post-delete (1) tags not correct.")
|
||||
}
|
||||
|
||||
|
||||
err = ib.DeleteFirst(0x22)
|
||||
log.PanicIf(err)
|
||||
|
||||
@ -936,11 +933,10 @@ func TestDeleteFirst(t *testing.T) {
|
||||
currentIds[i] = bt.tagId
|
||||
}
|
||||
|
||||
if reflect.DeepEqual([]uint16 { 0x11, 0x33 }, currentIds) == false {
|
||||
if reflect.DeepEqual([]uint16{0x11, 0x33}, currentIds) == false {
|
||||
t.Fatalf("Post-delete (2) tags not correct.")
|
||||
}
|
||||
|
||||
|
||||
err = ib.DeleteFirst(0x22)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected an error.")
|
||||
@ -952,7 +948,7 @@ func TestDeleteFirst(t *testing.T) {
|
||||
func TestDeleteN(t *testing.T) {
|
||||
ib := NewIfdBuilder(RootIi, TestDefaultByteOrder)
|
||||
|
||||
bt := &builderTag{
|
||||
bt := &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x11,
|
||||
@ -962,7 +958,7 @@ func TestDeleteN(t *testing.T) {
|
||||
err := ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x22,
|
||||
@ -972,7 +968,7 @@ func TestDeleteN(t *testing.T) {
|
||||
err = ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x22,
|
||||
@ -982,7 +978,7 @@ func TestDeleteN(t *testing.T) {
|
||||
err = ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x33,
|
||||
@ -992,7 +988,6 @@ func TestDeleteN(t *testing.T) {
|
||||
err = ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
|
||||
if len(ib.Tags()) != 4 {
|
||||
t.Fatalf("Pre-delete tag count not correct.")
|
||||
}
|
||||
@ -1002,11 +997,10 @@ func TestDeleteN(t *testing.T) {
|
||||
currentIds[i] = bt.tagId
|
||||
}
|
||||
|
||||
if reflect.DeepEqual([]uint16 { 0x11, 0x22, 0x22, 0x33 }, currentIds) == false {
|
||||
if reflect.DeepEqual([]uint16{0x11, 0x22, 0x22, 0x33}, currentIds) == false {
|
||||
t.Fatalf("Pre-delete tags not correct.")
|
||||
}
|
||||
|
||||
|
||||
err = ib.DeleteN(0x22, 1)
|
||||
log.PanicIf(err)
|
||||
|
||||
@ -1019,11 +1013,10 @@ func TestDeleteN(t *testing.T) {
|
||||
currentIds[i] = bt.tagId
|
||||
}
|
||||
|
||||
if reflect.DeepEqual([]uint16 { 0x11, 0x22, 0x33 }, currentIds) == false {
|
||||
if reflect.DeepEqual([]uint16{0x11, 0x22, 0x33}, currentIds) == false {
|
||||
t.Fatalf("Post-delete (1) tags not correct.")
|
||||
}
|
||||
|
||||
|
||||
err = ib.DeleteN(0x22, 1)
|
||||
log.PanicIf(err)
|
||||
|
||||
@ -1036,11 +1029,10 @@ func TestDeleteN(t *testing.T) {
|
||||
currentIds[i] = bt.tagId
|
||||
}
|
||||
|
||||
if reflect.DeepEqual([]uint16 { 0x11, 0x33 }, currentIds) == false {
|
||||
if reflect.DeepEqual([]uint16{0x11, 0x33}, currentIds) == false {
|
||||
t.Fatalf("Post-delete (2) tags not correct.")
|
||||
}
|
||||
|
||||
|
||||
err = ib.DeleteN(0x22, 1)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected an error.")
|
||||
@ -1052,7 +1044,7 @@ func TestDeleteN(t *testing.T) {
|
||||
func TestDeleteN_Two(t *testing.T) {
|
||||
ib := NewIfdBuilder(RootIi, TestDefaultByteOrder)
|
||||
|
||||
bt := &builderTag{
|
||||
bt := &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x11,
|
||||
@ -1062,7 +1054,7 @@ func TestDeleteN_Two(t *testing.T) {
|
||||
err := ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x22,
|
||||
@ -1072,7 +1064,7 @@ func TestDeleteN_Two(t *testing.T) {
|
||||
err = ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x22,
|
||||
@ -1082,7 +1074,7 @@ func TestDeleteN_Two(t *testing.T) {
|
||||
err = ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x33,
|
||||
@ -1092,7 +1084,6 @@ func TestDeleteN_Two(t *testing.T) {
|
||||
err = ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
|
||||
if len(ib.Tags()) != 4 {
|
||||
t.Fatalf("Pre-delete tag count not correct.")
|
||||
}
|
||||
@ -1102,11 +1093,10 @@ func TestDeleteN_Two(t *testing.T) {
|
||||
currentIds[i] = bt.tagId
|
||||
}
|
||||
|
||||
if reflect.DeepEqual([]uint16 { 0x11, 0x22, 0x22, 0x33 }, currentIds) == false {
|
||||
if reflect.DeepEqual([]uint16{0x11, 0x22, 0x22, 0x33}, currentIds) == false {
|
||||
t.Fatalf("Pre-delete tags not correct.")
|
||||
}
|
||||
|
||||
|
||||
err = ib.DeleteN(0x22, 2)
|
||||
log.PanicIf(err)
|
||||
|
||||
@ -1119,11 +1109,10 @@ func TestDeleteN_Two(t *testing.T) {
|
||||
currentIds[i] = bt.tagId
|
||||
}
|
||||
|
||||
if reflect.DeepEqual([]uint16 { 0x11, 0x33 }, currentIds) == false {
|
||||
if reflect.DeepEqual([]uint16{0x11, 0x33}, currentIds) == false {
|
||||
t.Fatalf("Post-delete tags not correct.")
|
||||
}
|
||||
|
||||
|
||||
err = ib.DeleteFirst(0x22)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected an error.")
|
||||
@ -1135,7 +1124,7 @@ func TestDeleteN_Two(t *testing.T) {
|
||||
func TestDeleteAll(t *testing.T) {
|
||||
ib := NewIfdBuilder(RootIi, TestDefaultByteOrder)
|
||||
|
||||
bt := &builderTag{
|
||||
bt := &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x11,
|
||||
@ -1145,7 +1134,7 @@ func TestDeleteAll(t *testing.T) {
|
||||
err := ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x22,
|
||||
@ -1155,7 +1144,7 @@ func TestDeleteAll(t *testing.T) {
|
||||
err = ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x22,
|
||||
@ -1165,7 +1154,7 @@ func TestDeleteAll(t *testing.T) {
|
||||
err = ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
bt = &builderTag{
|
||||
bt = &BuilderTag{
|
||||
ii: RootIi,
|
||||
typeId: TypeByte,
|
||||
tagId: 0x33,
|
||||
@ -1175,7 +1164,6 @@ func TestDeleteAll(t *testing.T) {
|
||||
err = ib.Add(bt)
|
||||
log.PanicIf(err)
|
||||
|
||||
|
||||
if len(ib.Tags()) != 4 {
|
||||
t.Fatalf("Pre-delete tag count not correct.")
|
||||
}
|
||||
@ -1185,11 +1173,10 @@ func TestDeleteAll(t *testing.T) {
|
||||
currentIds[i] = bt.tagId
|
||||
}
|
||||
|
||||
if reflect.DeepEqual([]uint16 { 0x11, 0x22, 0x22, 0x33 }, currentIds) == false {
|
||||
if reflect.DeepEqual([]uint16{0x11, 0x22, 0x22, 0x33}, currentIds) == false {
|
||||
t.Fatalf("Pre-delete tags not correct.")
|
||||
}
|
||||
|
||||
|
||||
n, err := ib.DeleteAll(0x22)
|
||||
log.PanicIf(err)
|
||||
|
||||
@ -1204,11 +1191,10 @@ func TestDeleteAll(t *testing.T) {
|
||||
currentIds[i] = bt.tagId
|
||||
}
|
||||
|
||||
if reflect.DeepEqual([]uint16 { 0x11, 0x33 }, currentIds) == false {
|
||||
if reflect.DeepEqual([]uint16{0x11, 0x33}, currentIds) == false {
|
||||
t.Fatalf("Post-delete tags not correct.")
|
||||
}
|
||||
|
||||
|
||||
err = ib.DeleteFirst(0x22)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected an error.")
|
||||
@ -1240,7 +1226,7 @@ func Test_IfdBuilder_CreateIfdBuilderFromExistingChain(t *testing.T) {
|
||||
|
||||
actual := ib.DumpToStrings()
|
||||
|
||||
expected := []string {
|
||||
expected := []string{
|
||||
"<PARENTS=[] IFD-NAME=[IFD]> IFD-TAG-ID=(0x0000) CHILD-IFD=[] INDEX=(0) TAG=[0x010f]",
|
||||
"<PARENTS=[] IFD-NAME=[IFD]> IFD-TAG-ID=(0x0000) CHILD-IFD=[] INDEX=(1) TAG=[0x0110]",
|
||||
"<PARENTS=[] IFD-NAME=[IFD]> IFD-TAG-ID=(0x0000) CHILD-IFD=[] INDEX=(2) TAG=[0x0112]",
|
||||
@ -1309,7 +1295,6 @@ func Test_IfdBuilder_CreateIfdBuilderFromExistingChain_RealData(t *testing.T) {
|
||||
|
||||
e := NewExif()
|
||||
|
||||
|
||||
rawExif, err := e.SearchAndExtractExif(filepath)
|
||||
log.PanicIf(err)
|
||||
|
||||
@ -1323,7 +1308,6 @@ func Test_IfdBuilder_CreateIfdBuilderFromExistingChain_RealData(t *testing.T) {
|
||||
|
||||
originalTags := originalIndex.RootIfd.DumpTags()
|
||||
|
||||
|
||||
// Encode back to binary.
|
||||
|
||||
ibe := NewIfdByteEncoder()
|
||||
@ -1334,7 +1318,6 @@ func Test_IfdBuilder_CreateIfdBuilderFromExistingChain_RealData(t *testing.T) {
|
||||
updatedExif, err := ibe.EncodeToExif(rootIb)
|
||||
log.PanicIf(err)
|
||||
|
||||
|
||||
// Parse again.
|
||||
|
||||
_, recoveredIndex, err := e.Collect(updatedExif)
|
||||
@ -1342,31 +1325,28 @@ func Test_IfdBuilder_CreateIfdBuilderFromExistingChain_RealData(t *testing.T) {
|
||||
|
||||
recoveredTags := recoveredIndex.RootIfd.DumpTags()
|
||||
|
||||
|
||||
recoveredThumbnailData, err := recoveredIndex.RootIfd.NextIfd.Thumbnail()
|
||||
log.PanicIf(err)
|
||||
|
||||
|
||||
// Check the thumbnail.
|
||||
|
||||
if bytes.Compare(recoveredThumbnailData, originalThumbnailData) != 0 {
|
||||
t.Fatalf("recovered thumbnail does not match original")
|
||||
}
|
||||
|
||||
|
||||
// Validate that all of the same IFDs were presented.
|
||||
|
||||
originalIfdTags := make([][2]interface{}, 0)
|
||||
for _, ite := range originalTags {
|
||||
if ite.ChildIfdName != "" {
|
||||
originalIfdTags = append(originalIfdTags, [2]interface{} { ite.Ii, ite.TagId })
|
||||
originalIfdTags = append(originalIfdTags, [2]interface{}{ite.Ii, ite.TagId})
|
||||
}
|
||||
}
|
||||
|
||||
recoveredIfdTags := make([][2]interface{}, 0)
|
||||
for _, ite := range recoveredTags {
|
||||
if ite.ChildIfdName != "" {
|
||||
recoveredIfdTags = append(recoveredIfdTags, [2]interface{} { ite.Ii, ite.TagId })
|
||||
recoveredIfdTags = append(recoveredIfdTags, [2]interface{}{ite.Ii, ite.TagId})
|
||||
}
|
||||
}
|
||||
|
||||
@ -1388,7 +1368,6 @@ func Test_IfdBuilder_CreateIfdBuilderFromExistingChain_RealData(t *testing.T) {
|
||||
t.Fatalf("Recovered IFD tags are not correct.")
|
||||
}
|
||||
|
||||
|
||||
// Validate that all of the tags owned by the IFDs were presented. Note
|
||||
// that the thumbnail tags are not kept but only produced on the fly, which
|
||||
// is why we check it above.
|
||||
@ -1412,7 +1391,7 @@ func Test_IfdBuilder_CreateIfdBuilderFromExistingChain_RealData(t *testing.T) {
|
||||
t.Fatalf("Tag-type not as expected: %d != %d ITE=%s", recoveredIte.TagType, originalIte.TagType, recoveredIte)
|
||||
}
|
||||
|
||||
// TODO(dustin): We're always accessing the addressable-data using the root-IFD. It shouldn't matter, but we'd rather access it from our specific IFD.
|
||||
// TODO(dustin): We're always accessing the addressable-data using the root-IFD. It shouldn't matter, but we'd rather access it from our specific IFD.
|
||||
originalValueBytes, err := originalIte.ValueBytes(originalIndex.RootIfd.addressableData, originalIndex.RootIfd.ByteOrder)
|
||||
log.PanicIf(err)
|
||||
|
||||
@ -1430,7 +1409,6 @@ func Test_IfdBuilder_CreateIfdBuilderFromExistingChain_RealData_WithUpdate(t *te
|
||||
|
||||
e := NewExif()
|
||||
|
||||
|
||||
rawExif, err := e.SearchAndExtractExif(filepath)
|
||||
log.PanicIf(err)
|
||||
|
||||
@ -1444,7 +1422,6 @@ func Test_IfdBuilder_CreateIfdBuilderFromExistingChain_RealData_WithUpdate(t *te
|
||||
|
||||
originalTags := originalIndex.RootIfd.DumpTags()
|
||||
|
||||
|
||||
// Encode back to binary.
|
||||
|
||||
ibe := NewIfdByteEncoder()
|
||||
@ -1452,7 +1429,6 @@ func Test_IfdBuilder_CreateIfdBuilderFromExistingChain_RealData_WithUpdate(t *te
|
||||
itevr := NewIfdTagEntryValueResolver(rawExif, originalIndex.RootIfd.ByteOrder)
|
||||
rootIb := NewIfdBuilderFromExistingChain(originalIndex.RootIfd, itevr)
|
||||
|
||||
|
||||
// Update a tag,.
|
||||
|
||||
exifBt, err := rootIb.FindTagWithName("ExifTag")
|
||||
@ -1469,13 +1445,11 @@ func Test_IfdBuilder_CreateIfdBuilderFromExistingChain_RealData_WithUpdate(t *te
|
||||
err = ucBt.SetValue(rootIb.byteOrder, uc)
|
||||
log.PanicIf(err)
|
||||
|
||||
|
||||
// Encode.
|
||||
|
||||
updatedExif, err := ibe.EncodeToExif(rootIb)
|
||||
log.PanicIf(err)
|
||||
|
||||
|
||||
// Parse again.
|
||||
|
||||
_, recoveredIndex, err := e.Collect(updatedExif)
|
||||
@ -1483,31 +1457,28 @@ func Test_IfdBuilder_CreateIfdBuilderFromExistingChain_RealData_WithUpdate(t *te
|
||||
|
||||
recoveredTags := recoveredIndex.RootIfd.DumpTags()
|
||||
|
||||
|
||||
recoveredThumbnailData, err := recoveredIndex.RootIfd.NextIfd.Thumbnail()
|
||||
log.PanicIf(err)
|
||||
|
||||
|
||||
// Check the thumbnail.
|
||||
|
||||
if bytes.Compare(recoveredThumbnailData, originalThumbnailData) != 0 {
|
||||
t.Fatalf("recovered thumbnail does not match original")
|
||||
}
|
||||
|
||||
|
||||
// Validate that all of the same IFDs were presented.
|
||||
|
||||
originalIfdTags := make([][2]interface{}, 0)
|
||||
for _, ite := range originalTags {
|
||||
if ite.ChildIfdName != "" {
|
||||
originalIfdTags = append(originalIfdTags, [2]interface{} { ite.Ii, ite.TagId })
|
||||
originalIfdTags = append(originalIfdTags, [2]interface{}{ite.Ii, ite.TagId})
|
||||
}
|
||||
}
|
||||
|
||||
recoveredIfdTags := make([][2]interface{}, 0)
|
||||
for _, ite := range recoveredTags {
|
||||
if ite.ChildIfdName != "" {
|
||||
recoveredIfdTags = append(recoveredIfdTags, [2]interface{} { ite.Ii, ite.TagId })
|
||||
recoveredIfdTags = append(recoveredIfdTags, [2]interface{}{ite.Ii, ite.TagId})
|
||||
}
|
||||
}
|
||||
|
||||
@ -1529,7 +1500,6 @@ func Test_IfdBuilder_CreateIfdBuilderFromExistingChain_RealData_WithUpdate(t *te
|
||||
t.Fatalf("Recovered IFD tags are not correct.")
|
||||
}
|
||||
|
||||
|
||||
// Validate that all of the tags owned by the IFDs were presented. Note
|
||||
// that the thumbnail tags are not kept but only produced on the fly, which
|
||||
// is why we check it above.
|
||||
@ -1562,7 +1532,7 @@ func Test_IfdBuilder_CreateIfdBuilderFromExistingChain_RealData_WithUpdate(t *te
|
||||
if recoveredIte.TagId == 0x9286 {
|
||||
expectedValueBytes := make([]byte, 0)
|
||||
|
||||
expectedValueBytes = append(expectedValueBytes, []byte{ 'A', 'S', 'C', 'I', 'I', 0, 0, 0 }...)
|
||||
expectedValueBytes = append(expectedValueBytes, []byte{'A', 'S', 'C', 'I', 'I', 0, 0, 0}...)
|
||||
expectedValueBytes = append(expectedValueBytes, []byte("TEST COMMENT")...)
|
||||
|
||||
if bytes.Compare(recoveredValueBytes, expectedValueBytes) != 0 {
|
||||
@ -1574,7 +1544,7 @@ func Test_IfdBuilder_CreateIfdBuilderFromExistingChain_RealData_WithUpdate(t *te
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleReadThumbnail() {
|
||||
func ExampleIfd_Thumbnail() {
|
||||
filepath := path.Join(assetsPath, "NDM_8901.jpg")
|
||||
|
||||
e := NewExif()
|
||||
@ -1592,7 +1562,7 @@ func ExampleReadThumbnail() {
|
||||
// Output:
|
||||
}
|
||||
|
||||
func ExampleUpdateUnknownTag() {
|
||||
func ExampleBuilderTag_SetValue() {
|
||||
filepath := path.Join(assetsPath, "NDM_8901.jpg")
|
||||
|
||||
e := NewExif()
|
||||
@ -1603,13 +1573,11 @@ func ExampleUpdateUnknownTag() {
|
||||
_, index, err := e.Collect(rawExif)
|
||||
log.PanicIf(err)
|
||||
|
||||
|
||||
// Create builder.
|
||||
|
||||
itevr := NewIfdTagEntryValueResolver(rawExif, index.RootIfd.ByteOrder)
|
||||
rootIb := NewIfdBuilderFromExistingChain(index.RootIfd, itevr)
|
||||
|
||||
|
||||
// Find tag to update.
|
||||
|
||||
exifBt, err := rootIb.FindTagWithName("ExifTag")
|
||||
@ -1618,10 +1586,10 @@ func ExampleUpdateUnknownTag() {
|
||||
ucBt, err := exifBt.value.Ib().FindTagWithName("UserComment")
|
||||
log.PanicIf(err)
|
||||
|
||||
|
||||
// Update the value. Since this is an "undefined"-type tag, we have to use
|
||||
// its type-specific struct.
|
||||
|
||||
// TODO(dustin): !! Add an example for setting a non-unknown value, too.
|
||||
uc := TagUnknownType_9298_UserComment{
|
||||
EncodingType: TagUnknownType_9298_UserComment_Encoding_ASCII,
|
||||
EncodingBytes: []byte("TEST COMMENT"),
|
||||
@ -1630,7 +1598,6 @@ func ExampleUpdateUnknownTag() {
|
||||
err = ucBt.SetValue(rootIb.byteOrder, uc)
|
||||
log.PanicIf(err)
|
||||
|
||||
|
||||
// Encode.
|
||||
|
||||
ibe := NewIfdByteEncoder()
|
||||
@ -1671,41 +1638,41 @@ func Test_IfdBuilder_CreateIfdBuilderWithExistingIfd(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNewStandardBuilderTagFromConfig_OneUnit(t *testing.T) {
|
||||
bt := NewStandardBuilderTagFromConfig(ExifIi, uint16(0x8833), TestDefaultByteOrder, []uint32 { uint32(0x1234) })
|
||||
bt := NewStandardBuilderTagFromConfig(ExifIi, uint16(0x8833), TestDefaultByteOrder, []uint32{uint32(0x1234)})
|
||||
|
||||
if bt.ii != ExifIi {
|
||||
t.Fatalf("II in builderTag not correct")
|
||||
t.Fatalf("II in BuilderTag not correct")
|
||||
} else if bt.tagId != 0x8833 {
|
||||
t.Fatalf("tag-ID not correct")
|
||||
} else if bytes.Compare(bt.value.Bytes(), []byte { 0x0, 0x0, 0x12, 0x34, }) != 0 {
|
||||
} else if bytes.Compare(bt.value.Bytes(), []byte{0x0, 0x0, 0x12, 0x34}) != 0 {
|
||||
t.Fatalf("value not correct")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewStandardBuilderTagFromConfig_TwoUnits(t *testing.T) {
|
||||
bt := NewStandardBuilderTagFromConfig(ExifIi, uint16(0x8833), TestDefaultByteOrder, []uint32 { uint32(0x1234), uint32(0x5678) })
|
||||
bt := NewStandardBuilderTagFromConfig(ExifIi, uint16(0x8833), TestDefaultByteOrder, []uint32{uint32(0x1234), uint32(0x5678)})
|
||||
|
||||
if bt.ii != ExifIi {
|
||||
t.Fatalf("II in builderTag not correct")
|
||||
t.Fatalf("II in BuilderTag not correct")
|
||||
} else if bt.tagId != 0x8833 {
|
||||
t.Fatalf("tag-ID not correct")
|
||||
} else if bytes.Compare(bt.value.Bytes(), []byte {
|
||||
} else if bytes.Compare(bt.value.Bytes(), []byte{
|
||||
0x0, 0x0, 0x12, 0x34,
|
||||
0x0, 0x0, 0x56, 0x78, }) != 0 {
|
||||
0x0, 0x0, 0x56, 0x78}) != 0 {
|
||||
t.Fatalf("value not correct")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewStandardBuilderTagFromConfigWithName(t *testing.T) {
|
||||
bt := NewStandardBuilderTagFromConfigWithName(ExifIi, "ISOSpeed", TestDefaultByteOrder, []uint32 { uint32(0x1234), uint32(0x5678) })
|
||||
bt := NewStandardBuilderTagFromConfigWithName(ExifIi, "ISOSpeed", TestDefaultByteOrder, []uint32{uint32(0x1234), uint32(0x5678)})
|
||||
|
||||
if bt.ii != ExifIi {
|
||||
t.Fatalf("II in builderTag not correct")
|
||||
t.Fatalf("II in BuilderTag not correct")
|
||||
} else if bt.tagId != 0x8833 {
|
||||
t.Fatalf("tag-ID not correct")
|
||||
} else if bytes.Compare(bt.value.Bytes(), []byte {
|
||||
} else if bytes.Compare(bt.value.Bytes(), []byte{
|
||||
0x0, 0x0, 0x12, 0x34,
|
||||
0x0, 0x0, 0x56, 0x78, }) != 0 {
|
||||
0x0, 0x0, 0x56, 0x78}) != 0 {
|
||||
t.Fatalf("value not correct")
|
||||
}
|
||||
}
|
||||
@ -1734,4 +1701,3 @@ func TestAddFromConfigWithName(t *testing.T) {
|
||||
t.Fatalf("Value not correct: (%d) [%s]", len(s), s)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user