mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 01:47:47 +03:00 
			
		
		
		
	Merge pull request #8618 from radarhere/px
This commit is contained in:
		
						commit
						17541258c0
					
				| 
						 | 
				
			
			@ -331,11 +331,13 @@ def test_dxt5_colorblock_alpha_issue_4142() -> None:
 | 
			
		|||
 | 
			
		||||
    with Image.open("Tests/images/dxt5-colorblock-alpha-issue-4142.dds") as im:
 | 
			
		||||
        px = im.getpixel((0, 0))
 | 
			
		||||
        assert isinstance(px, tuple)
 | 
			
		||||
        assert px[0] != 0
 | 
			
		||||
        assert px[1] != 0
 | 
			
		||||
        assert px[2] != 0
 | 
			
		||||
 | 
			
		||||
        px = im.getpixel((1, 0))
 | 
			
		||||
        assert isinstance(px, tuple)
 | 
			
		||||
        assert px[0] != 0
 | 
			
		||||
        assert px[1] != 0
 | 
			
		||||
        assert px[2] != 0
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -95,10 +95,14 @@ def test_sanity(filename: str, size: tuple[int, int], scale: int) -> None:
 | 
			
		|||
@pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available")
 | 
			
		||||
def test_load() -> None:
 | 
			
		||||
    with Image.open(FILE1) as im:
 | 
			
		||||
        assert im.load()[0, 0] == (255, 255, 255)
 | 
			
		||||
        px = im.load()
 | 
			
		||||
        assert px is not None
 | 
			
		||||
        assert px[0, 0] == (255, 255, 255)
 | 
			
		||||
 | 
			
		||||
        # Test again now that it has already been loaded once
 | 
			
		||||
        assert im.load()[0, 0] == (255, 255, 255)
 | 
			
		||||
        px = im.load()
 | 
			
		||||
        assert px is not None
 | 
			
		||||
        assert px[0, 0] == (255, 255, 255)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_binary() -> None:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,10 +14,14 @@ def test_gbr_file() -> None:
 | 
			
		|||
 | 
			
		||||
def test_load() -> None:
 | 
			
		||||
    with Image.open("Tests/images/gbr.gbr") as im:
 | 
			
		||||
        px = im.load()
 | 
			
		||||
        assert px is not None
 | 
			
		||||
        assert im.load()[0, 0] == (0, 0, 0, 0)
 | 
			
		||||
 | 
			
		||||
        # Test again now that it has already been loaded once
 | 
			
		||||
        assert im.load()[0, 0] == (0, 0, 0, 0)
 | 
			
		||||
        px = im.load()
 | 
			
		||||
        assert px is not None
 | 
			
		||||
        assert px[0, 0] == (0, 0, 0, 0)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_multiple_load_operations() -> None:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -307,6 +307,7 @@ def test_roundtrip_save_all_1(tmp_path: Path) -> None:
 | 
			
		|||
def test_loading_multiple_palettes(path: str, mode: str) -> None:
 | 
			
		||||
    with Image.open(path) as im:
 | 
			
		||||
        assert im.mode == "P"
 | 
			
		||||
        assert im.palette is not None
 | 
			
		||||
        first_frame_colors = im.palette.colors.keys()
 | 
			
		||||
        original_color = im.convert("RGB").getpixel((0, 0))
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -525,6 +526,7 @@ def test_dispose_background_transparency() -> None:
 | 
			
		|||
    with Image.open("Tests/images/dispose_bgnd_transparency.gif") as img:
 | 
			
		||||
        img.seek(2)
 | 
			
		||||
        px = img.load()
 | 
			
		||||
        assert px is not None
 | 
			
		||||
        assert px[35, 30][3] == 0
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1323,6 +1325,7 @@ def test_palette_save_all_P(tmp_path: Path) -> None:
 | 
			
		|||
    with Image.open(out) as im:
 | 
			
		||||
        # Assert that the frames are correct, and each frame has the same palette
 | 
			
		||||
        assert_image_equal(im.convert("RGB"), frames[0].convert("RGB"))
 | 
			
		||||
        assert im.palette is not None
 | 
			
		||||
        assert im.palette.palette == im.global_palette.palette
 | 
			
		||||
 | 
			
		||||
        im.seek(1)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -32,10 +32,14 @@ def test_sanity() -> None:
 | 
			
		|||
 | 
			
		||||
