Add support for DXT3 to DdsImagePlugin

This commit is contained in:
Robert Nix 2016-08-25 20:12:44 -05:00
parent 18a91cebcf
commit b46804ea27
5 changed files with 17 additions and 5 deletions

View File

@ -122,6 +122,9 @@ class DdsImageFile(ImageFile.ImageFile):
if fourcc == b"DXT1":
self.pixel_format = "DXT1"
n = 1
elif fourcc == b"DXT3":
self.pixel_format = "DXT3"
n = 2
elif fourcc == b"DXT5":
self.pixel_format = "DXT5"
n = 3

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

View File

@ -36,12 +36,21 @@ class TestFileDds(PillowTestCase):
self.assertEqual(im.mode, "RGBA")
self.assertEqual(im.size, (256, 256))
self.assert_image_equal(target, im, 5)
self.assert_image_equal(target, im)
def test_sanity_dxt3(self):
"""Check DXT3 images are not supported"""
self.assertRaises(NotImplementedError,
lambda: Image.open(TEST_FILE_DXT3))
"""Check DXT3 images can be opened"""
target = Image.open(TEST_FILE_DXT3.replace('.dds', '.png'))
im = Image.open(TEST_FILE_DXT3)
im.load()
self.assertEqual(im.format, "DDS")
self.assertEqual(im.mode, "RGBA")
self.assertEqual(im.size, (256, 256))
self.assert_image_equal(target, im)
def test__validate_true(self):
"""Check valid prefix"""

View File

@ -153,7 +153,7 @@ static void decode_bc1_block(rgba *col, const UINT8* src) {
static void decode_bc2_block(rgba *col, const UINT8* src) {
int n, bitI, byI, av;
decode_bc1_color(col, src);
decode_bc1_color(col, src + 8);
for (n = 0; n < 16; n++) {
bitI = n * 4;
byI = bitI >> 3;