mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 01:47:47 +03:00 
			
		
		
		
	Merge pull request #6569 from radarhere/tiff_child_images
This commit is contained in:
		
						commit
						aa8877ac5b
					
				
							
								
								
									
										
											BIN
										
									
								
								Tests/images/child_ifd.tiff
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Tests/images/child_ifd.tiff
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								Tests/images/child_ifd_jpeg.tiff
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Tests/images/child_ifd_jpeg.tiff
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
						 | 
					@ -84,6 +84,24 @@ class TestFileTiff:
 | 
				
			||||||
            with Image.open("Tests/images/multipage.tiff") as im:
 | 
					            with Image.open("Tests/images/multipage.tiff") as im:
 | 
				
			||||||
                im.load()
 | 
					                im.load()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @pytest.mark.parametrize(
 | 
				
			||||||
 | 
					        "path, sizes",
 | 
				
			||||||
 | 
					        (
 | 
				
			||||||
 | 
					            ("Tests/images/hopper.tif", ()),
 | 
				
			||||||
 | 
					            ("Tests/images/child_ifd.tiff", (16, 8)),
 | 
				
			||||||
 | 
					            ("Tests/images/child_ifd_jpeg.tiff", (20,)),
 | 
				
			||||||
 | 
					        ),
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    def test_get_child_images(self, path, sizes):
 | 
				
			||||||
 | 
					        with Image.open(path) as im:
 | 
				
			||||||
 | 
					            ims = im.get_child_images()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        assert len(ims) == len(sizes)
 | 
				
			||||||
 | 
					        for i, im in enumerate(ims):
 | 
				
			||||||
 | 
					            w = sizes[i]
 | 
				
			||||||
 | 
					            expected = Image.new("RGB", (w, w), "#f00")
 | 
				
			||||||
 | 
					            assert_image_similar(im, expected, 1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_mac_tiff(self):
 | 
					    def test_mac_tiff(self):
 | 
				
			||||||
        # Read RGBa images from macOS [@PIL136]
 | 
					        # Read RGBa images from macOS [@PIL136]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1148,6 +1148,39 @@ class TiffImageFile(ImageFile.ImageFile):
 | 
				
			||||||
        """Return the current frame number"""
 | 
					        """Return the current frame number"""
 | 
				
			||||||
        return self.__frame
 | 
					        return self.__frame
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def get_child_images(self):
 | 
				
			||||||
 | 
					        if SUBIFD not in self.tag_v2:
 | 
				
			||||||
 | 
					            return []
 | 
				
			||||||
 | 
					        child_images = []
 | 
				
			||||||
 | 
					        exif = self.getexif()
 | 
				
			||||||
 | 
					        offset = None
 | 
				
			||||||
 | 
					        for im_offset in self.tag_v2[SUBIFD]:
 | 
				
			||||||
 | 
					            # reset buffered io handle in case fp
 | 
				
			||||||
 | 
					            # was passed to libtiff, invalidating the buffer
 | 
				
			||||||
 | 
					            current_offset = self._fp.tell()
 | 
				
			||||||
 | 
					            if offset is None:
 | 
				
			||||||
 | 
					                offset = current_offset
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            fp = self._fp
 | 
				
			||||||
 | 
					            ifd = exif._get_ifd_dict(im_offset)
 | 
				
			||||||
 | 
					            jpegInterchangeFormat = ifd.get(513)
 | 
				
			||||||
 | 
					            if jpegInterchangeFormat is not None:
 | 
				
			||||||
 | 
					                fp.seek(jpegInterchangeFormat)
 | 
				
			||||||
 | 
					                jpeg_data = fp.read(ifd.get(514))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                fp = io.BytesIO(jpeg_data)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            with Image.open(fp) as im:
 | 
				
			||||||
 | 
					                if jpegInterchangeFormat is None:
 | 
				
			||||||
 | 
					                    im._frame_pos = [im_offset]
 | 
				
			||||||
 | 
					                    im._seek(0)
 | 
				
			||||||
 | 
					                im.load()
 | 
				
			||||||
 | 
					                child_images.append(im)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if offset is not None:
 | 
				
			||||||
 | 
					            self._fp.seek(offset)
 | 
				
			||||||
 | 
					        return child_images
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def getxmp(self):
 | 
					    def getxmp(self):
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        Returns a dictionary containing the XMP tags.
 | 
					        Returns a dictionary containing the XMP tags.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -160,6 +160,7 @@ TAGS_V2 = {
 | 
				
			||||||
    323: ("TileLength", LONG, 1),
 | 
					    323: ("TileLength", LONG, 1),
 | 
				
			||||||
    324: ("TileOffsets", LONG, 0),
 | 
					    324: ("TileOffsets", LONG, 0),
 | 
				
			||||||
    325: ("TileByteCounts", LONG, 0),
 | 
					    325: ("TileByteCounts", LONG, 0),
 | 
				
			||||||
 | 
					    330: ("SubIFDs", LONG, 0),
 | 
				
			||||||
    332: ("InkSet", SHORT, 1),
 | 
					    332: ("InkSet", SHORT, 1),
 | 
				
			||||||
    333: ("InkNames", ASCII, 1),
 | 
					    333: ("InkNames", ASCII, 1),
 | 
				
			||||||
    334: ("NumberOfInks", SHORT, 1),
 | 
					    334: ("NumberOfInks", SHORT, 1),
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user