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