Use MAKE_UINT32 when possible for unpacking

This commit is contained in:
Alexander 2017-08-22 00:00:17 +03:00
parent fc40ef0c1e
commit 40d30f678b

View File

@ -313,26 +313,25 @@ unpackL4IR(UINT8* out, const UINT8* in, int pixels)
} }
static void static void
unpackLA(UINT8* out, const UINT8* in, int pixels) unpackLA(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* LA, pixel interleaved */ /* LA, pixel interleaved */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
out[R] = out[G] = out[B] = in[0]; out[i] = MAKE_UINT32(in[0], in[0], in[0], in[1]);
out[A] = in[1]; in += 2;
in += 2; out += 4;
} }
} }
static void static void
unpackLAL(UINT8* out, const UINT8* in, int pixels) unpackLAL(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* LA, line interleaved */ /* LA, line interleaved */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
out[R] = out[G] = out[B] = in[i]; out[i] = MAKE_UINT32(in[i], in[i], in[i], in[i+pixels]);
out[A] = in[i+pixels];
out += 4;
} }
} }
@ -483,58 +482,50 @@ ImagingUnpackRGB(UINT8* _out, const UINT8* in, int pixels)
} }
void void
unpackRGB16B(UINT8* out, const UINT8* in, int pixels) unpackRGB16B(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* 16-bit RGB triplets, big-endian order */ /* 16-bit RGB triplets, big-endian order */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
out[R] = in[0]; out[i] = MAKE_UINT32(in[0], in[2], in[4], 255);
out[G] = in[2]; in += 6;
out[B] = in[4];
out[A] = 255;
out += 4; in += 6;
} }
} }
static void static void
unpackRGBL(UINT8* out, const UINT8* in, int pixels) unpackRGBL(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* RGB, line interleaved */ /* RGB, line interleaved */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
out[R] = in[i]; out[i] = MAKE_UINT32(in[i], in[i+pixels], in[i+pixels+pixels], 255);
out[G] = in[i+pixels];
out[B] = in[i+pixels+pixels];
out[A] = 255;
out += 4;
} }
} }
static void static void
unpackRGBR(UINT8* out, const UINT8* in, int pixels) unpackRGBR(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* RGB, bit reversed */ /* RGB, bit reversed */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
out[R] = BITFLIP[in[0]]; out[i] = MAKE_UINT32(BITFLIP[in[0]], BITFLIP[in[1]],
out[G] = BITFLIP[in[1]]; BITFLIP[in[2]], 255);
out[B] = BITFLIP[in[2]]; in += 3;
out[A] = 255;
out += 4; in += 3;
} }
} }
void void
ImagingUnpackBGR(UINT8* out, const UINT8* in, int pixels) ImagingUnpackBGR(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* RGB, reversed bytes */ /* RGB, reversed bytes */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
out[R] = in[2]; out[i] = MAKE_UINT32(in[2], in[1], in[0], 255);
out[G] = in[1]; in += 3;
out[B] = in[0];
out[A] = 255;
out += 4; in += 3;
} }
} }
@ -659,118 +650,106 @@ ImagingUnpackRGBA4B(UINT8* out, const UINT8* in, int pixels)
} }
static void static void
ImagingUnpackBGRX(UINT8* out, const UINT8* in, int pixels) ImagingUnpackBGRX(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* RGB, reversed bytes with padding */ /* RGB, reversed bytes with padding */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
out[R] = in[2]; out[i] = MAKE_UINT32(in[2], in[1], in[0], 255);
out[G] = in[1]; in += 4;
out[B] = in[0];
out[A] = 255;
out += 4; in += 4;
} }
} }
static void static void
ImagingUnpackXRGB(UINT8* out, const UINT8* in, int pixels) ImagingUnpackXRGB(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* RGB, leading pad */ /* RGB, leading pad */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
out[R] = in[1]; out[i] = MAKE_UINT32(in[1], in[2], in[3], 255);
out[G] = in[2]; in += 4;
out[B] = in[3];
out[A] = 255;
out += 4; in += 4;
} }
} }
static void static void
ImagingUnpackXBGR(UINT8* out, const UINT8* in, int pixels) ImagingUnpackXBGR(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* RGB, reversed bytes, leading pad */ /* RGB, reversed bytes, leading pad */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
out[R] = in[3]; out[i] = MAKE_UINT32(in[3], in[2], in[1], 255);
out[G] = in[2]; in += 4;
out[B] = in[1];
out[A] = 255;
out += 4; in += 4;
} }
} }
/* Unpack to "RGBA" image */ /* Unpack to "RGBA" image */
static void static void
unpackRGBALA(UINT8* out, const UINT8* in, int pixels) unpackRGBALA(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* greyscale with alpha */ /* greyscale with alpha */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
out[R] = out[G] = out[B] = in[0]; out[i] = MAKE_UINT32(in[0], in[0], in[0], in[1]);
out[A] = in[1]; in += 2;
out += 4; in += 2;
} }
} }
static void static void
unpackRGBALA16B(UINT8* out, const UINT8* in, int pixels) unpackRGBALA16B(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* 16-bit greyscale with alpha, big-endian */ /* 16-bit greyscale with alpha, big-endian */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
out[R] = out[G] = out[B] = in[0]; out[i] = MAKE_UINT32(in[0], in[0], in[0], in[2]);
out[A] = in[2]; in += 4;
out += 4; in += 4;
} }
} }
static void static void
unpackRGBa(UINT8* out, const UINT8* in, int pixels) unpackRGBa(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* premultiplied RGBA */ /* premultiplied RGBA */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
int a = in[3]; int a = in[3];
if (!a) if ( ! a)
out[R] = out[G] = out[B] = out[A] = 0; out[i] = 0;
else if (a == 255) { else if (a == 255) {
out[R] = in[0]; out[i] = MAKE_UINT32(in[0], in[1], in[2], a);
out[G] = in[1];
out[B] = in[2];
out[A] = a;
} else { } else {
out[R] = CLIP(in[0] * 255 / a); out[i] = MAKE_UINT32(CLIP(in[0] * 255 / a),
out[G] = CLIP(in[1] * 255 / a); CLIP(in[1] * 255 / a),
out[B] = CLIP(in[2] * 255 / a); CLIP(in[2] * 255 / a), a);
out[A] = a;
} }
out += 4; in += 4; in += 4;
} }
} }
static void static void
unpackBGRa(UINT8* out, const UINT8* in, int pixels) unpackBGRa(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* premultiplied BGRA */ /* premultiplied BGRA */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
int a = in[3]; int a = in[3];
if (!a) if (!a)
out[R] = out[G] = out[B] = out[A] = 0; out[i] = 0;
else if (a == 255) { else if (a == 255) {
out[R] = in[2]; out[i] = MAKE_UINT32(in[2], in[1], in[0], a);
out[G] = in[1];
out[B] = in[0];
out[A] = a;
} else { } else {
out[R] = CLIP(in[2] * 255 / a); out[i] = MAKE_UINT32(CLIP(in[2] * 255 / a),
out[G] = CLIP(in[1] * 255 / a); CLIP(in[1] * 255 / a),
out[B] = CLIP(in[0] * 255 / a); CLIP(in[0] * 255 / a), a);
out[A] = a;
} }
out += 4; in += 4; in += 4;
} }
} }
@ -789,73 +768,62 @@ unpackRGBAI(UINT8* out, const UINT8* in, int pixels)
} }
static void static void
unpackRGBAL(UINT8* out, const UINT8* in, int pixels) unpackRGBAL(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* RGBA, line interleaved */ /* RGBA, line interleaved */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
out[R] = in[i]; out[i] = MAKE_UINT32(in[i], in[i+pixels], in[i+pixels+pixels],
out[G] = in[i+pixels]; in[i+pixels+pixels+pixels]);
out[B] = in[i+pixels+pixels];
out[A] = in[i+pixels+pixels+pixels];
out += 4;
} }
} }
void void
unpackRGBA16B(UINT8* out, const UINT8* in, int pixels) unpackRGBA16B(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* 16-bit RGBA, big-endian order */ /* 16-bit RGBA, big-endian order */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
out[R] = in[0]; out[i] = MAKE_UINT32(in[0], in[2], in[4], in[6]);
out[G] = in[2]; in += 8;
out[B] = in[4];
out[A] = in[6];
out += 4; in += 8;
} }
} }
static void static void
unpackARGB(UINT8* out, const UINT8* in, int pixels) unpackARGB(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* RGBA, leading pad */ /* RGBA, leading pad */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
out[R] = in[1]; out[i] = MAKE_UINT32(in[1], in[2], in[3], in[0]);
out[G] = in[2]; in += 4;
out[B] = in[3];
out[A] = in[0];
out += 4; in += 4;
} }
} }
static void static void
unpackABGR(UINT8* out, const UINT8* in, int pixels) unpackABGR(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* RGBA, reversed bytes */ /* RGBA, reversed bytes */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
out[R] = in[3]; out[i] = MAKE_UINT32(in[3], in[2], in[1], in[0]);
out[G] = in[2]; in += 4;
out[B] = in[1];
out[A] = in[0];
out += 4; in += 4;
} }
} }
static void static void
unpackBGRA(UINT8* out, const UINT8* in, int pixels) unpackBGRA(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* RGBA, reversed bytes */ /* RGBA, reversed bytes */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
out[R] = in[2]; out[i] = MAKE_UINT32(in[2], in[1], in[0], in[3]);
out[G] = in[1]; in += 4;
out[B] = in[0];
out[A] = in[3];
out += 4; in += 4;
} }
} }
@ -863,16 +831,14 @@ unpackBGRA(UINT8* out, const UINT8* in, int pixels)
/* Unpack to "CMYK" image */ /* Unpack to "CMYK" image */
static void static void
unpackCMYKI(UINT8* out, const UINT8* in, int pixels) unpackCMYKI(UINT8* _out, const UINT8* in, int pixels)
{ {
int i; int i;
UINT32* out = (UINT32*) _out;
/* CMYK, inverted bytes (Photoshop 2.5) */ /* CMYK, inverted bytes (Photoshop 2.5) */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
out[C] = ~in[0]; out[i] = ~MAKE_UINT32(in[0], in[1], in[2], in[3]);
out[M] = ~in[1]; in += 4;
out[Y] = ~in[2];
out[K] = ~in[3];
out += 4; in += 4;
} }
} }
@ -893,6 +859,7 @@ ImagingUnpackLAB(UINT8* out, const UINT8* in, int pixels)
int i; int i;
/* LAB triplets */ /* LAB triplets */
for (i = 0; i < pixels; i++) { for (i = 0; i < pixels; i++) {
/* signed in outside world */
out[0] = in[0]; out[0] = in[0];
out[1] = in[1] ^ 128; /* signed in outside world */ out[1] = in[1] ^ 128; /* signed in outside world */
out[2] = in[2] ^ 128; out[2] = in[2] ^ 128;