Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/PIL/TiffTags.py: 88%
46 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
1#
2# The Python Imaging Library.
3# $Id$
4#
5# TIFF tags
6#
7# This module provides clear-text names for various well-known
8# TIFF tags. the TIFF codec works just fine without it.
9#
10# Copyright (c) Secret Labs AB 1999.
11#
12# See the README file for information on usage and redistribution.
13#
15##
16# This module provides constants and clear-text names for various
17# well-known TIFF tags.
18##
20from collections import namedtuple
23class TagInfo(namedtuple("_TagInfo", "value name type length enum")):
24 __slots__ = []
26 def __new__(cls, value=None, name="unknown", type=None, length=None, enum=None):
27 return super().__new__(cls, value, name, type, length, enum or {})
29 def cvt_enum(self, value):
30 # Using get will call hash(value), which can be expensive
31 # for some types (e.g. Fraction). Since self.enum is rarely
32 # used, it's usually better to test it first.
33 return self.enum.get(value, value) if self.enum else value
36def lookup(tag, group=None):
37 """
38 :param tag: Integer tag number
39 :param group: Which :py:data:`~PIL.TiffTags.TAGS_V2_GROUPS` to look in
41 .. versionadded:: 8.3.0
43 :returns: Taginfo namedtuple, From the ``TAGS_V2`` info if possible,
44 otherwise just populating the value and name from ``TAGS``.
45 If the tag is not recognized, "unknown" is returned for the name
47 """
49 if group is not None:
50 info = TAGS_V2_GROUPS[group].get(tag) if group in TAGS_V2_GROUPS else None
51 else:
52 info = TAGS_V2.get(tag)
53 return info or TagInfo(tag, TAGS.get(tag, "unknown"))
56##
57# Map tag numbers to tag info.
58#
59# id: (Name, Type, Length, enum_values)
60#
61# The length here differs from the length in the tiff spec. For
62# numbers, the tiff spec is for the number of fields returned. We
63# agree here. For string-like types, the tiff spec uses the length of
64# field in bytes. In Pillow, we are using the number of expected
65# fields, in general 1 for string-like types.
68BYTE = 1
69ASCII = 2
70SHORT = 3
71LONG = 4
72RATIONAL = 5
73SIGNED_BYTE = 6
74UNDEFINED = 7
75SIGNED_SHORT = 8
76SIGNED_LONG = 9
77SIGNED_RATIONAL = 10
78FLOAT = 11
79DOUBLE = 12
80IFD = 13
81LONG8 = 16
83TAGS_V2 = {
84 254: ("NewSubfileType", LONG, 1),
85 255: ("SubfileType", SHORT, 1),
86 256: ("ImageWidth", LONG, 1),
87 257: ("ImageLength", LONG, 1),
88 258: ("BitsPerSample", SHORT, 0),
89 259: (
90 "Compression",
91 SHORT,
92 1,
93 {
94 "Uncompressed": 1,
95 "CCITT 1d": 2,
96 "Group 3 Fax": 3,
97 "Group 4 Fax": 4,
98 "LZW": 5,
99 "JPEG": 6,
100 "PackBits": 32773,
101 },
102 ),
103 262: (
104 "PhotometricInterpretation",
105 SHORT,
106 1,
107 {
108 "WhiteIsZero": 0,
109 "BlackIsZero": 1,
110 "RGB": 2,
111 "RGB Palette": 3,
112 "Transparency Mask": 4,
113 "CMYK": 5,
114 "YCbCr": 6,
115 "CieLAB": 8,
116 "CFA": 32803, # TIFF/EP, Adobe DNG
117 "LinearRaw": 32892, # Adobe DNG
118 },
119 ),
120 263: ("Threshholding", SHORT, 1),
121 264: ("CellWidth", SHORT, 1),
122 265: ("CellLength", SHORT, 1),
123 266: ("FillOrder", SHORT, 1),
124 269: ("DocumentName", ASCII, 1),
125 270: ("ImageDescription", ASCII, 1),
126 271: ("Make", ASCII, 1),
127 272: ("Model", ASCII, 1),
128 273: ("StripOffsets", LONG, 0),
129 274: ("Orientation", SHORT, 1),
130 277: ("SamplesPerPixel", SHORT, 1),
131 278: ("RowsPerStrip", LONG, 1),
132 279: ("StripByteCounts", LONG, 0),
133 280: ("MinSampleValue", SHORT, 0),
134 281: ("MaxSampleValue", SHORT, 0),
135 282: ("XResolution", RATIONAL, 1),
136 283: ("YResolution", RATIONAL, 1),
137 284: ("PlanarConfiguration", SHORT, 1, {"Contiguous": 1, "Separate": 2}),
138 285: ("PageName", ASCII, 1),
139 286: ("XPosition", RATIONAL, 1),
140 287: ("YPosition", RATIONAL, 1),
141 288: ("FreeOffsets", LONG, 1),
142 289: ("FreeByteCounts", LONG, 1),
143 290: ("GrayResponseUnit", SHORT, 1),
144 291: ("GrayResponseCurve", SHORT, 0),
145 292: ("T4Options", LONG, 1),
146 293: ("T6Options", LONG, 1),
147 296: ("ResolutionUnit", SHORT, 1, {"none": 1, "inch": 2, "cm": 3}),
148 297: ("PageNumber", SHORT, 2),
149 301: ("TransferFunction", SHORT, 0),
150 305: ("Software", ASCII, 1),
151 306: ("DateTime", ASCII, 1),
152 315: ("Artist", ASCII, 1),
153 316: ("HostComputer", ASCII, 1),
154 317: ("Predictor", SHORT, 1, {"none": 1, "Horizontal Differencing": 2}),
155 318: ("WhitePoint", RATIONAL, 2),
156 319: ("PrimaryChromaticities", RATIONAL, 6),
157 320: ("ColorMap", SHORT, 0),
158 321: ("HalftoneHints", SHORT, 2),
159 322: ("TileWidth", LONG, 1),
160 323: ("TileLength", LONG, 1),
161 324: ("TileOffsets", LONG, 0),
162 325: ("TileByteCounts", LONG, 0),
163 332: ("InkSet", SHORT, 1),
164 333: ("InkNames", ASCII, 1),
165 334: ("NumberOfInks", SHORT, 1),
166 336: ("DotRange", SHORT, 0),
167 337: ("TargetPrinter", ASCII, 1),
168 338: ("ExtraSamples", SHORT, 0),
169 339: ("SampleFormat", SHORT, 0),
170 340: ("SMinSampleValue", DOUBLE, 0),
171 341: ("SMaxSampleValue", DOUBLE, 0),
172 342: ("TransferRange", SHORT, 6),
173 347: ("JPEGTables", UNDEFINED, 1),
174 # obsolete JPEG tags
175 512: ("JPEGProc", SHORT, 1),
176 513: ("JPEGInterchangeFormat", LONG, 1),
177 514: ("JPEGInterchangeFormatLength", LONG, 1),
178 515: ("JPEGRestartInterval", SHORT, 1),
179 517: ("JPEGLosslessPredictors", SHORT, 0),
180 518: ("JPEGPointTransforms", SHORT, 0),
181 519: ("JPEGQTables", LONG, 0),
182 520: ("JPEGDCTables", LONG, 0),
183 521: ("JPEGACTables", LONG, 0),
184 529: ("YCbCrCoefficients", RATIONAL, 3),
185 530: ("YCbCrSubSampling", SHORT, 2),
186 531: ("YCbCrPositioning", SHORT, 1),
187 532: ("ReferenceBlackWhite", RATIONAL, 6),
188 700: ("XMP", BYTE, 0),
189 33432: ("Copyright", ASCII, 1),
190 33723: ("IptcNaaInfo", UNDEFINED, 1),
191 34377: ("PhotoshopInfo", BYTE, 0),
192 # FIXME add more tags here
193 34665: ("ExifIFD", LONG, 1),
194 34675: ("ICCProfile", UNDEFINED, 1),
195 34853: ("GPSInfoIFD", LONG, 1),
196 36864: ("ExifVersion", UNDEFINED, 1),
197 40965: ("InteroperabilityIFD", LONG, 1),
198 41730: ("CFAPattern", UNDEFINED, 1),
199 # MPInfo
200 45056: ("MPFVersion", UNDEFINED, 1),
201 45057: ("NumberOfImages", LONG, 1),
202 45058: ("MPEntry", UNDEFINED, 1),
203 45059: ("ImageUIDList", UNDEFINED, 0), # UNDONE, check
204 45060: ("TotalFrames", LONG, 1),
205 45313: ("MPIndividualNum", LONG, 1),
206 45569: ("PanOrientation", LONG, 1),
207 45570: ("PanOverlap_H", RATIONAL, 1),
208 45571: ("PanOverlap_V", RATIONAL, 1),
209 45572: ("BaseViewpointNum", LONG, 1),
210 45573: ("ConvergenceAngle", SIGNED_RATIONAL, 1),
211 45574: ("BaselineLength", RATIONAL, 1),
212 45575: ("VerticalDivergence", SIGNED_RATIONAL, 1),
213 45576: ("AxisDistance_X", SIGNED_RATIONAL, 1),
214 45577: ("AxisDistance_Y", SIGNED_RATIONAL, 1),
215 45578: ("AxisDistance_Z", SIGNED_RATIONAL, 1),
216 45579: ("YawAngle", SIGNED_RATIONAL, 1),
217 45580: ("PitchAngle", SIGNED_RATIONAL, 1),
218 45581: ("RollAngle", SIGNED_RATIONAL, 1),
219 40960: ("FlashPixVersion", UNDEFINED, 1),
220 50741: ("MakerNoteSafety", SHORT, 1, {"Unsafe": 0, "Safe": 1}),
221 50780: ("BestQualityScale", RATIONAL, 1),
222 50838: ("ImageJMetaDataByteCounts", LONG, 0), # Can be more than one
223 50839: ("ImageJMetaData", UNDEFINED, 1), # see Issue #2006
224}
225TAGS_V2_GROUPS = {
226 # ExifIFD
227 34665: {
228 36864: ("ExifVersion", UNDEFINED, 1),
229 40960: ("FlashPixVersion", UNDEFINED, 1),
230 40965: ("InteroperabilityIFD", LONG, 1),
231 41730: ("CFAPattern", UNDEFINED, 1),
232 },
233 # GPSInfoIFD
234 34853: {},
235 # InteroperabilityIFD
236 40965: {1: ("InteropIndex", ASCII, 1), 2: ("InteropVersion", UNDEFINED, 1)},
237}
239# Legacy Tags structure
240# these tags aren't included above, but were in the previous versions
241TAGS = {
242 347: "JPEGTables",
243 700: "XMP",
244 # Additional Exif Info
245 32932: "Wang Annotation",
246 33434: "ExposureTime",
247 33437: "FNumber",
248 33445: "MD FileTag",
249 33446: "MD ScalePixel",
250 33447: "MD ColorTable",
251 33448: "MD LabName",
252 33449: "MD SampleInfo",
253 33450: "MD PrepDate",
254 33451: "MD PrepTime",
255 33452: "MD FileUnits",
256 33550: "ModelPixelScaleTag",
257 33723: "IptcNaaInfo",
258 33918: "INGR Packet Data Tag",
259 33919: "INGR Flag Registers",
260 33920: "IrasB Transformation Matrix",
261 33922: "ModelTiepointTag",
262 34264: "ModelTransformationTag",
263 34377: "PhotoshopInfo",
264 34735: "GeoKeyDirectoryTag",
265 34736: "GeoDoubleParamsTag",
266 34737: "GeoAsciiParamsTag",
267 34850: "ExposureProgram",
268 34852: "SpectralSensitivity",
269 34855: "ISOSpeedRatings",
270 34856: "OECF",
271 34864: "SensitivityType",
272 34865: "StandardOutputSensitivity",
273 34866: "RecommendedExposureIndex",
274 34867: "ISOSpeed",
275 34868: "ISOSpeedLatitudeyyy",
276 34869: "ISOSpeedLatitudezzz",
277 34908: "HylaFAX FaxRecvParams",
278 34909: "HylaFAX FaxSubAddress",
279 34910: "HylaFAX FaxRecvTime",
280 36864: "ExifVersion",
281 36867: "DateTimeOriginal",
282 36868: "DateTImeDigitized",
283 37121: "ComponentsConfiguration",
284 37122: "CompressedBitsPerPixel",
285 37724: "ImageSourceData",
286 37377: "ShutterSpeedValue",
287 37378: "ApertureValue",
288 37379: "BrightnessValue",
289 37380: "ExposureBiasValue",
290 37381: "MaxApertureValue",
291 37382: "SubjectDistance",
292 37383: "MeteringMode",
293 37384: "LightSource",
294 37385: "Flash",
295 37386: "FocalLength",
296 37396: "SubjectArea",
297 37500: "MakerNote",
298 37510: "UserComment",
299 37520: "SubSec",
300 37521: "SubSecTimeOriginal",
301 37522: "SubsecTimeDigitized",
302 40960: "FlashPixVersion",
303 40961: "ColorSpace",
304 40962: "PixelXDimension",
305 40963: "PixelYDimension",
306 40964: "RelatedSoundFile",
307 40965: "InteroperabilityIFD",
308 41483: "FlashEnergy",
309 41484: "SpatialFrequencyResponse",
310 41486: "FocalPlaneXResolution",
311 41487: "FocalPlaneYResolution",
312 41488: "FocalPlaneResolutionUnit",
313 41492: "SubjectLocation",
314 41493: "ExposureIndex",
315 41495: "SensingMethod",
316 41728: "FileSource",
317 41729: "SceneType",
318 41730: "CFAPattern",
319 41985: "CustomRendered",
320 41986: "ExposureMode",
321 41987: "WhiteBalance",
322 41988: "DigitalZoomRatio",
323 41989: "FocalLengthIn35mmFilm",
324 41990: "SceneCaptureType",
325 41991: "GainControl",
326 41992: "Contrast",
327 41993: "Saturation",
328 41994: "Sharpness",
329 41995: "DeviceSettingDescription",
330 41996: "SubjectDistanceRange",
331 42016: "ImageUniqueID",
332 42032: "CameraOwnerName",
333 42033: "BodySerialNumber",
334 42034: "LensSpecification",
335 42035: "LensMake",
336 42036: "LensModel",
337 42037: "LensSerialNumber",
338 42112: "GDAL_METADATA",
339 42113: "GDAL_NODATA",
340 42240: "Gamma",
341 50215: "Oce Scanjob Description",
342 50216: "Oce Application Selector",
343 50217: "Oce Identification Number",
344 50218: "Oce ImageLogic Characteristics",
345 # Adobe DNG
346 50706: "DNGVersion",
347 50707: "DNGBackwardVersion",
348 50708: "UniqueCameraModel",
349 50709: "LocalizedCameraModel",
350 50710: "CFAPlaneColor",
351 50711: "CFALayout",
352 50712: "LinearizationTable",
353 50713: "BlackLevelRepeatDim",
354 50714: "BlackLevel",
355 50715: "BlackLevelDeltaH",
356 50716: "BlackLevelDeltaV",
357 50717: "WhiteLevel",
358 50718: "DefaultScale",
359 50719: "DefaultCropOrigin",
360 50720: "DefaultCropSize",
361 50721: "ColorMatrix1",
362 50722: "ColorMatrix2",
363 50723: "CameraCalibration1",
364 50724: "CameraCalibration2",
365 50725: "ReductionMatrix1",
366 50726: "ReductionMatrix2",
367 50727: "AnalogBalance",
368 50728: "AsShotNeutral",
369 50729: "AsShotWhiteXY",
370 50730: "BaselineExposure",
371 50731: "BaselineNoise",
372 50732: "BaselineSharpness",
373 50733: "BayerGreenSplit",
374 50734: "LinearResponseLimit",
375 50735: "CameraSerialNumber",
376 50736: "LensInfo",
377 50737: "ChromaBlurRadius",
378 50738: "AntiAliasStrength",
379 50740: "DNGPrivateData",
380 50778: "CalibrationIlluminant1",
381 50779: "CalibrationIlluminant2",
382 50784: "Alias Layer Metadata",
383}
386def _populate():
387 for k, v in TAGS_V2.items():
388 # Populate legacy structure.
389 TAGS[k] = v[0]
390 if len(v) == 4:
391 for sk, sv in v[3].items():
392 TAGS[(k, sv)] = sk
394 TAGS_V2[k] = TagInfo(k, *v)
396 for group, tags in TAGS_V2_GROUPS.items():
397 for k, v in tags.items():
398 tags[k] = TagInfo(k, *v)
401_populate()
402##
403# Map type numbers to type names -- defined in ImageFileDirectory.
405TYPES = {}
407# was:
408# TYPES = {
409# 1: "byte",
410# 2: "ascii",
411# 3: "short",
412# 4: "long",
413# 5: "rational",
414# 6: "signed byte",
415# 7: "undefined",
416# 8: "signed short",
417# 9: "signed long",
418# 10: "signed rational",
419# 11: "float",
420# 12: "double",
421# }
423#
424# These tags are handled by default in libtiff, without
425# adding to the custom dictionary. From tif_dir.c, searching for
426# case TIFFTAG in the _TIFFVSetField function:
427# Line: item.
428# 148: case TIFFTAG_SUBFILETYPE:
429# 151: case TIFFTAG_IMAGEWIDTH:
430# 154: case TIFFTAG_IMAGELENGTH:
431# 157: case TIFFTAG_BITSPERSAMPLE:
432# 181: case TIFFTAG_COMPRESSION:
433# 202: case TIFFTAG_PHOTOMETRIC:
434# 205: case TIFFTAG_THRESHHOLDING:
435# 208: case TIFFTAG_FILLORDER:
436# 214: case TIFFTAG_ORIENTATION:
437# 221: case TIFFTAG_SAMPLESPERPIXEL:
438# 228: case TIFFTAG_ROWSPERSTRIP:
439# 238: case TIFFTAG_MINSAMPLEVALUE:
440# 241: case TIFFTAG_MAXSAMPLEVALUE:
441# 244: case TIFFTAG_SMINSAMPLEVALUE:
442# 247: case TIFFTAG_SMAXSAMPLEVALUE:
443# 250: case TIFFTAG_XRESOLUTION:
444# 256: case TIFFTAG_YRESOLUTION:
445# 262: case TIFFTAG_PLANARCONFIG:
446# 268: case TIFFTAG_XPOSITION:
447# 271: case TIFFTAG_YPOSITION:
448# 274: case TIFFTAG_RESOLUTIONUNIT:
449# 280: case TIFFTAG_PAGENUMBER:
450# 284: case TIFFTAG_HALFTONEHINTS:
451# 288: case TIFFTAG_COLORMAP:
452# 294: case TIFFTAG_EXTRASAMPLES:
453# 298: case TIFFTAG_MATTEING:
454# 305: case TIFFTAG_TILEWIDTH:
455# 316: case TIFFTAG_TILELENGTH:
456# 327: case TIFFTAG_TILEDEPTH:
457# 333: case TIFFTAG_DATATYPE:
458# 344: case TIFFTAG_SAMPLEFORMAT:
459# 361: case TIFFTAG_IMAGEDEPTH:
460# 364: case TIFFTAG_SUBIFD:
461# 376: case TIFFTAG_YCBCRPOSITIONING:
462# 379: case TIFFTAG_YCBCRSUBSAMPLING:
463# 383: case TIFFTAG_TRANSFERFUNCTION:
464# 389: case TIFFTAG_REFERENCEBLACKWHITE:
465# 393: case TIFFTAG_INKNAMES:
467# Following pseudo-tags are also handled by default in libtiff:
468# TIFFTAG_JPEGQUALITY 65537
470# some of these are not in our TAGS_V2 dict and were included from tiff.h
472# This list also exists in encode.c
473LIBTIFF_CORE = {
474 255,
475 256,
476 257,
477 258,
478 259,
479 262,
480 263,
481 266,
482 274,
483 277,
484 278,
485 280,
486 281,
487 340,
488 341,
489 282,
490 283,
491 284,
492 286,
493 287,
494 296,
495 297,
496 321,
497 320,
498 338,
499 32995,
500 322,
501 323,
502 32998,
503 32996,
504 339,
505 32997,
506 330,
507 531,
508 530,
509 301,
510 532,
511 333,
512 # as above
513 269, # this has been in our tests forever, and works
514 65537,
515}
517LIBTIFF_CORE.remove(255) # We don't have support for subfiletypes
518LIBTIFF_CORE.remove(322) # We don't have support for writing tiled images with libtiff
519LIBTIFF_CORE.remove(323) # Tiled images
520LIBTIFF_CORE.remove(333) # Ink Names either
522# Note to advanced users: There may be combinations of these
523# parameters and values that when added properly, will work and
524# produce valid tiff images that may work in your application.
525# It is safe to add and remove tags from this set from Pillow's point
526# of view so long as you test against libtiff.