def test_load() -> None:
 | 
			
		||||
    with Image.open(TEST_FILE) as im:
 | 
			
		||||
        assert im.load()[0, 0] == (0, 0, 0, 0)
 | 
			
		||||
        px = im.load()
 | 
			
		||||
        assert px is not None
 | 
			
		||||
        assert px[0, 0] == (0, 0, 0, 0)
 | 
			
		||||
 | 
			
		||||
        # Test again now that it has already been loaded once
 | 
			
		||||
        assert im.load()[0, 0] == (0, 0, 0, 0)
 | 
			
		||||
        px = im.load()
 | 
			
		||||
        assert px is not None
 | 
			
		||||
        assert px[0, 0] == (0, 0, 0, 0)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_save(tmp_path: Path) -> None:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -24,7 +24,9 @@ def test_sanity() -> None:
 | 
			
		|||
 | 
			
		||||
def test_load() -> None:
 | 
			
		||||
    with Image.open(TEST_ICO_FILE) as im:
 | 
			
		||||
        assert im.load()[0, 0] == (1, 1, 9, 255)
 | 
			
		||||
        px = im.load()
 | 
			
		||||
        assert px is not None
 | 
			
		||||
        assert px[0, 0] == (1, 1, 9, 255)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_mask() -> None:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -63,6 +63,7 @@ def test_sanity() -> None:
 | 
			
		|||
 | 
			
		||||
    with Image.open("Tests/images/test-card-lossless.jp2") as im:
 | 
			
		||||
        px = im.load()
 | 
			
		||||
        assert px is not None
 | 
			
		||||
        assert px[0, 0] == (0, 0, 0)
 | 
			
		||||
        assert im.mode == "RGB"
 | 
			
		||||
        assert im.size == (640, 480)
 | 
			
		||||
| 
						 | 
				
			
			@ -421,6 +422,7 @@ def test_subsampling_decode(name: str) -> None:
 | 
			
		|||
