mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 09:57:43 +03:00 
			
		
		
		
	Merge pull request #3672 from radarhere/tiff_tag_type
Corrected length of Tiff BYTE tags
This commit is contained in:
		
						commit
						c88ada1dcd
					
				| 
						 | 
				
			
			@ -234,11 +234,11 @@ class TestFileLibTiff(LibTiffTestCase):
 | 
			
		|||
 | 
			
		||||
    def test_custom_metadata(self):
 | 
			
		||||
        custom = {
 | 
			
		||||
            37000: 4,
 | 
			
		||||
            37001: 4.2,
 | 
			
		||||
            37002: 'custom tag value',
 | 
			
		||||
            37003: u'custom tag value',
 | 
			
		||||
            37004: b'custom tag value'
 | 
			
		||||
            37000: [4, TiffTags.SHORT],
 | 
			
		||||
            37001: [4.2, TiffTags.RATIONAL],
 | 
			
		||||
            37002: ['custom tag value', TiffTags.ASCII],
 | 
			
		||||
            37003: [u'custom tag value', TiffTags.ASCII],
 | 
			
		||||
            37004: [b'custom tag value', TiffTags.BYTE]
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        libtiff_version = TiffImagePlugin._libtiff_version()
 | 
			
		||||
| 
						 | 
				
			
			@ -251,17 +251,33 @@ class TestFileLibTiff(LibTiffTestCase):
 | 
			
		|||
        for libtiff in libtiffs:
 | 
			
		||||
            TiffImagePlugin.WRITE_LIBTIFF = libtiff
 | 
			
		||||
 | 
			
		||||
            im = hopper()
 | 
			
		||||
            def check_tags(tiffinfo):
 | 
			
		||||
                im = hopper()
 | 
			
		||||
 | 
			
		||||
            out = self.tempfile("temp.tif")
 | 
			
		||||
            im.save(out, tiffinfo=custom)
 | 
			
		||||
            TiffImagePlugin.WRITE_LIBTIFF = False
 | 
			
		||||
                out = self.tempfile("temp.tif")
 | 
			
		||||
                im.save(out, tiffinfo=tiffinfo)
 | 
			
		||||
 | 
			
		||||
            reloaded = Image.open(out)
 | 
			
		||||
            for tag, value in custom.items():
 | 
			
		||||
                if libtiff and isinstance(value, bytes):
 | 
			
		||||
                    value = value.decode()
 | 
			
		||||
                self.assertEqual(reloaded.tag_v2[tag], value)
 | 
			
		||||
                reloaded = Image.open(out)
 | 
			
		||||
                for tag, value in tiffinfo.items():
 | 
			
		||||
                    reloaded_value = reloaded.tag_v2[tag]
 | 
			
		||||
                    if isinstance(reloaded_value, TiffImagePlugin.IFDRational):
 | 
			
		||||
                        reloaded_value = float(reloaded_value)
 | 
			
		||||
 | 
			
		||||
                    if libtiff and isinstance(value, bytes):
 | 
			
		||||
                        value = value.decode()
 | 
			
		||||
 | 
			
		||||
                    self.assertEqual(reloaded_value, value)
 | 
			
		||||
 | 
			
		||||
            # Test with types
 | 
			
		||||
            ifd = TiffImagePlugin.ImageFileDirectory_v2()
 | 
			
		||||
            for tag, tagdata in custom.items():
 | 
			
		||||
                ifd[tag] = tagdata[0]
 | 
			
		||||
                ifd.tagtype[tag] = tagdata[1]
 | 
			
		||||
            check_tags(ifd)
 | 
			
		||||
 | 
			
		||||
            # Test without types
 | 
			
		||||
            check_tags({tag: tagdata[0] for tag, tagdata in custom.items()})
 | 
			
		||||
        TiffImagePlugin.WRITE_LIBTIFF = False
 | 
			
		||||
 | 
			
		||||
    def test_int_dpi(self):
 | 
			
		||||
        # issue #1765
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -819,7 +819,7 @@ class ImageFileDirectory_v2(MutableMapping):
 | 
			
		|||
                    print("- value:", values)
 | 
			
		||||
 | 
			
		||||
            # count is sum of lengths for string and arbitrary data
 | 
			
		||||
            if typ in [TiffTags.ASCII, TiffTags.UNDEFINED]:
 | 
			
		||||
            if typ in [TiffTags.BYTE, TiffTags.ASCII, TiffTags.UNDEFINED]:
 | 
			
		||||
                count = len(data)
 | 
			
		||||
            else:
 | 
			
		||||
                count = len(values)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user