mirror of https://github.com/dsoprea/go-exif.git
parent
a909226514
commit
67a5e1f548
|
@ -1,32 +1,3 @@
|
|||
#!/usr/bin/env python3.4
|
||||
|
||||
import sys
|
||||
|
||||
import ruamel.yaml
|
||||
|
||||
|
||||
class HexInt(int):
|
||||
pass
|
||||
|
||||
def representer(dumper, data):
|
||||
return \
|
||||
ruamel.yaml.ScalarNode(
|
||||
'tag:yaml.org,2002:int',
|
||||
'0x{:04x}'.format(data))
|
||||
|
||||
ruamel.yaml.add_representer(HexInt, representer)
|
||||
|
||||
data = {
|
||||
'item1': {
|
||||
'string_value': 'some_string',
|
||||
'hex_value': HexInt(641),
|
||||
}
|
||||
}
|
||||
|
||||
ruamel.yaml.dump(data, sys.stdout, default_flow_style=False)
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
#!/usr/bin/env python2.7
|
||||
|
||||
"""
|
||||
|
@ -55,19 +26,6 @@ def representer(dumper, data):
|
|||
|
||||
ruamel.yaml.add_representer(HexInt, representer)
|
||||
|
||||
data = {
|
||||
'item1': {
|
||||
'string_value': 'some_string',
|
||||
'hex_value': HexInt(641),
|
||||
}
|
||||
}
|
||||
|
||||
ruamel.yaml.dump(data, sys.stdout, default_flow_style=False)
|
||||
|
||||
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
def _write(tags):
|
||||
writeable = {}
|
||||
|
||||
|
@ -77,12 +35,23 @@ def _write(tags):
|
|||
item = {
|
||||
'id': HexInt(tag['id_dec']),
|
||||
'name': tag['fq_key'][pivot + 1:],
|
||||
'type_name': tag['type'].upper(),
|
||||
}
|
||||
|
||||
ifdName = tag['ifd']
|
||||
if ifdName == 'Image':
|
||||
ifdName = 'IFD'
|
||||
if ifdName == 'Photo':
|
||||
ifdName = 'Exif'
|
||||
|
||||
# UserComment. Has invalid type "COMMENT".
|
||||
if item['id'] == 0x9286 and ifdName == 'Exif':
|
||||
item['type_name'] = 'UNDEFINED'
|
||||
|
||||
try:
|
||||
writeable[tag['ifd']].append(item)
|
||||
writeable[ifdName].append(item)
|
||||
except KeyError:
|
||||
writeable[tag['ifd']] = [item]
|
||||
writeable[ifdName] = [item]
|
||||
|
||||
with open('tags.yaml', 'w') as f:
|
||||
# Otherwise, the next dictionaries will look like Python dictionaries,
|
||||
|
|
1280
assets/tags.yaml
1280
assets/tags.yaml
File diff suppressed because it is too large
Load Diff
15
tags.go
15
tags.go
|
@ -50,6 +50,7 @@ type encodedTag struct {
|
|||
// support unsigned.
|
||||
Id int `yaml:"id"`
|
||||
Name string `yaml:"name"`
|
||||
TypeName string `yaml:"type_name"`
|
||||
}
|
||||
|
||||
|
||||
|
@ -59,6 +60,7 @@ type IndexedTag struct {
|
|||
Id uint16
|
||||
Name string
|
||||
Ifd string
|
||||
Type uint16
|
||||
}
|
||||
|
||||
func (it IndexedTag) String() string {
|
||||
|
@ -116,11 +118,24 @@ func (ti *TagIndex) load() (err error) {
|
|||
for _, tagInfo := range tags {
|
||||
tagId := uint16(tagInfo.Id)
|
||||
tagName := tagInfo.Name
|
||||
tagTypeName := tagInfo.TypeName
|
||||
|
||||
// TODO(dustin): !! Non-standard types but present types. Ignore for right now.
|
||||
if tagTypeName == "SSHORT" || tagTypeName == "FLOAT" || tagTypeName == "DOUBLE" {
|
||||
continue
|
||||
}
|
||||
|
||||
tagTypeId, found := TypeNamesR[tagTypeName]
|
||||
if found == false {
|
||||
log.Panicf("type [%s] for [%s] not valid", tagTypeName, tagName)
|
||||
continue
|
||||
}
|
||||
|
||||
tag := &IndexedTag{
|
||||
Ifd: ifdName,
|
||||
Id: tagId,
|
||||
Name: tagName,
|
||||
Type: tagTypeId,
|
||||
}
|
||||
|
||||
family, found := tagsByIfd[ifdName]
|
||||
|
|
9
type.go
9
type.go
|
@ -31,7 +31,10 @@ var (
|
|||
|
||||
TypeAsciiNoNul: "_ASCII_NO_NUL",
|
||||
}
|
||||
|
||||
TypeNamesR = map[string]uint16 {}
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrCantDetermineTagValueSize is used when we're trying to determine a
|
||||
//size for a non-standard/undefined type.
|
||||
|
@ -61,3 +64,9 @@ type SignedRational struct {
|
|||
Numerator int32
|
||||
Denominator int32
|
||||
}
|
||||
|
||||
func init() {
|
||||
for typeId, typeName := range TypeNames {
|
||||
TypeNamesR[typeName] = typeId
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue