-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Libtiff metadata writing fixes #2288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
18b0a37
1ad3dd7
8a77275
320884d
713d383
e1110b5
c69500e
d79b1d4
5c9de81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,8 +95,8 @@ def lookup(tag): | |
| 278: ("RowsPerStrip", LONG, 1), | ||
| 279: ("StripByteCounts", LONG, 0), | ||
|
|
||
| 280: ("MinSampleValue", LONG, 0), | ||
| 281: ("MaxSampleValue", SHORT, 0), | ||
| 280: ("MinSampleValue", LONG, 1), | ||
| 281: ("MaxSampleValue", SHORT, 1), | ||
| 282: ("XResolution", RATIONAL, 1), | ||
| 283: ("YResolution", RATIONAL, 1), | ||
| 284: ("PlanarConfiguration", SHORT, 1, {"Contiguous": 1, "Separate": 2}), | ||
|
|
@@ -121,7 +121,7 @@ def lookup(tag): | |
| 316: ("HostComputer", ASCII, 1), | ||
| 317: ("Predictor", SHORT, 1, {"none": 1, "Horizontal Differencing": 2}), | ||
| 318: ("WhitePoint", RATIONAL, 2), | ||
| 319: ("PrimaryChromaticities", SHORT, 6), | ||
| 319: ("PrimaryChromaticities", RATIONAL, 6), | ||
|
|
||
| 320: ("ColorMap", SHORT, 0), | ||
| 321: ("HalftoneHints", SHORT, 2), | ||
|
|
@@ -130,16 +130,17 @@ def lookup(tag): | |
| 324: ("TileOffsets", LONG, 0), | ||
| 325: ("TileByteCounts", LONG, 0), | ||
|
|
||
| 330: ("SubIFD", SHORT, 1), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #6569 added this tag, but as "SubIFDs", |
||
| 332: ("InkSet", SHORT, 1), | ||
| 333: ("InkNames", ASCII, 1), | ||
| 334: ("NumberOfInks", SHORT, 1), | ||
| 336: ("DotRange", SHORT, 0), | ||
| 337: ("TargetPrinter", ASCII, 1), | ||
| 338: ("ExtraSamples", SHORT, 0), | ||
| 339: ("SampleFormat", SHORT, 0), | ||
| 339: ("SampleFormat", SHORT, 1), | ||
|
|
||
| 340: ("SMinSampleValue", DOUBLE, 0), | ||
| 341: ("SMaxSampleValue", DOUBLE, 0), | ||
| 340: ("SMinSampleValue", DOUBLE, 1), | ||
| 341: ("SMaxSampleValue", DOUBLE, 1), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see why these changes were made - |
||
| 342: ("TransferRange", SHORT, 6), | ||
|
|
||
| # obsolete JPEG tags | ||
|
|
@@ -156,7 +157,13 @@ def lookup(tag): | |
| 529: ("YCbCrCoefficients", RATIONAL, 3), | ||
| 530: ("YCbCrSubSampling", SHORT, 2), | ||
| 531: ("YCbCrPositioning", SHORT, 1), | ||
| 532: ("ReferenceBlackWhite", LONG, 0), | ||
| 532: ("ReferenceBlackWhite", RATIONAL, 6), | ||
|
|
||
| # sgi, in core | ||
| 32995:("Matteing", SHORT, 1), | ||
| 32996:("DataType", SHORT, 1), | ||
| 32997:("ImageDepth", LONG, 1), | ||
| 32998:("TileDepth", LONG, 1), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at https://gitlab.com/libtiff/libtiff/-/blob/master/libtiff/tif_dirinfo.c?ref_type=heads#L136, I've concluded "DataType" should be I've created #9245 to add these four tags. |
||
|
|
||
| 33432: ("Copyright", ASCII, 1), | ||
|
|
||
|
|
@@ -417,23 +424,25 @@ def _populate(): | |
| # 393: case TIFFTAG_INKNAMES: | ||
|
|
||
| # some of these are not in our TAGS_V2 dict and were included from tiff.h | ||
| # Anything included here needs to have the correct type in TAGS_V2 above | ||
|
|
||
| LIBTIFF_CORE = {255, 256, 257, 258, 259, 262, 263, 266, 274, 277, | ||
| 278, 280, 281, 340, 341, 282, 283, 284, 286, 287, | ||
| 296, 297, 321, 320, 338, 32995, 322, 323, 32998, | ||
| 32996, 339, 32997, 330, 531, 530, 301, 532, 333, | ||
| # as above | ||
| 269 # this has been in our tests forever, and works | ||
| 269, # this has been in our tests forever, and works | ||
| 318, # Whitepoint, Specific test for it | ||
| 319, # Primary Chromaticities | ||
| } | ||
|
|
||
| LIBTIFF_CORE.remove(320) # Array of short, crashes | ||
| LIBTIFF_CORE.remove(301) # Array of short, crashes | ||
| LIBTIFF_CORE.remove(532) # Array of long, crashes | ||
|
||
| LIBTIFF_CORE.remove(330) # subifd, requires extra support for uint64 payload | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that #5120 blocked the tag when saving with libtiff, I don't think this is needed anymore. |
||
|
|
||
| LIBTIFF_CORE.remove(255) # We don't have support for subfiletypes | ||
| LIBTIFF_CORE.remove(322) # We don't have support for tiled images in libtiff | ||
| LIBTIFF_CORE.remove(323) # Tiled images | ||
| LIBTIFF_CORE.remove(333) # Ink Names either | ||
| LIBTIFF_CORE.remove(301) # Transfer Function. No support as of yet. | ||
|
|
||
| # Note to advanced users: There may be combinations of these | ||
| # parameters and values that when added properly, will work and | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -194,6 +194,7 @@ def test_additional_metadata(self): | |||||
| del(core_items[tag]) | ||||||
| except: | ||||||
| pass | ||||||
| del(core_items[320]) # colormap is special, tested below | ||||||
|
|
||||||
| # Type codes: | ||||||
| # 2: "ascii", | ||||||
|
|
@@ -222,11 +223,21 @@ def test_additional_metadata(self): | |||||
|
|
||||||
| out = self.tempfile("temp.tif") | ||||||
| TiffImagePlugin.WRITE_LIBTIFF = True | ||||||
|
|
||||||
| im.save(out, tiffinfo=new_ifd) | ||||||
|
|
||||||
| TiffImagePlugin.WRITE_LIBTIFF = False | ||||||
|
|
||||||
| def test_int_dpi(self): | ||||||
| # issue #1765 | ||||||
| im = hopper('RGB') | ||||||
| out = self.tempfile('temp.tif') | ||||||
| TiffImagePlugin.WRITE_LIBTIFF = True | ||||||
| im.save(out, dpi=(72, 72)) | ||||||
| TiffImagePlugin.WRITE_LIBTIFF = False | ||||||
| reloaded = Image.open(out) | ||||||
| self.assertEqual(reloaded.info['dpi'], (72.0, 72.0)) | ||||||
|
|
||||||
| def test_g3_compression(self): | ||||||
| i = Image.open('Tests/images/hopper_g4_500.tif') | ||||||
| out = self.tempfile("temp.tif") | ||||||
|
|
@@ -354,6 +365,19 @@ def test_cmyk_save(self): | |||||
| im2 = Image.open(out) | ||||||
| self.assert_image_equal(im, im2) | ||||||
|
|
||||||
| def test_palette_save(self): | ||||||
| im = hopper('P') | ||||||
| out = self.tempfile('temp.tif') | ||||||
| TiffImagePlugin.WRITE_LIBTIFF = True | ||||||
| im.save(out) | ||||||
| TiffImagePlugin.WRITE_LIBTIFF = False | ||||||
|
|
||||||
| reloaded = Image.open(out) | ||||||
| # colormap/palette tag | ||||||
| self.assertTrue(len(reloaded.tag_v2[320]), 768) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| self.assert_image_equal(im, reloaded) | ||||||
|
|
||||||
|
|
||||||
| def xtest_bw_compression_w_rgb(self): | ||||||
| """ This test passes, but when running all tests causes a failure due | ||||||
| to output on stderr from the error thrown by libtiff. We need to | ||||||
|
|
@@ -493,6 +517,16 @@ def test_crashing_metadata(self): | |||||
| im.save(out, format='TIFF') | ||||||
| TiffImagePlugin.WRITE_LIBTIFF = False | ||||||
|
|
||||||
| reloaded = Image.open(out) | ||||||
|
|
||||||
| self.assert_image_equal(im, reloaded) | ||||||
| for tag in (318, 319): | ||||||
| for ix in range(len(im.tag_v2[tag])): | ||||||
| self.assertAlmostEqual(float(im.tag_v2[tag][ix]), | ||||||
| float(reloaded.tag_v2[tag][ix]), | ||||||
| places=5) | ||||||
|
|
||||||
|
|
||||||
| def test_page_number_x_0(self): | ||||||
| # Issue 973 | ||||||
| # Test TIFF with tag 297 (Page Number) having value of 0 0. | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,3 +6,5 @@ Internal Reference Docs | |
|
|
||
| open_files | ||
| limits | ||
| tiff_metadata | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why this change was made - https://www.awaresystems.be/imaging/tiff/tifftags/minsamplevalue.html and https://www.awaresystems.be/imaging/tiff/tifftags/maxsamplevalue.html