scale values when converting to bgr;15/16

instead of just cutting off the lower three bytes
This commit is contained in:
Yay295 2024-04-11 22:54:59 -05:00
parent de18f55568
commit e1cdd22ded

View File

@ -280,24 +280,30 @@ rgb2f(UINT8 *out_, const UINT8 *in, int xsize) {
}
static void
rgb2bgr15(UINT8 *out_, const UINT8 *in, int xsize) {
rgb2bgr15(UINT8 *out, const UINT8 *in, const int xsize) {
int x;
for (x = 0; x < xsize; x++, in += 4, out_ += 2) {
UINT16 v = ((((UINT16)in[0]) << 7) & 0x7c00) +
((((UINT16)in[1]) << 2) & 0x03e0) +
((((UINT16)in[2]) >> 3) & 0x001f);
memcpy(out_, &v, sizeof(v));
for (x = 0; x < xsize; x++, in += 4, out += 2) {
const UINT16 r = (UINT16)in[0] * 31 / 255;
const UINT16 g = (UINT16)in[1] * 31 / 255;
const UINT16 b = (UINT16)in[2] * 31 / 255;
const UINT16 v = ((b & 31) << 10) +
((g & 31) << 5) +
(r & 31);
memcpy(out, &v, sizeof(v));
}
}
static void
rgb2bgr16(UINT8 *out_, const UINT8 *in, int xsize) {
rgb2bgr16(UINT8 *out, const UINT8 *in, const int xsize) {
int x;
for (x = 0; x < xsize; x++, in += 4, out_ += 2) {
UINT16 v = ((((UINT16)in[0]) << 8) & 0xf800) +
((((UINT16)in[1]) << 3) & 0x07e0) +
((((UINT16)in[2]) >> 3) & 0x001f);
memcpy(out_, &v, sizeof(v));
for (x = 0; x < xsize; x++, in += 4, out += 2) {
const UINT16 r = (UINT16)in[0] * 31 / 255;
const UINT16 g = (UINT16)in[1] * 63 / 255;
const UINT16 b = (UINT16)in[2] * 31 / 255;
const UINT16 v = ((b & 31) << 11) +
((g & 63) << 6) +
(r & 31);
memcpy(out, &v, sizeof(v));
}
}