Skip to content

Commit

Permalink
Merge pull request #7918 from radarhere/convert
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Mar 30, 2024
2 parents 0b1d0c2 + fb6b860 commit c5eb7c7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
2 changes: 0 additions & 2 deletions Tests/helper.py
Expand Up @@ -263,8 +263,6 @@ def hopper(mode: str | None = None, cache: dict[str, Image.Image] = {}) -> Image
if im is None:
if mode == "F":
im = hopper("L").convert(mode)
elif mode[:4] == "I;16":
im = hopper("I").convert(mode)
else:
im = hopper().convert(mode)
cache[mode] = im
Expand Down
23 changes: 23 additions & 0 deletions src/libImaging/Convert.c
Expand Up @@ -250,6 +250,26 @@ rgb2i(UINT8 *out_, const UINT8 *in, int xsize) {
}
}

static void
rgb2i16l(UINT8 *out_, const UINT8 *in, int xsize) {
int x;
for (x = 0; x < xsize; x++, in += 4) {
UINT8 v = CLIP16(L24(in) >> 16);
*out_++ = v;
*out_++ = v >> 8;
}
}

static void
rgb2i16b(UINT8 *out_, const UINT8 *in, int xsize) {
int x;
for (x = 0; x < xsize; x++, in += 4) {
UINT8 v = CLIP16(L24(in) >> 16);
*out_++ = v >> 8;
*out_++ = v;
}
}

static void
rgb2f(UINT8 *out_, const UINT8 *in, int xsize) {
int x;
Expand Down Expand Up @@ -944,6 +964,9 @@ static struct {
{"RGB", "LA", rgb2la},
{"RGB", "La", rgb2la},
{"RGB", "I", rgb2i},
{"RGB", "I;16", rgb2i16l},
{"RGB", "I;16L", rgb2i16l},
{"RGB", "I;16B", rgb2i16b},
{"RGB", "F", rgb2f},
{"RGB", "BGR;15", rgb2bgr15},
{"RGB", "BGR;16", rgb2bgr16},
Expand Down

0 comments on commit c5eb7c7

Please sign in to comment.