mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 01:47:47 +03:00 
			
		
		
		
	Merge pull request #8762 from radarhere/sun
This commit is contained in:
		
						commit
						1126733edf
					
				| 
						 | 
				
			
			@ -1,10 +1,11 @@
 | 
			
		|||
from __future__ import annotations
 | 
			
		||||
 | 
			
		||||
import io
 | 
			
		||||
import os
 | 
			
		||||
 | 
			
		||||
import pytest
 | 
			
		||||
 | 
			
		||||
from PIL import Image, SunImagePlugin
 | 
			
		||||
from PIL import Image, SunImagePlugin, _binary
 | 
			
		||||
 | 
			
		||||
from .helper import assert_image_equal_tofile, assert_image_similar, hopper
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -33,6 +34,60 @@ def test_im1() -> None:
 | 
			
		|||
        assert_image_equal_tofile(im, "Tests/images/sunraster.im1.png")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def _sun_header(
 | 
			
		||||
    depth: int = 0, file_type: int = 0, palette_length: int = 0
 | 
			
		||||
) -> io.BytesIO:
 | 
			
		||||
    return io.BytesIO(
 | 
			
		||||
        _binary.o32be(0x59A66A95)
 | 
			
		||||
        + b"\x00" * 8
 | 
			
		||||
        + _binary.o32be(depth)
 | 
			
		||||
        + b"\x00" * 4
 | 
			
		||||
        + _binary.o32be(file_type)
 | 
			
		||||
        + b"\x00" * 4
 | 
			
		||||
        + _binary.o32be(palette_length)
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_unsupported_mode_bit_depth() -> None:
 | 
			
		||||
    with pytest.raises(SyntaxError, match="Unsupported Mode/Bit Depth"):
 | 
			
		||||
        with SunImagePlugin.SunImageFile(_sun_header()):
 | 
			
		||||
            pass
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_unsupported_color_palette_length() -> None:
 | 
			
		||||
    with pytest.raises(SyntaxError, match="Unsupported Color Palette Length"):
 | 
			
		||||
        with SunImagePlugin.SunImageFile(_sun_header(depth=1, palette_length=1025)):
 | 
			
		||||
            pass
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_unsupported_palette_type() -> None:
 | 
			
		||||
    with pytest.raises(SyntaxError, match="Unsupported Palette Type"):
 | 
			
		||||
        with SunImagePlugin.SunImageFile(_sun_header(depth=1, palette_length=1)):
 | 
			
		||||
            pass
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_unsupported_file_type() -> None:
 | 
			
		||||
    with pytest.raises(SyntaxError, match="Unsupported Sun Raster file type"):
 | 
			
		||||
        with SunImagePlugin.SunImageFile(_sun_header(depth=1, file_type=6)):
 | 
			
		||||
            pass
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@pytest.mark.skipif(
 | 
			
		||||
    not os.path.exists(EXTRA_DIR), reason="Extra image files not installed"
 | 
			
		||||
)
 | 
			
		||||
def test_rgbx() -> None:
 | 
			
		||||
    with open(os.path.join(EXTRA_DIR, "32bpp.ras"), "rb") as fp:
 | 
			
		||||
        data = fp.read()
 | 
			
		||||
 | 
			
		||||
    # Set file type to 3
 | 
			
		||||
    data = data[:20] + _binary.o32be(3) + data[24:]
 | 
			
		||||
 | 
			
		||||
    with Image.open(io.BytesIO(data)) as im:
 | 
			
		||||
        r, g, b = im.split()
 | 
			
		||||
        im = Image.merge("RGB", (b, g, r))
 | 
			
		||||
        assert_image_equal_tofile(im, os.path.join(EXTRA_DIR, "32bpp.png"))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@pytest.mark.skipif(
 | 
			
		||||
    not os.path.exists(EXTRA_DIR), reason="Extra image files not installed"
 | 
			
		||||
)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user