mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 09:56:17 +03:00
Merge pull request #875 from hugovk/tifftags
Correct duplicate EXIF and TIFF tags
This commit is contained in:
commit
f6caaa1c9f
|
@ -67,8 +67,8 @@ TAGS = {
|
||||||
0x0213: "YCbCrPositioning",
|
0x0213: "YCbCrPositioning",
|
||||||
0x0214: "ReferenceBlackWhite",
|
0x0214: "ReferenceBlackWhite",
|
||||||
0x1000: "RelatedImageFileFormat",
|
0x1000: "RelatedImageFileFormat",
|
||||||
0x1001: "RelatedImageLength", # FIXME / Dictionary contains duplicate keys
|
0x1001: "RelatedImageWidth",
|
||||||
0x1001: "RelatedImageWidth", # FIXME \ Dictionary contains duplicate keys
|
0x1002: "RelatedImageLength",
|
||||||
0x828d: "CFARepeatPatternDim",
|
0x828d: "CFARepeatPatternDim",
|
||||||
0x828e: "CFAPattern",
|
0x828e: "CFAPattern",
|
||||||
0x828f: "BatteryLevel",
|
0x828f: "BatteryLevel",
|
||||||
|
|
|
@ -46,8 +46,8 @@ TAGS = {
|
||||||
(262, 5): "CMYK",
|
(262, 5): "CMYK",
|
||||||
(262, 6): "YCbCr",
|
(262, 6): "YCbCr",
|
||||||
(262, 8): "CieLAB",
|
(262, 8): "CieLAB",
|
||||||
(262, 32803): "CFA", # TIFF/EP, Adobe DNG
|
(262, 32803): "CFA", # TIFF/EP, Adobe DNG
|
||||||
(262, 32892): "LinearRaw", # Adobe DNG
|
(262, 32892): "LinearRaw", # Adobe DNG
|
||||||
|
|
||||||
263: "Thresholding",
|
263: "Thresholding",
|
||||||
264: "CellWidth",
|
264: "CellWidth",
|
||||||
|
@ -240,7 +240,7 @@ TAGS = {
|
||||||
45579: "YawAngle",
|
45579: "YawAngle",
|
||||||
45580: "PitchAngle",
|
45580: "PitchAngle",
|
||||||
45581: "RollAngle",
|
45581: "RollAngle",
|
||||||
|
|
||||||
# Adobe DNG
|
# Adobe DNG
|
||||||
50706: "DNGVersion",
|
50706: "DNGVersion",
|
||||||
50707: "DNGBackwardVersion",
|
50707: "DNGBackwardVersion",
|
||||||
|
@ -255,7 +255,6 @@ TAGS = {
|
||||||
50716: "BlackLevelDeltaV",
|
50716: "BlackLevelDeltaV",
|
||||||
50717: "WhiteLevel",
|
50717: "WhiteLevel",
|
||||||
50718: "DefaultScale",
|
50718: "DefaultScale",
|
||||||
50741: "BestQualityScale", # FIXME! Dictionary contains duplicate keys 50741
|
|
||||||
50719: "DefaultCropOrigin",
|
50719: "DefaultCropOrigin",
|
||||||
50720: "DefaultCropSize",
|
50720: "DefaultCropSize",
|
||||||
50778: "CalibrationIlluminant1",
|
50778: "CalibrationIlluminant1",
|
||||||
|
@ -279,11 +278,12 @@ TAGS = {
|
||||||
50737: "ChromaBlurRadius",
|
50737: "ChromaBlurRadius",
|
||||||
50738: "AntiAliasStrength",
|
50738: "AntiAliasStrength",
|
||||||
50740: "DNGPrivateData",
|
50740: "DNGPrivateData",
|
||||||
50741: "MakerNoteSafety", # FIXME! Dictionary contains duplicate keys 50741
|
50741: "MakerNoteSafety",
|
||||||
|
50780: "BestQualityScale",
|
||||||
|
|
||||||
#ImageJ
|
# ImageJ
|
||||||
50838: "ImageJMetaDataByteCounts", # private tag registered with Adobe
|
50838: "ImageJMetaDataByteCounts", # private tag registered with Adobe
|
||||||
50839: "ImageJMetaData", # private tag registered with Adobe
|
50839: "ImageJMetaData", # private tag registered with Adobe
|
||||||
}
|
}
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
|
@ -60,7 +60,8 @@ class TestFileJpeg(PillowTestCase):
|
||||||
self.assertGreater(y, 0.8)
|
self.assertGreater(y, 0.8)
|
||||||
self.assertEqual(k, 0.0)
|
self.assertEqual(k, 0.0)
|
||||||
# the opposite corner is black
|
# the opposite corner is black
|
||||||
c, m, y, k = [x / 255.0 for x in im.getpixel((im.size[0]-1, im.size[1]-1))]
|
c, m, y, k = [x / 255.0 for x in im.getpixel((
|
||||||
|
im.size[0]-1, im.size[1]-1))]
|
||||||
self.assertGreater(k, 0.9)
|
self.assertGreater(k, 0.9)
|
||||||
# roundtrip, and check again
|
# roundtrip, and check again
|
||||||
im = self.roundtrip(im)
|
im = self.roundtrip(im)
|
||||||
|
@ -69,7 +70,8 @@ class TestFileJpeg(PillowTestCase):
|
||||||
self.assertGreater(m, 0.8)
|
self.assertGreater(m, 0.8)
|
||||||
self.assertGreater(y, 0.8)
|
self.assertGreater(y, 0.8)
|
||||||
self.assertEqual(k, 0.0)
|
self.assertEqual(k, 0.0)
|
||||||
c, m, y, k = [x / 255.0 for x in im.getpixel((im.size[0]-1, im.size[1]-1))]
|
c, m, y, k = [x / 255.0 for x in im.getpixel((
|
||||||
|
im.size[0]-1, im.size[1]-1))]
|
||||||
self.assertGreater(k, 0.9)
|
self.assertGreater(k, 0.9)
|
||||||
|
|
||||||
def test_dpi(self):
|
def test_dpi(self):
|
||||||
|
@ -150,7 +152,8 @@ class TestFileJpeg(PillowTestCase):
|
||||||
if py3:
|
if py3:
|
||||||
a = bytes(random.randint(0, 255) for _ in range(256 * 256 * 3))
|
a = bytes(random.randint(0, 255) for _ in range(256 * 256 * 3))
|
||||||
else:
|
else:
|
||||||
a = b''.join(chr(random.randint(0, 255)) for _ in range(256 * 256 * 3))
|
a = b''.join(chr(random.randint(0, 255)) for _ in range(
|
||||||
|
256 * 256 * 3))
|
||||||
im = Image.frombuffer("RGB", (256, 256), a, "raw", "RGB", 0, 1)
|
im = Image.frombuffer("RGB", (256, 256), a, "raw", "RGB", 0, 1)
|
||||||
# this requires more bytes than pixels in the image
|
# this requires more bytes than pixels in the image
|
||||||
im.save(f, format="JPEG", progressive=True, quality=100)
|
im.save(f, format="JPEG", progressive=True, quality=100)
|
||||||
|
@ -235,11 +238,13 @@ class TestFileJpeg(PillowTestCase):
|
||||||
qtables = im.quantization
|
qtables = im.quantization
|
||||||
reloaded = self.roundtrip(im, qtables=qtables, subsampling=0)
|
reloaded = self.roundtrip(im, qtables=qtables, subsampling=0)
|
||||||
self.assertEqual(im.quantization, reloaded.quantization)
|
self.assertEqual(im.quantization, reloaded.quantization)
|
||||||
self.assert_image_similar(im, self.roundtrip(im, qtables='web_low'), 30)
|
self.assert_image_similar(im, self.roundtrip(im, qtables='web_low'),
|
||||||
self.assert_image_similar(im, self.roundtrip(im, qtables='web_high'), 30)
|
30)
|
||||||
|
self.assert_image_similar(im, self.roundtrip(im, qtables='web_high'),
|
||||||
|
30)
|
||||||
self.assert_image_similar(im, self.roundtrip(im, qtables='keep'), 30)
|
self.assert_image_similar(im, self.roundtrip(im, qtables='keep'), 30)
|
||||||
|
|
||||||
#values from wizard.txt in jpeg9-a src package.
|
# values from wizard.txt in jpeg9-a src package.
|
||||||
standard_l_qtable = [int(s) for s in """
|
standard_l_qtable = [int(s) for s in """
|
||||||
16 11 10 16 24 40 51 61
|
16 11 10 16 24 40 51 61
|
||||||
12 12 14 19 26 58 60 55
|
12 12 14 19 26 58 60 55
|
||||||
|
@ -251,7 +256,7 @@ class TestFileJpeg(PillowTestCase):
|
||||||
72 92 95 98 112 100 103 99
|
72 92 95 98 112 100 103 99
|
||||||
""".split(None)]
|
""".split(None)]
|
||||||
|
|
||||||
standard_chrominance_qtable= [int(s) for s in """
|
standard_chrominance_qtable = [int(s) for s in """
|
||||||
17 18 24 47 99 99 99 99
|
17 18 24 47 99 99 99 99
|
||||||
18 21 26 66 99 99 99 99
|
18 21 26 66 99 99 99 99
|
||||||
24 26 56 99 99 99 99 99
|
24 26 56 99 99 99 99 99
|
||||||
|
@ -276,8 +281,8 @@ class TestFileJpeg(PillowTestCase):
|
||||||
# dict of qtable lists
|
# dict of qtable lists
|
||||||
self.assert_image_similar(im,
|
self.assert_image_similar(im,
|
||||||
self.roundtrip(im,
|
self.roundtrip(im,
|
||||||
qtables={0:standard_l_qtable,
|
qtables={0: standard_l_qtable,
|
||||||
1:standard_chrominance_qtable}),
|
1: standard_chrominance_qtable}),
|
||||||
30)
|
30)
|
||||||
|
|
||||||
@unittest.skipUnless(djpeg_available(), "djpeg not available")
|
@unittest.skipUnless(djpeg_available(), "djpeg not available")
|
||||||
|
@ -295,6 +300,15 @@ class TestFileJpeg(PillowTestCase):
|
||||||
# Default save quality is 75%, so a tiny bit of difference is alright
|
# Default save quality is 75%, so a tiny bit of difference is alright
|
||||||
self.assert_image_similar(img, Image.open(tempfile), 1)
|
self.assert_image_similar(img, Image.open(tempfile), 1)
|
||||||
|
|
||||||
|
def test_no_duplicate_0x1001_tag(self):
|
||||||
|
# Arrange
|
||||||
|
from PIL import ExifTags
|
||||||
|
tag_ids = dict(zip(ExifTags.TAGS.values(), ExifTags.TAGS.keys()))
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
self.assertEqual(tag_ids['RelatedImageWidth'], 0x1001)
|
||||||
|
self.assertEqual(tag_ids['RelatedImageLength'], 0x1002)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -8,7 +8,7 @@ tag_ids = dict(zip(TiffTags.TAGS.values(), TiffTags.TAGS.keys()))
|
||||||
class TestFileTiffMetadata(PillowTestCase):
|
class TestFileTiffMetadata(PillowTestCase):
|
||||||
|
|
||||||
def test_rt_metadata(self):
|
def test_rt_metadata(self):
|
||||||
""" Test writing arbitray metadata into the tiff image directory
|
""" Test writing arbitrary metadata into the tiff image directory
|
||||||
Use case is ImageJ private tags, one numeric, one arbitrary
|
Use case is ImageJ private tags, one numeric, one arbitrary
|
||||||
data. https://github.com/python-pillow/Pillow/issues/291
|
data. https://github.com/python-pillow/Pillow/issues/291
|
||||||
"""
|
"""
|
||||||
|
@ -86,6 +86,10 @@ class TestFileTiffMetadata(PillowTestCase):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
value, reloaded[tag], "%s didn't roundtrip" % tag)
|
value, reloaded[tag], "%s didn't roundtrip" % tag)
|
||||||
|
|
||||||
|
def test_no_duplicate_50741_tag(self):
|
||||||
|
self.assertEqual(tag_ids['MakerNoteSafety'], 50741)
|
||||||
|
self.assertEqual(tag_ids['BestQualityScale'], 50780)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user