mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 09:57:43 +03:00 
			
		
		
		
	Support saving variable length rational TIFF tags by default
This commit is contained in:
		
							parent
							
								
									fbdf607c7f
								
							
						
					
					
						commit
						c874256132
					
				| 
						 | 
					@ -367,6 +367,15 @@ class TestFileLibTiff(LibTiffTestCase):
 | 
				
			||||||
            assert isinstance(reloaded, TiffImagePlugin.TiffImageFile)
 | 
					            assert isinstance(reloaded, TiffImagePlugin.TiffImageFile)
 | 
				
			||||||
            assert reloaded.tag_v2[318] == pytest.approx((0.3127, 0.3289))
 | 
					            assert reloaded.tag_v2[318] == pytest.approx((0.3127, 0.3289))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # Save tag by default
 | 
				
			||||||
 | 
					        out = tmp_path / "temp2.tif"
 | 
				
			||||||
 | 
					        with Image.open("Tests/images/rdf.tif") as im:
 | 
				
			||||||
 | 
					            im.save(out)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        with Image.open(out) as reloaded:
 | 
				
			||||||
 | 
					            assert isinstance(reloaded, TiffImagePlugin.TiffImageFile)
 | 
				
			||||||
 | 
					            assert reloaded.tag_v2[318] == pytest.approx((0.3127, 0.3289999))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_xmlpacket_tag(
 | 
					    def test_xmlpacket_tag(
 | 
				
			||||||
        self, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
 | 
					        self, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
 | 
				
			||||||
    ) -> None:
 | 
					    ) -> None:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -252,6 +252,7 @@ OPEN_INFO = {
 | 
				
			||||||
    (II, 3, (1,), 1, (8,), ()): ("P", "P"),
 | 
					    (II, 3, (1,), 1, (8,), ()): ("P", "P"),
 | 
				
			||||||
    (MM, 3, (1,), 1, (8,), ()): ("P", "P"),
 | 
					    (MM, 3, (1,), 1, (8,), ()): ("P", "P"),
 | 
				
			||||||
    (II, 3, (1,), 1, (8, 8), (0,)): ("P", "PX"),
 | 
					    (II, 3, (1,), 1, (8, 8), (0,)): ("P", "PX"),
 | 
				
			||||||
 | 
					    (MM, 3, (1,), 1, (8, 8), (0,)): ("P", "PX"),
 | 
				
			||||||
    (II, 3, (1,), 1, (8, 8), (2,)): ("PA", "PA"),
 | 
					    (II, 3, (1,), 1, (8, 8), (2,)): ("PA", "PA"),
 | 
				
			||||||
    (MM, 3, (1,), 1, (8, 8), (2,)): ("PA", "PA"),
 | 
					    (MM, 3, (1,), 1, (8, 8), (2,)): ("PA", "PA"),
 | 
				
			||||||
    (II, 3, (1,), 2, (8,), ()): ("P", "P;R"),
 | 
					    (II, 3, (1,), 2, (8,), ()): ("P", "P;R"),
 | 
				
			||||||
| 
						 | 
					@ -1177,6 +1178,7 @@ class TiffImageFile(ImageFile.ImageFile):
 | 
				
			||||||
        """Open the first image in a TIFF file"""
 | 
					        """Open the first image in a TIFF file"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Header
 | 
					        # Header
 | 
				
			||||||
 | 
					        assert self.fp is not None
 | 
				
			||||||
        ifh = self.fp.read(8)
 | 
					        ifh = self.fp.read(8)
 | 
				
			||||||
        if ifh[2] == 43:
 | 
					        if ifh[2] == 43:
 | 
				
			||||||
            ifh += self.fp.read(8)
 | 
					            ifh += self.fp.read(8)
 | 
				
			||||||
| 
						 | 
					@ -1343,6 +1345,7 @@ class TiffImageFile(ImageFile.ImageFile):
 | 
				
			||||||
        # To be nice on memory footprint, if there's a
 | 
					        # To be nice on memory footprint, if there's a
 | 
				
			||||||
        # file descriptor, use that instead of reading
 | 
					        # file descriptor, use that instead of reading
 | 
				
			||||||
        # into a string in python.
 | 
					        # into a string in python.
 | 
				
			||||||
 | 
					        assert self.fp is not None
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            fp = hasattr(self.fp, "fileno") and self.fp.fileno()
 | 
					            fp = hasattr(self.fp, "fileno") and self.fp.fileno()
 | 
				
			||||||
            # flush the file descriptor, prevents error on pypy 2.4+
 | 
					            # flush the file descriptor, prevents error on pypy 2.4+
 | 
				
			||||||
| 
						 | 
					@ -1936,9 +1939,10 @@ def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
 | 
				
			||||||
                    types[tag] = TiffTags.LONG8
 | 
					                    types[tag] = TiffTags.LONG8
 | 
				
			||||||
                elif tag in ifd.tagtype:
 | 
					                elif tag in ifd.tagtype:
 | 
				
			||||||
                    types[tag] = ifd.tagtype[tag]
 | 
					                    types[tag] = ifd.tagtype[tag]
 | 
				
			||||||
                elif not (isinstance(value, (int, float, str, bytes))):
 | 
					                elif isinstance(value, (int, float, str, bytes)) or (
 | 
				
			||||||
                    continue
 | 
					                    isinstance(value, tuple)
 | 
				
			||||||
                else:
 | 
					                    and all(isinstance(v, (int, float, IFDRational)) for v in value)
 | 
				
			||||||
 | 
					                ):
 | 
				
			||||||
                    type = TiffTags.lookup(tag).type
 | 
					                    type = TiffTags.lookup(tag).type
 | 
				
			||||||
                    if type:
 | 
					                    if type:
 | 
				
			||||||
                        types[tag] = type
 | 
					                        types[tag] = type
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user