Merge pull request #3335 from uploadcare/more-tiff-modes

Add more raw Tiff modes (RGBaX, RGBaXX, RGBAX, RGBAXX)
This commit is contained in:
Andrew Murray 2018-09-10 19:42:09 +10:00 committed by GitHub
commit dd2698f00e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 70 additions and 4 deletions

View File

@ -309,13 +309,25 @@ class TestLibUnpack(PillowTestCase):
"RGBA", "LA;16B", 4, (1, 1, 1, 3), (5, 5, 5, 7), (9, 9, 9, 11))
self.assert_unpack(
"RGBA", "RGBA", 4, (1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12))
self.assert_unpack(
"RGBA", "RGBAX", 5, (1, 2, 3, 4), (6, 7, 8, 9), (11, 12, 13, 14))
self.assert_unpack(
"RGBA", "RGBAXX", 6, (1, 2, 3, 4), (7, 8, 9, 10), (13, 14, 15, 16))
self.assert_unpack(
"RGBA", "RGBa", 4,
(63, 127, 191, 4), (159, 191, 223, 8), (191, 212, 233, 12))
self.assert_unpack(
"RGBA", "RGBa",
b'\x01\x02\x03\x00\x10\x20\x30\xff',
(0, 0, 0, 0), (16, 32, 48, 255))
b'\x01\x02\x03\x00\x10\x20\x30\x7f\x10\x20\x30\xff',
(0, 0, 0, 0), (32, 64, 96, 127), (16, 32, 48, 255))
self.assert_unpack(
"RGBA", "RGBaX",
b'\x01\x02\x03\x00-\x10\x20\x30\x7f-\x10\x20\x30\xff-',
(0, 0, 0, 0), (32, 64, 96, 127), (16, 32, 48, 255))
self.assert_unpack(
"RGBA", "RGBaXX",
b'\x01\x02\x03\x00==\x10\x20\x30\x7f!!\x10\x20\x30\xff??',
(0, 0, 0, 0), (32, 64, 96, 127), (16, 32, 48, 255))
self.assert_unpack(
"RGBA", "RGBa;16L", 8,
(63, 127, 191, 8), (159, 191, 223, 16), (191, 212, 233, 24))

View File

@ -207,8 +207,16 @@ OPEN_INFO = {
(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, 8), (1, 0)): ("RGBA", "RGBaX"),
(MM, 2, (1,), 1, (8, 8, 8, 8, 8), (1, 0)): ("RGBA", "RGBaX"),
(II, 2, (1,), 1, (8, 8, 8, 8, 8, 8), (1, 0, 0)): ("RGBA", "RGBaXX"),
(MM, 2, (1,), 1, (8, 8, 8, 8, 8, 8), (1, 0, 0)): ("RGBA", "RGBaXX"),
(II, 2, (1,), 1, (8, 8, 8, 8), (2,)): ("RGBA", "RGBA"),
(MM, 2, (1,), 1, (8, 8, 8, 8), (2,)): ("RGBA", "RGBA"),
(II, 2, (1,), 1, (8, 8, 8, 8, 8), (2, 0)): ("RGBA", "RGBAX"),
(MM, 2, (1,), 1, (8, 8, 8, 8, 8), (2, 0)): ("RGBA", "RGBAX"),
(II, 2, (1,), 1, (8, 8, 8, 8, 8, 8), (2, 0, 0)): ("RGBA", "RGBAXX"),
(MM, 2, (1,), 1, (8, 8, 8, 8, 8, 8), (2, 0, 0)): ("RGBA", "RGBAXX"),
(II, 2, (1,), 1, (8, 8, 8, 8), (999,)): ("RGBA", "RGBA"), # Corel Draw 10
(MM, 2, (1,), 1, (8, 8, 8, 8), (999,)): ("RGBA", "RGBA"), # Corel Draw 10
@ -253,8 +261,8 @@ OPEN_INFO = {
(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), (0, 0)): ("YCbCr", "YCbCrXX"),
(MM, 6, (1,), 1, (8, 8, 8, 8, 8), (0, 0)): ("YCbCr", "YCbCrXX"),
(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"),

View File

@ -797,6 +797,48 @@ unpackRGBa(UINT8* _out, const UINT8* in, int pixels)
}
}
static void
unpackRGBaskip1(UINT8* _out, const UINT8* in, int pixels)
{
int i;
UINT32* out = (UINT32*) _out;
/* premultiplied RGBA */
for (i = 0; i < pixels; i++) {
int a = in[3];
if ( ! a) {
out[i] = 0;
} else if (a == 255) {
out[i] = MAKE_UINT32(in[0], in[1], in[2], a);
} else {
out[i] = MAKE_UINT32(CLIP8(in[0] * 255 / a),
CLIP8(in[1] * 255 / a),
CLIP8(in[2] * 255 / a), a);
}
in += 5;
}
}
static void
unpackRGBaskip2(UINT8* _out, const UINT8* in, int pixels)
{
int i;
UINT32* out = (UINT32*) _out;
/* premultiplied RGBA */
for (i = 0; i < pixels; i++) {
int a = in[3];
if ( ! a) {
out[i] = 0;
} else if (a == 255) {
out[i] = MAKE_UINT32(in[0], in[1], in[2], a);
} else {
out[i] = MAKE_UINT32(CLIP8(in[0] * 255 / a),
CLIP8(in[1] * 255 / a),
CLIP8(in[2] * 255 / a), a);
}
in += 6;
}
}
static void
unpackBGRa(UINT8* _out, const UINT8* in, int pixels)
{
@ -1301,7 +1343,11 @@ static struct {
{"RGBA", "LA", 16, unpackRGBALA},
{"RGBA", "LA;16B", 32, unpackRGBALA16B},
{"RGBA", "RGBA", 32, copy4},
{"RGBA", "RGBAX", 40, copy4skip1},
{"RGBA", "RGBAXX", 48, copy4skip2},
{"RGBA", "RGBa", 32, unpackRGBa},
{"RGBA", "RGBaX", 40, unpackRGBaskip1},
{"RGBA", "RGBaXX", 48, unpackRGBaskip2},
{"RGBA", "RGBa;16L", 64, unpackRGBa16L},
{"RGBA", "RGBa;16B", 64, unpackRGBa16B},
{"RGBA", "BGRa", 32, unpackBGRa},