def test_pclr() -> None:
 | 
			
		||||
    with Image.open(f"{EXTRA_DIR}/issue104_jpxstream.jp2") as im:
 | 
			
		||||
        assert im.mode == "P"
 | 
			
		||||
        assert im.palette is not None
 | 
			
		||||
        assert len(im.palette.colors) == 256
 | 
			
		||||
        assert im.palette.colors[(255, 255, 255)] == 0
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -428,6 +430,7 @@ def test_pclr() -> None:
 | 
			
		|||
        f"{EXTRA_DIR}/147af3f1083de4393666b7d99b01b58b_signal_sigsegv_130c531_6155_5136.jp2"
 | 
			
		||||
    ) as im:
 | 
			
		||||
        assert im.mode == "P"
 | 
			
		||||
        assert im.palette is not None
 | 
			
		||||
        assert len(im.palette.colors) == 139
 | 
			
		||||
        assert im.palette.colors[(0, 0, 0, 0)] == 0
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -79,6 +79,7 @@ def test_arbitrary_maxval(
 | 
			
		|||
        assert im.mode == mode
 | 
			
		||||
 | 
			
		||||
        px = im.load()
 | 
			
		||||
        assert px is not None
 | 
			
		||||
        assert tuple(px[x, 0] for x in range(3)) == pixels
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -72,6 +72,7 @@ def test_palette_depth_8(tmp_path: Path) -> None:
 | 
			
		|||
 | 
			
		||||
def test_palette_depth_16(tmp_path: Path) -> None:
 | 
			
		||||
    with Image.open("Tests/images/p_16.tga") as im:
 | 
			
		||||
        assert im.palette is not None
 | 
			
		||||
        assert im.palette.mode == "RGBA"
 | 
			
		||||
        assert_image_equal_tofile(im.convert("RGBA"), "Tests/images/p_16.png")
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -213,10 +214,14 @@ def test_save_orientation(tmp_path: Path) -> None:
 | 
			
		|||
def test_horizontal_orientations() -> None:
 | 
			
		||||
    # These images have been manually hexedited to have the relevant orientations
 | 
			
		||||
    with Image.open("Tests/images/rgb32rle_top_right.tga") as im:
 | 
			
		||||
        assert im.load()[90, 90][:3] == (0, 0, 0)
 | 
			
		||||
        px = im.load()
 | 
			
		||||
        assert px is not None
 | 
			
		||||
        assert px[90, 90][:3] == (0, 0, 0)
 | 
			
		||||
 | 
			
		||||
    with Image.open("Tests/images/rgb32rle_bottom_right.tga") as im:
 | 
			
		||||
        assert im.load()[90, 90][:3] == (0, 255, 0)
 | 
			
		||||
        px = im.load()
 | 
			
		||||
        assert px is not None
 | 
			
		||||
        assert px[90, 90][:3] == (0, 255, 0)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_save_rle(tmp_path: Path) -> None:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -21,7 +21,11 @@ def test_open() -> None:
 | 
			
		|||
 | 
			
		||||
def test_load() -> None:
 | 
			
		||||
    with WalImageFile.open(TEST_FILE) as im:
 | 
			
		||||
        assert im.load()[0, 0] == 122
 | 
			
		||||
        px = im.load()
 | 
			
		||||
        assert px is not None
 | 
			
		||||
        assert px[0, 0] == 122
 | 
			
		||||
 | 
			
		||||
        # Test again now that it has already been loaded once
 | 
			
		||||
        assert im.load()[0, 0] == 122
 | 
			
		||||
        px = im.load()
 | 
			
		||||
        assert px is not None
 | 
			
		||||
        assert px[0, 0] == 122
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -32,7 +32,9 @@ def test_load_raw() -> None:
 | 
			
		|||
def test_load() -> None:
 | 
			
		||||
    with Image.open("Tests/images/drawing.emf") as im:
 | 
			
		||||
        if hasattr(Image.core, "drawwmf"):
 | 
			
		||||
            assert im.load()[0, 0] == (255, 255, 255)
 | 
			
		||||
            px = im.load()
 | 
			
		||||
            assert px is not None
 | 
			
		||||
            assert px[0, 0] == (255, 255, 255)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_load_zero_inch() -> None:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -658,6 +658,7 @@ class TestImage:
 | 
			
		|||
        im.putpalette(list(range(256)) * 4, "RGBA")
 | 
			
		||||
        im_remapped = im.remap_palette(list(range(256)))
 | 
			
		||||
        assert_image_equal(im, im_remapped)
 | 
			
		||||
        assert im.palette is not None
 | 
			
		||||
        assert im.palette.palette == im_remapped.palette.palette
 | 
			
		||||
 | 
			
		||||
        # Test illegal image mode
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -234,6 +234,7 @@ def test_gif_with_rgba_palette_to_p() -> None:
 | 
			
		|||
    with Image.open("Tests/images/hopper.gif") as im:
 | 
			
		||||
        im.info["transparency"] = 255
 | 
			
		||||
        im.load()
 | 
			
		||||
        assert im.palette is not None
 | 
			
		||||
        assert im.palette.mode == "RGB"
 | 
			
		||||
        im_p = im.convert("P")
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -47,6 +47,7 @@ class TestImageTransform:
 | 
			
		|||
            transformed = im.transform(
 | 
			
		||||
                im.size, Image.Transform.AFFINE, [1, 0, 0, 0, 1, 0]
 | 
			
		||||
            )
 | 
			
		||||
            assert im.palette is not None
 | 
			
		||||
            assert im.palette.palette == transformed.palette.palette
 | 
			
		||||
 | 
			
		||||
    def test_extent(self) -> None:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,6 +17,7 @@ def test_sanity() -> None:
 | 
			
		|||
def test_reload() -> None:
 | 
			
		||||
    with Image.open("Tests/images/hopper.gif") as im:
 | 
			
		||||
        original = im.copy()
 | 
			
		||||
        assert im.palette is not None
 | 
			
		||||
        im.palette.dirty = 1
 | 
			
		||||
        assert_image_equal(im.convert("RGB"), original.convert("RGB"))
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user