mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 01:47:47 +03:00 
			
		
		
		
	Reset handle when seeking backwards as well
This commit is contained in:
		
							parent
							
								
									ef9a8e5f7f
								
							
						
					
					
						commit
						fd299e36ce
					
				| 
						 | 
					@ -578,6 +578,17 @@ class TestFileLibTiff(LibTiffTestCase):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        TiffImagePlugin.READ_LIBTIFF = False
 | 
					        TiffImagePlugin.READ_LIBTIFF = False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_multipage_seek_backwards(self):
 | 
				
			||||||
 | 
					        TiffImagePlugin.READ_LIBTIFF = True
 | 
				
			||||||
 | 
					        with Image.open("Tests/images/multipage.tiff") as im:
 | 
				
			||||||
 | 
					            im.seek(1)
 | 
				
			||||||
 | 
					            im.load()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            im.seek(0)
 | 
				
			||||||
 | 
					            assert im.convert("RGB").getpixel((0, 0)) == (0, 128, 0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        TiffImagePlugin.READ_LIBTIFF = False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test__next(self):
 | 
					    def test__next(self):
 | 
				
			||||||
        TiffImagePlugin.READ_LIBTIFF = True
 | 
					        TiffImagePlugin.READ_LIBTIFF = True
 | 
				
			||||||
        with Image.open("Tests/images/hopper.tif") as im:
 | 
					        with Image.open("Tests/images/hopper.tif") as im:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1052,6 +1052,11 @@ class TiffImageFile(ImageFile.ImageFile):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _seek(self, frame):
 | 
					    def _seek(self, frame):
 | 
				
			||||||
        self.fp = self.__fp
 | 
					        self.fp = self.__fp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # reset buffered io handle in case fp
 | 
				
			||||||
 | 
					        # was passed to libtiff, invalidating the buffer
 | 
				
			||||||
 | 
					        self.fp.tell()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        while len(self._frame_pos) <= frame:
 | 
					        while len(self._frame_pos) <= frame:
 | 
				
			||||||
            if not self.__next:
 | 
					            if not self.__next:
 | 
				
			||||||
                raise EOFError("no more images in TIFF file")
 | 
					                raise EOFError("no more images in TIFF file")
 | 
				
			||||||
| 
						 | 
					@ -1059,9 +1064,6 @@ class TiffImageFile(ImageFile.ImageFile):
 | 
				
			||||||
                f"Seeking to frame {frame}, on frame {self.__frame}, "
 | 
					                f"Seeking to frame {frame}, on frame {self.__frame}, "
 | 
				
			||||||
                f"__next {self.__next}, location: {self.fp.tell()}"
 | 
					                f"__next {self.__next}, location: {self.fp.tell()}"
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
            # reset buffered io handle in case fp
 | 
					 | 
				
			||||||
            # was passed to libtiff, invalidating the buffer
 | 
					 | 
				
			||||||
            self.fp.tell()
 | 
					 | 
				
			||||||
            self.fp.seek(self.__next)
 | 
					            self.fp.seek(self.__next)
 | 
				
			||||||
            self._frame_pos.append(self.__next)
 | 
					            self._frame_pos.append(self.__next)
 | 
				
			||||||
            logger.debug("Loading tags, location: %s" % self.fp.tell())
 | 
					            logger.debug("Loading tags, location: %s" % self.fp.tell())
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user