Merge pull request #2938 from uploadcare/tiff-with-optional-channels

Tiff with optional channels
This commit is contained in:
wiredfool 2018-01-24 11:10:18 +00:00 committed by GitHub
commit 9a19858fb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 2 deletions

View File

@ -339,6 +339,10 @@ class TestLibUnpack(PillowTestCase):
self.assert_unpack("RGBX", "RGB;4B", 2, (17,0,34,X), (51,0,68,X))
self.assert_unpack("RGBX", "RGBX", 4,
(1,2,3,4), (5,6,7,8), (9,10,11,12))
self.assert_unpack("RGBX", "RGBXX", 5,
(1,2,3,4), (6,7,8,9), (11,12,13,14))
self.assert_unpack("RGBX", "RGBXXX", 6,
(1,2,3,4), (7,8,9,10), (13,14,15,16))
self.assert_unpack("RGBX", "RGBX;L", 4,
(1,4,7,10), (2,5,8,11), (3,6,9,12))
self.assert_unpack("RGBX", "RGBX;16L", 8, (2,4,6,8), (10,12,14,16))
@ -355,7 +359,12 @@ class TestLibUnpack(PillowTestCase):
self.assert_unpack("RGBX", "X", 1, (0,0,0,1), (0,0,0,2), (0,0,0,3))
def test_CMYK(self):
self.assert_unpack("CMYK", "CMYK", 4, (1,2,3,4), (5,6,7,8), (9,10,11,12))
self.assert_unpack("CMYK", "CMYK", 4,
(1,2,3,4), (5,6,7,8), (9,10,11,12))
self.assert_unpack("CMYK", "CMYKX", 5,
(1,2,3,4), (6,7,8,9), (11,12,13,14))
self.assert_unpack("CMYK", "CMYKXX", 6,
(1,2,3,4), (7,8,9,10), (13,14,15,16))
self.assert_unpack("CMYK", "CMYK;I", 4,
(254,253,252,251), (250,249,248,247), (246,245,244,243))
self.assert_unpack("CMYK", "CMYK;L", 4,
@ -376,8 +385,10 @@ class TestLibUnpack(PillowTestCase):
def test_YCbCr(self):
self.assert_unpack("YCbCr", "YCbCr", 3, (1,2,3), (4,5,6), (7,8,9))
self.assert_unpack("YCbCr", "YCbCr;L", 3, (1,4,7), (2,5,8), (3,6,9))
self.assert_unpack("YCbCr", "YCbCrX", 4, (1,2,3), (5,6,7), (9,10,11))
self.assert_unpack("YCbCr", "YCbCrK", 4, (1,2,3), (5,6,7), (9,10,11))
self.assert_unpack("YCbCr", "YCbCrX", 4, (1,2,3), (5,6,7), (9,10,11))
self.assert_unpack("YCbCr", "YCbCrXX", 5, (1,2,3), (6,7,8), (11,12,13))
self.assert_unpack("YCbCr", "YCbCrXXX", 6, (1,2,3), (7,8,9), (13,14,15))
def test_LAB(self):
self.assert_unpack("LAB", "LAB", 3,

View File

@ -194,6 +194,10 @@ OPEN_INFO = {
(MM, 2, (1,), 1, (8, 8, 8, 8), ()): ("RGBA", "RGBA"), # missing ExtraSamples
(II, 2, (1,), 1, (8, 8, 8, 8), (0,)): ("RGBX", "RGBX"),
(MM, 2, (1,), 1, (8, 8, 8, 8), (0,)): ("RGBX", "RGBX"),
(II, 2, (1,), 1, (8, 8, 8, 8, 8), (0, 0)): ("RGBX", "RGBXX"),
(MM, 2, (1,), 1, (8, 8, 8, 8, 8), (0, 0)): ("RGBX", "RGBXX"),
(II, 2, (1,), 1, (8, 8, 8, 8, 8, 8), (0, 0, 0)): ("RGBX", "RGBXXX"),
(MM, 2, (1,), 1, (8, 8, 8, 8, 8, 8), (0, 0, 0)): ("RGBX", "RGBXXX"),
(II, 2, (1,), 1, (8, 8, 8, 8), (1,)): ("RGBA", "RGBa"),
(MM, 2, (1,), 1, (8, 8, 8, 8), (1,)): ("RGBA", "RGBa"),
(II, 2, (1,), 1, (8, 8, 8, 8), (2,)): ("RGBA", "RGBA"),
@ -233,9 +237,19 @@ OPEN_INFO = {
(II, 5, (1,), 1, (8, 8, 8, 8), ()): ("CMYK", "CMYK"),
(MM, 5, (1,), 1, (8, 8, 8, 8), ()): ("CMYK", "CMYK"),
(II, 5, (1,), 1, (8, 8, 8, 8, 8), (0,)): ("CMYK", "CMYKX"),
(MM, 5, (1,), 1, (8, 8, 8, 8, 8), (0,)): ("CMYK", "CMYKX"),
(II, 5, (1,), 1, (8, 8, 8, 8, 8, 8), (0, 0)): ("CMYK", "CMYKXX"),
(MM, 5, (1,), 1, (8, 8, 8, 8, 8, 8), (0, 0)): ("CMYK", "CMYKXX"),
(II, 6, (1,), 1, (8, 8, 8), ()): ("YCbCr", "YCbCr"),
(MM, 6, (1,), 1, (8, 8, 8), ()): ("YCbCr", "YCbCr"),
(II, 6, (1,), 1, (8, 8, 8, 8), (0,)): ("YCbCr", "YCbCrX"),
(MM, 6, (1,), 1, (8, 8, 8, 8), (0,)): ("YCbCr", "YCbCrX"),
(II, 6, (1,), 1, (8, 8, 8, 8, 8), (0, 0)): ("YCbCr", "YCbCrXXX"),
(MM, 6, (1,), 1, (8, 8, 8, 8, 8), (0, 0)): ("YCbCr", "YCbCrXXX"),
(II, 6, (1,), 1, (8, 8, 8, 8, 8, 8), (0, 0, 0)): ("YCbCr", "YCbCrXXX"),
(MM, 6, (1,), 1, (8, 8, 8, 8, 8, 8), (0, 0, 0)): ("YCbCr", "YCbCrXXX"),
(II, 8, (1,), 1, (8, 8, 8), ()): ("LAB", "LAB"),
(MM, 8, (1,), 1, (8, 8, 8), ()): ("LAB", "LAB"),

View File

@ -1041,6 +1041,28 @@ copy4(UINT8* out, const UINT8* in, int pixels)
memcpy(out, in, 4 * pixels);
}
static void
copy4skip1(UINT8* _out, const UINT8* in, int pixels)
{
int i;
UINT32* out = (UINT32*) _out;
for (i = 0; i < pixels; i++) {
out[i] = *(UINT32*)&in[0];
in += 5;
}
}
static void
copy4skip2(UINT8* _out, const UINT8* in, int pixels)
{
int i;
UINT32* out = (UINT32*) _out;
for (i = 0; i < pixels; i++) {
out[i] = *(UINT32*)&in[0];
in += 6;
}
}
/* Unpack to "I" and "F" images */
@ -1330,6 +1352,8 @@ static struct {
{"RGBX", "RGB;4B", 16, ImagingUnpackRGB4B},
{"RGBX", "BGR;5", 16, ImagingUnpackBGR15}, /* compat */
{"RGBX", "RGBX", 32, copy4},
{"RGBX", "RGBXX", 40, copy4skip1},
{"RGBX", "RGBXXX", 48, copy4skip2},
{"RGBX", "RGBX;L", 32, unpackRGBAL},
{"RGBX", "RGBX;16L", 64, unpackRGBA16L},
{"RGBX", "RGBX;16B", 64, unpackRGBA16B},
@ -1344,6 +1368,8 @@ static struct {
/* colour separation */
{"CMYK", "CMYK", 32, copy4},
{"CMYK", "CMYKX", 40, copy4skip1},
{"CMYK", "CMYKXX", 48, copy4skip2},
{"CMYK", "CMYK;I", 32, unpackCMYKI},
{"CMYK", "CMYK;L", 32, unpackRGBAL},
{"CMYK", "C", 8, band0},
@ -1359,6 +1385,8 @@ static struct {
{"YCbCr", "YCbCr", 24, ImagingUnpackRGB},
{"YCbCr", "YCbCr;L", 24, unpackRGBL},
{"YCbCr", "YCbCrX", 32, copy4},
{"YCbCr", "YCbCrXX", 40, copy4skip1},
{"YCbCr", "YCbCrXXX", 48, copy4skip2},
{"YCbCr", "YCbCrK", 32, copy4},
/* LAB Color */