Skip to content

Commit

Permalink
Support SLong.
Browse files Browse the repository at this point in the history
  • Loading branch information
hMatoba committed Jan 23, 2016
1 parent 6c49eb3 commit 90e84c0
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 19 deletions.
5 changes: 5 additions & 0 deletions doc/changes.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

1.0.3
-----

- Support SLong type.

1.0.2
-----

Expand Down
2 changes: 1 addition & 1 deletion piexif/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
from ._exif import *


VERSION = '1.0.2'
VERSION = '1.0.3'
18 changes: 9 additions & 9 deletions piexif/_dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ def _pack_long(*args):
return struct.pack(">" + "L" * len(args), *args)


#def _pack_slong(*args):
# return struct.pack(">" + "l" * len(args), *args)
def _pack_slong(*args):
return struct.pack(">" + "l" * len(args), *args)


def _value_to_bytes(raw_value, value_type, offset):
Expand Down Expand Up @@ -194,13 +194,13 @@ def _value_to_bytes(raw_value, value_type, offset):
else:
value_str = struct.pack(">I", offset)
four_bytes_over = _pack_long(*raw_value)
# elif value_type == "SLong":
# length = len(raw_value)
# if length <= 1:
# value_str = pack_long(*raw_value)
# else:
# value_str = struct.pack(">I", offset)
# four_bytes_over = pack_slong(*raw_value)
elif value_type == "SLong":
length = len(raw_value)
if length <= 1:
value_str = _pack_slong(*raw_value)
else:
value_str = struct.pack(">I", offset)
four_bytes_over = _pack_slong(*raw_value)
elif value_type == "Ascii":
try:
new_value = raw_value.encode("latin1") + b"\x00"
Expand Down
6 changes: 5 additions & 1 deletion piexif/_exif.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@
50982: {'name': 'ProfileLookTableData', 'type': 'Float'},
51008: {'name': 'OpcodeList1', 'type': 'Undefined'},
51009: {'name': 'OpcodeList2', 'type': 'Undefined'},
51022: {'name': 'OpcodeList3', 'type': 'Undefined'}},
51022: {'name': 'OpcodeList3', 'type': 'Undefined'},
60606: {'name': 'ZZZTestSlong1', 'type': 'SLong'},
60607: {'name': 'ZZZTestSlong2', 'type': 'SLong'}},
'Exif': {33434: {'name': 'ExposureTime', 'type': 'Rational'},
33437: {'name': 'FNumber', 'type': 'Rational'},
34850: {'name': 'ExposureProgram', 'type': 'Short'},
Expand Down Expand Up @@ -488,6 +490,8 @@ class ImageIFD:
OpcodeList2 = 51009
OpcodeList3 = 51022
NoiseProfile = 51041
ZZZTestSlong1 = 60606
ZZZTestSlong2 = 60607


class ExifIFD:
Expand Down
16 changes: 8 additions & 8 deletions piexif/_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,14 @@ def convert_value(self, val):
data = self.tiftag[pointer: pointer+length]
else:
data = value[0:length]
# elif t == 9: # SLONG
# if length > 1:
# pointer = struct.unpack(self.endian_mark + "L", value)[0]
# data = struct.unpack(self.endian_mark + "l" * length,
# self.exif_str[pointer: pointer+length*4])
# else:
# data = struct.unpack(self.endian_mark + "l" * length,
# value)
elif t == 9: # SLONG
if length > 1:
pointer = struct.unpack(self.endian_mark + "L", value)[0]
data = struct.unpack(self.endian_mark + "l" * length,
self.tiftag[pointer: pointer+length*4])
else:
data = struct.unpack(self.endian_mark + "l" * length,
value)
elif t == 10: # SRATIONAL
pointer = struct.unpack(self.endian_mark + "L", value)[0]
if length > 1:
Expand Down
2 changes: 2 additions & 0 deletions tests/s_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
ImageIFD.BitsPerSample: (24, 24, 24), # short * 3
ImageIFD.XResolution: (4294967295, 1), # rational
ImageIFD.BlackLevelDeltaH: ((1, 1), (1, 1), (1, 1)), # srational
ImageIFD.ZZZTestSlong1: -11,
ImageIFD.ZZZTestSlong2: (-11, -11, -11, -11),
}


Expand Down

0 comments on commit 90e84c0

Please sign in to comment.