mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-05-29 02:03:25 +03:00
support raw rgba8888 for dds
This commit is contained in:
parent
b9f1add34b
commit
b5c59878da
BIN
Tests/images/DXGI_FORMAT_R8G8B8A8_UNORM_SRGB.dds
Normal file
BIN
Tests/images/DXGI_FORMAT_R8G8B8A8_UNORM_SRGB.dds
Normal file
Binary file not shown.
BIN
Tests/images/DXGI_FORMAT_R8G8B8A8_UNORM_SRGB.png
Normal file
BIN
Tests/images/DXGI_FORMAT_R8G8B8A8_UNORM_SRGB.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 106 B |
BIN
Tests/images/argb-32bpp_MipMaps-1.dds
Normal file
BIN
Tests/images/argb-32bpp_MipMaps-1.dds
Normal file
Binary file not shown.
BIN
Tests/images/argb-32bpp_MipMaps-1.png
Normal file
BIN
Tests/images/argb-32bpp_MipMaps-1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 122 KiB |
|
@ -11,6 +11,8 @@ TEST_FILE_DXT3 = "Tests/images/dxt3-argb-8bbp-explicitalpha_MipMaps-1.dds"
|
||||||
TEST_FILE_DXT5 = "Tests/images/dxt5-argb-8bbp-interpolatedalpha_MipMaps-1.dds"
|
TEST_FILE_DXT5 = "Tests/images/dxt5-argb-8bbp-interpolatedalpha_MipMaps-1.dds"
|
||||||
TEST_FILE_DX10_BC7 = "Tests/images/bc7-argb-8bpp_MipMaps-1.dds"
|
TEST_FILE_DX10_BC7 = "Tests/images/bc7-argb-8bpp_MipMaps-1.dds"
|
||||||
TEST_FILE_DX10_BC7_UNORM_SRGB = "Tests/images/DXGI_FORMAT_BC7_UNORM_SRGB.dds"
|
TEST_FILE_DX10_BC7_UNORM_SRGB = "Tests/images/DXGI_FORMAT_BC7_UNORM_SRGB.dds"
|
||||||
|
TEST_FILE_DX10_R8G8B8A8 = "Tests/images/argb-32bpp_MipMaps-1.dds"
|
||||||
|
TEST_FILE_DX10_R8G8B8A8_UNORM_SRGB = "Tests/images/DXGI_FORMAT_R8G8B8A8_UNORM_SRGB.dds"
|
||||||
TEST_FILE_UNCOMPRESSED_RGB = "Tests/images/uncompressed_rgb.dds"
|
TEST_FILE_UNCOMPRESSED_RGB = "Tests/images/uncompressed_rgb.dds"
|
||||||
|
|
||||||
|
|
||||||
|
@ -87,6 +89,37 @@ def test_dx10_bc7_unorm_srgb():
|
||||||
assert_image_equal(target, im)
|
assert_image_equal(target, im)
|
||||||
|
|
||||||
|
|
||||||
|
def test_dx10_r8g8b8a8():
|
||||||
|
"""Check DX10 images can be opened"""
|
||||||
|
|
||||||
|
with Image.open(TEST_FILE_DX10_R8G8B8A8) as im:
|
||||||
|
im.load()
|
||||||
|
|
||||||
|
assert im.format == "DDS"
|
||||||
|
assert im.mode == "RGBA"
|
||||||
|
assert im.size == (256, 256)
|
||||||
|
|
||||||
|
with Image.open(TEST_FILE_DX10_R8G8B8A8.replace(".dds", ".png")) as target:
|
||||||
|
assert_image_equal(target, im)
|
||||||
|
|
||||||
|
|
||||||
|
def test_dx10_r8g8b8a8_unorm_srgb():
|
||||||
|
"""Check DX10 unsigned normalized integer images can be opened"""
|
||||||
|
|
||||||
|
with Image.open(TEST_FILE_DX10_R8G8B8A8_UNORM_SRGB) as im:
|
||||||
|
im.load()
|
||||||
|
|
||||||
|
assert im.format == "DDS"
|
||||||
|
assert im.mode == "RGBA"
|
||||||
|
assert im.size == (16, 16)
|
||||||
|
assert im.info["gamma"] == 1 / 2.2
|
||||||
|
|
||||||
|
with Image.open(
|
||||||
|
TEST_FILE_DX10_R8G8B8A8_UNORM_SRGB.replace(".dds", ".png")
|
||||||
|
) as target:
|
||||||
|
assert_image_equal(target, im)
|
||||||
|
|
||||||
|
|
||||||
def test_unimplemented_dxgi_format():
|
def test_unimplemented_dxgi_format():
|
||||||
with pytest.raises(NotImplementedError):
|
with pytest.raises(NotImplementedError):
|
||||||
Image.open("Tests/images/unimplemented_dxgi_format.dds")
|
Image.open("Tests/images/unimplemented_dxgi_format.dds")
|
||||||
|
|
|
@ -94,6 +94,9 @@ DXT5_FOURCC = 0x35545844
|
||||||
|
|
||||||
# dxgiformat.h
|
# dxgiformat.h
|
||||||
|
|
||||||
|
DXGI_FORMAT_R8G8B8A8_TYPELESS = 27
|
||||||
|
DXGI_FORMAT_R8G8B8A8_UNORM = 28
|
||||||
|
DXGI_FORMAT_R8G8B8A8_UNORM_SRGB = 29
|
||||||
DXGI_FORMAT_BC7_TYPELESS = 97
|
DXGI_FORMAT_BC7_TYPELESS = 97
|
||||||
DXGI_FORMAT_BC7_UNORM = 98
|
DXGI_FORMAT_BC7_UNORM = 98
|
||||||
DXGI_FORMAT_BC7_UNORM_SRGB = 99
|
DXGI_FORMAT_BC7_UNORM_SRGB = 99
|
||||||
|
@ -157,6 +160,15 @@ class DdsImageFile(ImageFile.ImageFile):
|
||||||
self.pixel_format = "BC7"
|
self.pixel_format = "BC7"
|
||||||
self.info["gamma"] = 1 / 2.2
|
self.info["gamma"] = 1 / 2.2
|
||||||
n = 7
|
n = 7
|
||||||
|
elif dxgi_format in (
|
||||||
|
DXGI_FORMAT_R8G8B8A8_TYPELESS,
|
||||||
|
DXGI_FORMAT_R8G8B8A8_UNORM,
|
||||||
|
DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
|
||||||
|
):
|
||||||
|
self.tile = [("raw", (0, 0) + self.size, 0, ("RGBA", 0, 1))]
|
||||||
|
if dxgi_format == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
|
||||||
|
self.info["gamma"] = 1 / 2.2
|
||||||
|
return
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError(
|
raise NotImplementedError(
|
||||||
"Unimplemented DXGI format %d" % (dxgi_format)
|
"Unimplemented DXGI format %d" % (dxgi_format)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user