Refactored YCoCg converstion
#include "prim_internal.h"
+/* helper function to convert raw 8 bit values to signed 16bit values.
+ */
+static INT16 convert(UINT8 raw, int shift)
+{
+ const int cll = shift - 1; /* -1 builds in the /2's */
+ return (INT16)((INT8)(raw << cll));
+}
+
/* ------------------------------------------------------------------------- */
static pstatus_t general_YCoCgToRGB_8u_AC4R(const BYTE* pSrc, INT32 srcStep, BYTE* pDst,
UINT32 DstFormat, INT32 dstStep, UINT32 width,
UINT32 height, UINT8 shift, BOOL withAlpha)
{
- BYTE A;
UINT32 x, y;
- BYTE* dptr = pDst;
- const BYTE* sptr = pSrc;
- INT16 Cg, Co, Y, T, R, G, B;
const DWORD formatSize = GetBytesPerPixel(DstFormat);
fkt_writePixel writePixel = getPixelWriteFunction(DstFormat, TRUE);
- int cll = shift - 1; /* -1 builds in the /2's */
- UINT32 srcPad = srcStep - (width * 4);
- UINT32 dstPad = dstStep - (width * formatSize);
for (y = 0; y < height; y++)
{
+ const BYTE* sptr = &pSrc[srcStep * y];
+ BYTE* dptr = &pDst[dstStep * y];
for (x = 0; x < width; x++)
{
/* Note: shifts must be done before sign-conversion. */
- Cg = (INT16)((INT8)((*sptr++) << cll));
- Co = (INT16)((INT8)((*sptr++) << cll));
- Y = (INT16)(*sptr++); /* UINT8->INT16 */
- A = *sptr++;
+ const INT16 Cg = convert(*sptr++, shift);
+ const INT16 Co = convert(*sptr++, shift);
+ const INT16 Y = *sptr++; /* UINT8->INT16 */
+ const INT16 T = Y - Cg;
+ const INT16 B = T + Co;
+ const INT16 G = Y + Cg;
+ const INT16 R = T - Co;
+ BYTE A = *sptr++;
if (!withAlpha)
A = 0xFFU;
- T = Y - Cg;
- B = T + Co;
- G = Y + Cg;
- R = T - Co;
dptr = writePixel(dptr, formatSize, DstFormat, CLIP(R), CLIP(G), CLIP(B), A);
}
-
- sptr += srcPad;
- dptr += dstPad;
}
return PRIMITIVES_SUCCESS;
