Currently when getting a BGR;15/16 pixel value, the result is scaled from 0-31 to 0-255.
|
static void |
|
get_pixel_BGR15(Imaging im, int x, int y, void *color) { |
|
UINT8 *in = (UINT8 *)&im->image8[y][x * 2]; |
|
UINT16 pixel = in[0] + (in[1] << 8); |
|
char *out = color; |
|
out[0] = (pixel & 31) * 255 / 31; |
|
out[1] = ((pixel >> 5) & 31) * 255 / 31; |
|
out[2] = ((pixel >> 10) & 31) * 255 / 31; |
|
} |
|
|
|
static void |
|
get_pixel_BGR16(Imaging im, int x, int y, void *color) { |
|
UINT8 *in = (UINT8 *)&im->image8[y][x * 2]; |
|
UINT16 pixel = in[0] + (in[1] << 8); |
|
char *out = color; |
|
out[0] = (pixel & 31) * 255 / 31; |
|
out[1] = ((pixel >> 5) & 63) * 255 / 63; |
|
out[2] = ((pixel >> 11) & 31) * 255 / 31; |
|
} |
Storing one of these pixels is also scaled, though using a different algorithm.
|
if (!strcmp(im->mode, "BGR;15")) { |
|
UINT16 v = ((((UINT16)r) << 7) & 0x7c00) + |
|
((((UINT16)g) << 2) & 0x03e0) + |
|
((((UINT16)b) >> 3) & 0x001f); |
|
|
|
ink[0] = (UINT8)v; |
|
ink[1] = (UINT8)(v >> 8); |
|
ink[2] = ink[3] = 0; |
|
return ink; |
|
} else if (!strcmp(im->mode, "BGR;16")) { |
|
UINT16 v = ((((UINT16)r) << 8) & 0xf800) + |
|
((((UINT16)g) << 3) & 0x07e0) + |
|
((((UINT16)b) >> 3) & 0x001f); |
|
ink[0] = (UINT8)v; |
|
ink[1] = (UINT8)(v >> 8); |
|
ink[2] = ink[3] = 0; |
|
return ink; |
Should scaling be done at all for these modes when getting/setting pixels? Also, the pixel order is backwards. It seems that these functions are actually converting to/from RGB rather than just returning the BGR;15/16 values.
Currently when getting a BGR;15/16 pixel value, the result is scaled from 0-31 to 0-255.
Pillow/src/libImaging/Access.c
Lines 90 to 108 in de18f55
Storing one of these pixels is also scaled, though using a different algorithm.
Pillow/src/_imaging.c
Lines 607 to 623 in de18f55
Should scaling be done at all for these modes when getting/setting pixels? Also, the pixel order is backwards. It seems that these functions are actually converting to/from RGB rather than just returning the BGR;15/16 values.