mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 09:57:43 +03:00 
			
		
		
		
	Merge pull request #7493 from radarhere/frombytes
Fixed frombytes() for images with a zero dimension
This commit is contained in:
		
						commit
						a5a6ca150c
					
				| 
						 | 
				
			
			@ -906,6 +906,13 @@ class TestImage:
 | 
			
		|||
        im = Image.new("RGB", size)
 | 
			
		||||
        assert im.tobytes() == b""
 | 
			
		||||
 | 
			
		||||
    @pytest.mark.parametrize("size", ((1, 0), (0, 1), (0, 0)))
 | 
			
		||||
    def test_zero_frombytes(self, size):
 | 
			
		||||
        Image.frombytes("RGB", size, b"")
 | 
			
		||||
 | 
			
		||||
        im = Image.new("RGB", size)
 | 
			
		||||
        im.frombytes(b"")
 | 
			
		||||
 | 
			
		||||
    def test_has_transparency_data(self):
 | 
			
		||||
        for mode in ("1", "L", "P", "RGB"):
 | 
			
		||||
            im = Image.new(mode, (1, 1))
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -791,6 +791,9 @@ class Image:
 | 
			
		|||
        but loads data into this image instead of creating a new image object.
 | 
			
		||||
        """
 | 
			
		||||
 | 
			
		||||
        if self.width == 0 or self.height == 0:
 | 
			
		||||
            return
 | 
			
		||||
 | 
			
		||||
        # may pass tuple instead of argument list
 | 
			
		||||
        if len(args) == 1 and isinstance(args[0], tuple):
 | 
			
		||||
            args = args[0]
 | 
			
		||||
| 
						 | 
				
			
			@ -2967,6 +2970,8 @@ def frombytes(mode, size, data, decoder_name="raw", *args):
 | 
			
		|||
 | 
			
		||||
    _check_size(size)
 | 
			
		||||
 | 
			
		||||
    im = new(mode, size)
 | 
			
		||||
    if im.width != 0 and im.height != 0:
 | 
			
		||||
        # may pass tuple instead of argument list
 | 
			
		||||
        if len(args) == 1 and isinstance(args[0], tuple):
 | 
			
		||||
            args = args[0]
 | 
			
		||||
| 
						 | 
				
			
			@ -2974,7 +2979,6 @@ def frombytes(mode, size, data, decoder_name="raw", *args):
 | 
			
		|||
        if decoder_name == "raw" and args == ():
 | 
			
		||||
            args = mode
 | 
			
		||||
 | 
			
		||||
    im = new(mode, size)
 | 
			
		||||
        im.frombytes(data, decoder_name, args)
 | 
			
		||||
    return im
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user