mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
Versioned interface for TiffTags
This commit is contained in:
parent
f3ab9b9f81
commit
4596df45c1
|
@ -55,7 +55,7 @@ import struct
|
|||
import sys
|
||||
import warnings
|
||||
|
||||
from .TiffTags import TAGS, TYPES, TagInfo
|
||||
from .TiffTags import TAGS_V2, TYPES, TagInfo
|
||||
|
||||
__version__ = "1.3.5"
|
||||
DEBUG = False # Needs to be merged with the new logging approach.
|
||||
|
@ -318,7 +318,7 @@ class ImageFileDirectory_v2(collections.MutableMapping):
|
|||
"""
|
||||
Returns the complete tag dictionary, with named tags where possible.
|
||||
"""
|
||||
return dict((TAGS.get(code, TagInfo()).name, value)
|
||||
return dict((TAGS_V2.get(code, TagInfo()).name, value)
|
||||
for code, value in self.items())
|
||||
|
||||
def __len__(self):
|
||||
|
@ -350,7 +350,7 @@ class ImageFileDirectory_v2(collections.MutableMapping):
|
|||
if bytes is str:
|
||||
basetypes += unicode,
|
||||
|
||||
info = TAGS.get(tag, TagInfo())
|
||||
info = TAGS_V2.get(tag, TagInfo())
|
||||
values = [value] if isinstance(value, basetypes) else value
|
||||
|
||||
if tag not in self.tagtype:
|
||||
|
@ -503,7 +503,7 @@ class ImageFileDirectory_v2(collections.MutableMapping):
|
|||
for i in range(self._unpack("H", self._ensure_read(fp,2))[0]):
|
||||
tag, typ, count, data = self._unpack("HHL4s", self._ensure_read(fp,12))
|
||||
if DEBUG:
|
||||
tagname = TAGS.get(tag, TagInfo()).name
|
||||
tagname = TAGS_V2.get(tag, TagInfo()).name
|
||||
typname = TYPES.get(typ, "unknown")
|
||||
print("tag: %s (%d) - type: %s (%d)" %
|
||||
(tagname, tag, typname, typ), end=" ")
|
||||
|
@ -571,7 +571,7 @@ class ImageFileDirectory_v2(collections.MutableMapping):
|
|||
values = value if isinstance(value, tuple) else (value,)
|
||||
data = self._write_dispatch[typ](self, *values)
|
||||
if DEBUG:
|
||||
tagname = TAGS.get(tag, TagInfo()).name
|
||||
tagname = TAGS_V2.get(tag, TagInfo()).name
|
||||
typname = TYPES.get(typ, "unknown")
|
||||
print("save: %s (%d) - type: %s (%d)" %
|
||||
(tagname, tag, typname, typ), end=" ")
|
||||
|
|
|
@ -19,6 +19,9 @@
|
|||
|
||||
from collections import namedtuple
|
||||
|
||||
# Legacy Tags structure
|
||||
TAGS = {}
|
||||
|
||||
class TagInfo(namedtuple("_TagInfo", "value name type length enum")):
|
||||
__slots__ = []
|
||||
|
||||
|
@ -34,7 +37,7 @@ class TagInfo(namedtuple("_TagInfo", "value name type length enum")):
|
|||
#
|
||||
# id: (Name, Type, Length, enum_values)
|
||||
#
|
||||
TAGS = {
|
||||
TAGS_V2 = {
|
||||
|
||||
254: ("NewSubfileType", 4, 1),
|
||||
255: ("SubfileType", 3, 1),
|
||||
|
@ -160,12 +163,17 @@ TAGS = {
|
|||
50839: ("ImageJMetaData", 7, 1)
|
||||
}
|
||||
|
||||
def _populate():
|
||||
for k, v in TAGS_V2.items():
|
||||
# Populate legacy structure.
|
||||
TAGS[k] = v[0]
|
||||
if len(v) == 4:
|
||||
for sk,sv in v[3].items():
|
||||
TAGS[(k,sk)] = sv
|
||||
|
||||
TAGS_V2[k] = TagInfo(k, *v)
|
||||
|
||||
for k, v in TAGS.items():
|
||||
TAGS[k] = TagInfo(k, *v)
|
||||
del k, v
|
||||
|
||||
|
||||
_populate()
|
||||
##
|
||||
# Map type numbers to type names -- defined in ImageFileDirectory.
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ from helper import unittest, PillowTestCase, hopper
|
|||
|
||||
from PIL import Image, TiffImagePlugin, TiffTags
|
||||
|
||||
tag_ids = dict((info.name, info.value) for info in TiffTags.TAGS.values())
|
||||
tag_ids = dict((info.name, info.value) for info in TiffTags.TAGS_V2.values())
|
||||
|
||||
|
||||
class TestFileTiffMetadata(PillowTestCase):
|
||||
|
|
Loading…
Reference in New Issue
Block a user