Skip to content

Commit c5eb7c7

Browse files
authored
Merge pull request #7918 from radarhere/convert
2 parents 0b1d0c2 + fb6b860 commit c5eb7c7

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

Tests/helper.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,6 @@ def hopper(mode: str | None = None, cache: dict[str, Image.Image] = {}) -> Image
263263
if im is None:
264264
if mode == "F":
265265
im = hopper("L").convert(mode)
266-
elif mode[:4] == "I;16":
267-
im = hopper("I").convert(mode)
268266
else:
269267
im = hopper().convert(mode)
270268
cache[mode] = im

src/libImaging/Convert.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,26 @@ rgb2i(UINT8 *out_, const UINT8 *in, int xsize) {
250250
}
251251
}
252252

253+
static void
254+
rgb2i16l(UINT8 *out_, const UINT8 *in, int xsize) {
255+
int x;
256+
for (x = 0; x < xsize; x++, in += 4) {
257+
UINT8 v = CLIP16(L24(in) >> 16);
258+
*out_++ = v;
259+
*out_++ = v >> 8;
260+
}
261+
}
262+
263+
static void
264+
rgb2i16b(UINT8 *out_, const UINT8 *in, int xsize) {
265+
int x;
266+
for (x = 0; x < xsize; x++, in += 4) {
267+
UINT8 v = CLIP16(L24(in) >> 16);
268+
*out_++ = v >> 8;
269+
*out_++ = v;
270+
}
271+
}
272+
253273
static void
254274
rgb2f(UINT8 *out_, const UINT8 *in, int xsize) {
255275
int x;
@@ -944,6 +964,9 @@ static struct {
944964
{"RGB", "LA", rgb2la},
945965
{"RGB", "La", rgb2la},
946966
{"RGB", "I", rgb2i},
967+
{"RGB", "I;16", rgb2i16l},
968+
{"RGB", "I;16L", rgb2i16l},
969+
{"RGB", "I;16B", rgb2i16b},
947970
{"RGB", "F", rgb2f},
948971
{"RGB", "BGR;15", rgb2bgr15},
949972
{"RGB", "BGR;16", rgb2bgr16},

0 commit comments

Comments
 (0)