mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 01:47:47 +03:00 
			
		
		
		
	Remove transparency if it cannot be remapped
This commit is contained in:
		
							parent
							
								
									46a80d144a
								
							
						
					
					
						commit
						99f4623a8d
					
				| 
						 | 
					@ -607,6 +607,20 @@ class TestImage:
 | 
				
			||||||
            with pytest.raises(ValueError):
 | 
					            with pytest.raises(ValueError):
 | 
				
			||||||
                im.remap_palette(None)
 | 
					                im.remap_palette(None)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_remap_palette_transparency(self):
 | 
				
			||||||
 | 
					        im = Image.new("P", (1, 2))
 | 
				
			||||||
 | 
					        im.putpixel((0, 1), 1)
 | 
				
			||||||
 | 
					        im.info["transparency"] = 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        im_remapped = im.remap_palette([1, 0])
 | 
				
			||||||
 | 
					        assert im_remapped.info["transparency"] == 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # Test unused transparency
 | 
				
			||||||
 | 
					        im.info["transparency"] = 2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        im_remapped = im.remap_palette([1, 0])
 | 
				
			||||||
 | 
					        assert "transparency" not in im_remapped.info
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test__new(self):
 | 
					    def test__new(self):
 | 
				
			||||||
        im = hopper("RGB")
 | 
					        im = hopper("RGB")
 | 
				
			||||||
        im_p = hopper("P")
 | 
					        im_p = hopper("P")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1935,7 +1935,11 @@ class Image:
 | 
				
			||||||
        m_im.palette = ImagePalette.ImagePalette("RGB", palette=palette_bytes)
 | 
					        m_im.palette = ImagePalette.ImagePalette("RGB", palette=palette_bytes)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if "transparency" in self.info:
 | 
					        if "transparency" in self.info:
 | 
				
			||||||
            m_im.info["transparency"] = new_positions[self.info["transparency"]]
 | 
					            try:
 | 
				
			||||||
 | 
					                m_im.info["transparency"] = dest_map.index(self.info["transparency"])
 | 
				
			||||||
 | 
					            except ValueError:
 | 
				
			||||||
 | 
					                if "transparency" in m_im.info:
 | 
				
			||||||
 | 
					                    del m_im.info["transparency"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return m_im
 | 
					        return m_im
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user