Faster ImagingUnpackRGB

This commit is contained in:
Alexander 2017-08-15 23:05:12 +03:00
parent 07fa92ba5b
commit b4e226714d
2 changed files with 19 additions and 9 deletions

View File

@ -467,7 +467,6 @@ typedef void (*ImagingShuffler)(UINT8* out, const UINT8* in, int pixels);
/* Public shufflers */
extern void ImagingPackRGB(UINT8* out, const UINT8* in, int pixels);
extern void ImagingPackBGR(UINT8* out, const UINT8* in, int pixels);
extern void ImagingUnpackRGB(UINT8* out, const UINT8* in, int pixels);
extern void ImagingUnpackBGR(UINT8* out, const UINT8* in, int pixels);
extern void ImagingUnpackYCC(UINT8* out, const UINT8* in, int pixels);
extern void ImagingUnpackYCCA(UINT8* out, const UINT8* in, int pixels);

View File

@ -463,19 +463,30 @@ unpackP4L(UINT8* out, const UINT8* in, int pixels)
}
}
#ifdef WORDS_BIGENDIAN
#define MAKE_UINT32(u0, u1, u2, u3) (u3 | (u2<<8) | (u1<<16) | (u0<<24))
#define CHANNEL_4_MASK 0x000000ff
#else
#define MAKE_UINT32(u0, u1, u2, u3) (u0 | (u1<<8) | (u2<<16) | (u3<<24))
#define CHANNEL_4_MASK 0xff000000
#endif
/* Unpack to "RGB" image */
void
ImagingUnpackRGB(UINT8* out, const UINT8* in, int pixels)
ImagingUnpackRGB(UINT8* _out, const UINT8* in, int pixels)
{
int i;
int i = 0;
UINT32* out = (UINT32*) _out;
/* RGB triplets */
for (i = 0; i < pixels; i++) {
out[R] = in[0];
out[G] = in[1];
out[B] = in[2];
out[A] = 255;
out += 4; in += 3;
for (; i < pixels-1; i++) {
out[i] = CHANNEL_4_MASK | *(UINT32*)&in[0];
in += 3;
}
for (; i < pixels; i++) {
out[i] = MAKE_UINT32(in[0], in[1], in[2], 255);
in += 3;
}
}