mirror of https://github.com/dsoprea/go-exif.git
value_context.go: No longer support override for unit-count
It's never set to anything different.pull/28/head
parent
71b242c269
commit
79b37fc0e1
|
@ -233,6 +233,8 @@ func UndefinedValue(ifdPath string, tagId uint16, valueContext interface{}, byte
|
|||
}
|
||||
}()
|
||||
|
||||
// TODO(dustin): Stop exporting this. Use `(*ValueContext).Undefined()`.
|
||||
|
||||
var valueContextPtr *ValueContext
|
||||
|
||||
if vc, ok := valueContext.(*ValueContext); ok == true {
|
||||
|
@ -252,7 +254,7 @@ func UndefinedValue(ifdPath string, tagId uint16, valueContext interface{}, byte
|
|||
if tagId == 0x9000 {
|
||||
// ExifVersion
|
||||
|
||||
valueContextPtr.SetUnknownValueParameters(TypeAsciiNoNul, valueContextPtr.UnitCount())
|
||||
valueContextPtr.SetUnknownValueType(TypeAsciiNoNul)
|
||||
|
||||
valueString, err := valueContextPtr.ReadAsciiNoNul()
|
||||
log.PanicIf(err)
|
||||
|
@ -261,7 +263,7 @@ func UndefinedValue(ifdPath string, tagId uint16, valueContext interface{}, byte
|
|||
} else if tagId == 0xa000 {
|
||||
// FlashpixVersion
|
||||
|
||||
valueContextPtr.SetUnknownValueParameters(TypeAsciiNoNul, valueContextPtr.UnitCount())
|
||||
valueContextPtr.SetUnknownValueType(TypeAsciiNoNul)
|
||||
|
||||
valueString, err := valueContextPtr.ReadAsciiNoNul()
|
||||
log.PanicIf(err)
|
||||
|
@ -270,7 +272,7 @@ func UndefinedValue(ifdPath string, tagId uint16, valueContext interface{}, byte
|
|||
} else if tagId == 0x9286 {
|
||||
// UserComment
|
||||
|
||||
valueContextPtr.SetUnknownValueParameters(TypeByte, valueContextPtr.UnitCount())
|
||||
valueContextPtr.SetUnknownValueType(TypeByte)
|
||||
|
||||
valueBytes, err := valueContextPtr.ReadBytes()
|
||||
log.PanicIf(err)
|
||||
|
@ -299,7 +301,7 @@ func UndefinedValue(ifdPath string, tagId uint16, valueContext interface{}, byte
|
|||
// TODO(dustin): !! This is the Wild Wild West. This very well might be a child IFD, but any and all OEM's define their own formats. If we're going to be writing changes and this is complete EXIF (which may not have the first eight bytes), it might be fine. However, if these are just IFDs they'll be relative to the main EXIF, this will invalidate the MakerNote data for IFDs and any other implementations that use offsets unless we can interpret them all. It be best to return to this later and just exclude this from being written for now, though means a loss of a wealth of image metadata.
|
||||
// -> We can also just blindly try to interpret as an IFD and just validate that it's looks good (maybe it will even have a 'next ifd' pointer that we can validate is 0x0).
|
||||
|
||||
valueContextPtr.SetUnknownValueParameters(TypeByte, valueContextPtr.UnitCount())
|
||||
valueContextPtr.SetUnknownValueType(TypeByte)
|
||||
|
||||
valueBytes, err := valueContextPtr.ReadBytes()
|
||||
log.PanicIf(err)
|
||||
|
@ -326,7 +328,7 @@ func UndefinedValue(ifdPath string, tagId uint16, valueContext interface{}, byte
|
|||
} else if tagId == 0x9101 {
|
||||
// ComponentsConfiguration
|
||||
|
||||
valueContextPtr.SetUnknownValueParameters(TypeByte, valueContextPtr.UnitCount())
|
||||
valueContextPtr.SetUnknownValueType(TypeByte)
|
||||
|
||||
valueBytes, err := valueContextPtr.ReadBytes()
|
||||
log.PanicIf(err)
|
||||
|
@ -353,7 +355,7 @@ func UndefinedValue(ifdPath string, tagId uint16, valueContext interface{}, byte
|
|||
if tagId == 0x001c {
|
||||
// GPSAreaInformation
|
||||
|
||||
valueContextPtr.SetUnknownValueParameters(TypeAsciiNoNul, valueContextPtr.UnitCount())
|
||||
valueContextPtr.SetUnknownValueType(TypeAsciiNoNul)
|
||||
|
||||
valueString, err := valueContextPtr.ReadAsciiNoNul()
|
||||
log.PanicIf(err)
|
||||
|
@ -362,7 +364,7 @@ func UndefinedValue(ifdPath string, tagId uint16, valueContext interface{}, byte
|
|||
} else if tagId == 0x001b {
|
||||
// GPSProcessingMethod
|
||||
|
||||
valueContextPtr.SetUnknownValueParameters(TypeAsciiNoNul, valueContextPtr.UnitCount())
|
||||
valueContextPtr.SetUnknownValueType(TypeAsciiNoNul)
|
||||
|
||||
valueString, err := valueContextPtr.ReadAsciiNoNul()
|
||||
log.PanicIf(err)
|
||||
|
@ -373,7 +375,7 @@ func UndefinedValue(ifdPath string, tagId uint16, valueContext interface{}, byte
|
|||
if tagId == 0x0002 {
|
||||
// InteropVersion
|
||||
|
||||
valueContextPtr.SetUnknownValueParameters(TypeAsciiNoNul, valueContextPtr.UnitCount())
|
||||
valueContextPtr.SetUnknownValueType(TypeAsciiNoNul)
|
||||
|
||||
valueString, err := valueContextPtr.ReadAsciiNoNul()
|
||||
log.PanicIf(err)
|
||||
|
@ -392,7 +394,7 @@ func UndefinedValue(ifdPath string, tagId uint16, valueContext interface{}, byte
|
|||
// Return encapsulated data rather than an error so that we can at least
|
||||
// print/profile the opaque data.
|
||||
|
||||
valueContextPtr.SetUnknownValueParameters(TypeByte, valueContextPtr.UnitCount())
|
||||
valueContextPtr.SetUnknownValueType(TypeByte)
|
||||
|
||||
valueBytes, err := valueContextPtr.ReadBytes()
|
||||
log.PanicIf(err)
|
||||
|
|
|
@ -21,13 +21,9 @@ type ValueContext struct {
|
|||
tagType TagTypePrimitive
|
||||
byteOrder binary.ByteOrder
|
||||
|
||||
// undefinedValueTagType is the effective type to use if this is an "undefined"
|
||||
// value.
|
||||
undefinedValueTagType TagTypePrimitive
|
||||
|
||||
// undefinedValueUnitCount is the effective unit-count to use if this is an
|
||||
// undefinedValueTagType is the effective type to use if this is an
|
||||
// "undefined" value.
|
||||
undefinedValueUnitCount uint32
|
||||
undefinedValueTagType TagTypePrimitive
|
||||
|
||||
ifdPath string
|
||||
tagId uint16
|
||||
|
@ -60,9 +56,8 @@ func newValueContextFromTag(ite *IfdTagEntry, addressableData []byte, byteOrder
|
|||
byteOrder)
|
||||
}
|
||||
|
||||
func (vc *ValueContext) SetUnknownValueParameters(tagType TagTypePrimitive, unitCount uint32) {
|
||||
func (vc *ValueContext) SetUnknownValueType(tagType TagTypePrimitive) {
|
||||
vc.undefinedValueTagType = tagType
|
||||
vc.undefinedValueUnitCount = unitCount
|
||||
}
|
||||
|
||||
func (vc *ValueContext) UnitCount() uint32 {
|
||||
|
@ -85,25 +80,23 @@ func (vc *ValueContext) AddressableData() []byte {
|
|||
// be precalculated since the size is not defined for all types (namely the
|
||||
// "undefined" types).
|
||||
func (vc *ValueContext) isEmbedded() bool {
|
||||
tagType, unitCount := vc.effectiveValueParameters()
|
||||
tagType := vc.effectiveValueType()
|
||||
|
||||
return (tagType.Size() * int(unitCount)) <= 4
|
||||
return (tagType.Size() * int(vc.unitCount)) <= 4
|
||||
}
|
||||
|
||||
func (vc *ValueContext) effectiveValueParameters() (tagType TagTypePrimitive, unitCount uint32) {
|
||||
func (vc *ValueContext) effectiveValueType() (tagType TagTypePrimitive) {
|
||||
if vc.tagType == TypeUndefined {
|
||||
tagType = vc.undefinedValueTagType
|
||||
unitCount = vc.undefinedValueUnitCount
|
||||
|
||||
if tagType == 0 {
|
||||
log.Panicf("undefined-value type not set")
|
||||
}
|
||||
} else {
|
||||
tagType = vc.tagType
|
||||
unitCount = vc.unitCount
|
||||
}
|
||||
|
||||
return tagType, unitCount
|
||||
return tagType
|
||||
}
|
||||
|
||||
func (vc *ValueContext) readRawEncoded() (rawBytes []byte, err error) {
|
||||
|
@ -113,15 +106,15 @@ func (vc *ValueContext) readRawEncoded() (rawBytes []byte, err error) {
|
|||
}
|
||||
}()
|
||||
|
||||
tagType, unitCount := vc.effectiveValueParameters()
|
||||
tagType := vc.effectiveValueType()
|
||||
|
||||
unitSizeRaw := uint32(tagType.Size())
|
||||
|
||||
if vc.isEmbedded() == true {
|
||||
byteLength := unitSizeRaw * unitCount
|
||||
byteLength := unitSizeRaw * vc.unitCount
|
||||
return vc.rawValueOffset[:byteLength], nil
|
||||
} else {
|
||||
return vc.addressableData[vc.valueOffset : vc.valueOffset+unitCount*unitSizeRaw], nil
|
||||
return vc.addressableData[vc.valueOffset : vc.valueOffset+vc.unitCount*unitSizeRaw], nil
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,7 +126,7 @@ func (vc *ValueContext) readRawEncoded() (rawBytes []byte, err error) {
|
|||
//
|
||||
// Since this method lacks the information to process undefined-type tags (e.g.
|
||||
// byte-order, tag-ID, IFD type), it will return an error if attempted. See
|
||||
// `UndefinedValue()`.
|
||||
// `Undefined()`.
|
||||
func (vc *ValueContext) Format() (value string, err error) {
|
||||
defer func() {
|
||||
if state := recover(); state != nil {
|
||||
|
@ -301,7 +294,7 @@ func (vc *ValueContext) ReadSignedRationals() (value []SignedRational, err error
|
|||
//
|
||||
// Since this method lacks the information to process unknown-type tags (e.g.
|
||||
// byte-order, tag-ID, IFD type), it will return an error if attempted. See
|
||||
// `UndefinedValue()`.
|
||||
// `Undefined()`.
|
||||
func (vc *ValueContext) Values() (value interface{}, err error) {
|
||||
defer func() {
|
||||
if state := recover(); state != nil {
|
||||
|
|
Loading…
Reference in New Issue