mirror of https://github.com/dsoprea/go-exif.git
Adjusted some string representations. Fixed some hex-encodings.
- unknown: We no longer truncate UNDEFINED UserComment values. - This is one less thing that will be different between what we read and how we encode.pull/3/head
parent
3c1c668a9f
commit
080ff7d07d
|
@ -29,6 +29,24 @@ type IfdBuilderTagValue struct {
|
|||
ib *IfdBuilder
|
||||
}
|
||||
|
||||
func (ibtv IfdBuilderTagValue) String() string {
|
||||
if ibtv.IsBytes() == true {
|
||||
var valuePhrase string
|
||||
if len(ibtv.valueBytes) <= 8 {
|
||||
valuePhrase = fmt.Sprintf("%v", ibtv.valueBytes)
|
||||
} else {
|
||||
valuePhrase = fmt.Sprintf("%v...", ibtv.valueBytes[:8])
|
||||
}
|
||||
|
||||
return fmt.Sprintf("IfdBuilderTagValue<BYTES=%v LEN=(%d)>", valuePhrase, len(ibtv.valueBytes))
|
||||
} else if ibtv.IsIb() == true {
|
||||
return fmt.Sprintf("IfdBuilderTagValue<IB=%s>", ibtv.ib)
|
||||
} else {
|
||||
log.Panicf("IBTV state undefined")
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func NewIfdBuilderTagValueFromBytes(valueBytes []byte) *IfdBuilderTagValue {
|
||||
return &IfdBuilderTagValue{
|
||||
valueBytes: valueBytes,
|
||||
|
@ -116,21 +134,7 @@ func (bt builderTag) Value() (value *IfdBuilderTagValue) {
|
|||
}
|
||||
|
||||
func (bt builderTag) String() string {
|
||||
valuePhrase := ""
|
||||
|
||||
if bt.value.IsBytes() == true {
|
||||
valueBytes := bt.value.Bytes()
|
||||
|
||||
if len(valueBytes) <= 8 {
|
||||
valuePhrase = fmt.Sprintf("%v", valueBytes)
|
||||
} else {
|
||||
valuePhrase = fmt.Sprintf("%v...", valueBytes[:8])
|
||||
}
|
||||
} else {
|
||||
valuePhrase = fmt.Sprintf("%v", bt.value.Ib())
|
||||
}
|
||||
|
||||
return fmt.Sprintf("BuilderTag<TAG-ID=(0x%02x) IFD=[%s] VALUE=[%v]>", bt.tagId, bt.ii, valuePhrase)
|
||||
return fmt.Sprintf("BuilderTag<TAG-ID=(0x%04x) IFD=[%s] VALUE=[%s]>", bt.tagId, bt.ii, bt.value)
|
||||
}
|
||||
|
||||
// NewStandardBuilderTagFromConfig constructs a `builderTag` instance. The type
|
||||
|
@ -330,7 +334,7 @@ func (ib *IfdBuilder) String() string {
|
|||
nextIfdPhrase = ib.nextIb.ii.IfdName
|
||||
}
|
||||
|
||||
return fmt.Sprintf("IfdBuilder<PARENT-IFD=[%s] IFD=[%s] TAG-ID=(0x%02x) COUNT=(%d) OFF=(0x%04x) NEXT-IFD=(0x%04x)>", ib.ii.ParentIfdName, ib.ii.IfdName, ib.ifdTagId, len(ib.tags), ib.existingOffset, nextIfdPhrase)
|
||||
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) {
|
||||
|
@ -440,7 +444,7 @@ func (ib *IfdBuilder) printTagTree(levels int) {
|
|||
|
||||
if isChildIb == true {
|
||||
if tag.value.IsIb() == false {
|
||||
log.Panicf("tag-ID (0x%02x) is an IFD but the tag value is not an IB instance: %v", tag.tagId, tag)
|
||||
log.Panicf("tag-ID (0x%04x) is an IFD but the tag value is not an IB instance: %v", tag.tagId, tag)
|
||||
}
|
||||
|
||||
fmt.Printf("\n")
|
||||
|
@ -479,7 +483,7 @@ func (ib *IfdBuilder) printIfdTree(levels int) {
|
|||
|
||||
if isChildIb == true {
|
||||
if tag.value.IsIb() == false {
|
||||
log.Panicf("tag-ID (0x%02x) is an IFD but the tag value is not an IB instance: %v", tag.tagId, tag)
|
||||
log.Panicf("tag-ID (0x%04x) is an IFD but the tag value is not an IB instance: %v", tag.tagId, tag)
|
||||
}
|
||||
|
||||
childIb := tag.value.Ib()
|
||||
|
@ -509,7 +513,7 @@ func (ib *IfdBuilder) dumpToStrings(thisIb *IfdBuilder, prefix string, lines []s
|
|||
childIfdName = tag.value.Ib().ii.IfdName
|
||||
}
|
||||
|
||||
line := fmt.Sprintf("<PARENTS=[%s] IFD-NAME=[%s]> IFD-TAG-ID=(0x%02x) CHILD-IFD=[%s] INDEX=(%d) TAG=[0x%02x]", prefix, thisIb.ii.IfdName, thisIb.ifdTagId, childIfdName, i, tag.tagId)
|
||||
line := fmt.Sprintf("<PARENTS=[%s] IFD-NAME=[%s]> IFD-TAG-ID=(0x%04x) CHILD-IFD=[%s] INDEX=(%d) TAG=[0x%04x]", prefix, thisIb.ii.IfdName, thisIb.ifdTagId, childIfdName, i, tag.tagId)
|
||||
linesOutput = append(linesOutput, line)
|
||||
|
||||
if tag.value.IsIb() == true {
|
||||
|
@ -883,10 +887,10 @@ func (ib *IfdBuilder) AddTagsFromExisting(ifd *Ifd, itevr *IfdTagEntryValueResol
|
|||
if childIfd == nil {
|
||||
childTagIds := make([]string, len(ifd.Children))
|
||||
for j, childIfd := range ifd.Children {
|
||||
childTagIds[j] = fmt.Sprintf("0x%02x (parent tag-position %d)", childIfd.TagId, childIfd.ParentTagIndex)
|
||||
childTagIds[j] = fmt.Sprintf("0x%04x (parent tag-position %d)", childIfd.TagId, childIfd.ParentTagIndex)
|
||||
}
|
||||
|
||||
log.Panicf("could not find child IFD for child ITE: II=[%s] TAG-ID=(0x%02x) CURRENT-TAG-POSITION=(%d) CHILDREN=%v", ite.Ii, ite.TagId, i, childTagIds)
|
||||
log.Panicf("could not find child IFD for child ITE: II=[%s] TAG-ID=(0x%04x) CURRENT-TAG-POSITION=(%d) CHILDREN=%v", ite.Ii, ite.TagId, i, childTagIds)
|
||||
}
|
||||
|
||||
childIb := NewIfdBuilderFromExistingChain(childIfd, itevr)
|
||||
|
|
|
@ -239,7 +239,7 @@ func (ibe *IfdByteEncoder) encodeTagToBytes(ib *IfdBuilder, bt *builderTag, bw *
|
|||
remainder := uint32(len_) % typeSize
|
||||
|
||||
if remainder > 0 {
|
||||
log.Panicf("tag (0x%02x) 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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ type IfdTagEntry struct {
|
|||
}
|
||||
|
||||
func (ite IfdTagEntry) String() string {
|
||||
return fmt.Sprintf("IfdTagEntry<TAG-IFD=[%s] TAG-ID=(0x%02x) TAG-TYPE=[%s] UNIT-COUNT=(%d)>", ite.ChildIfdName, ite.TagId, TypeNames[ite.TagType], ite.UnitCount)
|
||||
return fmt.Sprintf("IfdTagEntry<TAG-IFD=[%s] TAG-ID=(0x%04x) TAG-TYPE=[%s] UNIT-COUNT=(%d)>", ite.ChildIfdName, ite.TagId, TypeNames[ite.TagType], ite.UnitCount)
|
||||
}
|
||||
|
||||
// ValueString renders a string from whatever the value in this tag is.
|
||||
|
@ -98,7 +98,7 @@ func (ite IfdTagEntry) ValueBytes(addressableData []byte, byteOrder binary.ByteO
|
|||
return valueBytes, nil
|
||||
default:
|
||||
// TODO(dustin): !! Finish translating the rest of the types (make reusable and replace into other similar implementations?)
|
||||
log.Panicf("can not produce bytes for unknown-type tag (0x%02x): [%s]", ite.TagId, reflect.TypeOf(value))
|
||||
log.Panicf("can not produce bytes for unknown-type tag (0x%04x): [%s]", ite.TagId, reflect.TypeOf(value))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -93,7 +93,15 @@ type TagUnknownType_9298_UserComment struct {
|
|||
}
|
||||
|
||||
func (uc TagUnknownType_9298_UserComment) String() string {
|
||||
return fmt.Sprintf("UserComment<SIZE=(%d) ENCODING=[%s] V=%v>", len(uc.EncodingBytes), TagUnknownType_9298_UserComment_Encoding_Names[uc.EncodingType], uc.EncodingBytes)
|
||||
var valuePhrase string
|
||||
|
||||
if len(uc.EncodingBytes) <= 8 {
|
||||
valuePhrase = fmt.Sprintf("%v", uc.EncodingBytes)
|
||||
} else {
|
||||
valuePhrase = fmt.Sprintf("%v...", uc.EncodingBytes[:8])
|
||||
}
|
||||
|
||||
return fmt.Sprintf("UserComment<SIZE=(%d) ENCODING=[%s] V=%v LEN=(%d)>", len(uc.EncodingBytes), TagUnknownType_9298_UserComment_Encoding_Names[uc.EncodingType], valuePhrase, len(uc.EncodingBytes))
|
||||
}
|
||||
|
||||
func (uc TagUnknownType_9298_UserComment) ValueBytes() (value []byte, err error) {
|
||||
|
@ -103,9 +111,8 @@ func (uc TagUnknownType_9298_UserComment) ValueBytes() (value []byte, err error)
|
|||
}
|
||||
|
||||
value = make([]byte, len(uc.EncodingBytes) + 8)
|
||||
copy(value[:8], encodingTypeBytes)
|
||||
|
||||
// TODO(dustin): !! With undefined-encoded comments, we always make this empty. However, it comes in with a set of zero bytes. Is there a problem if we send it out with just the encoding bytes?
|
||||
copy(value[:8], encodingTypeBytes)
|
||||
copy(value[8:], uc.EncodingBytes)
|
||||
|
||||
return value, nil
|
||||
|
@ -245,20 +252,12 @@ func UndefinedValue(ii IfdIdentity, tagId uint16, valueContext ValueContext, byt
|
|||
encoding := valueBytes[:8]
|
||||
for encodingIndex, encodingBytes := range TagUnknownType_9298_UserComment_Encodings {
|
||||
if bytes.Compare(encoding, encodingBytes) == 0 {
|
||||
// If unknown, return the default rather than what we have
|
||||
// because there will be a big list of NULs (which aren't
|
||||
// functional) and this won't equal the default instance
|
||||
// (above).
|
||||
if encodingIndex == TagUnknownType_9298_UserComment_Encoding_UNDEFINED {
|
||||
return unknownUc, nil
|
||||
} else {
|
||||
uc := TagUnknownType_9298_UserComment{
|
||||
EncodingType: encodingIndex,
|
||||
EncodingBytes: valueBytes[8:],
|
||||
}
|
||||
|
||||
return uc, nil
|
||||
uc := TagUnknownType_9298_UserComment{
|
||||
EncodingType: encodingIndex,
|
||||
EncodingBytes: valueBytes[8:],
|
||||
}
|
||||
|
||||
return uc, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue