rlm@1: #include "../Port.h" rlm@1: rlm@1: extern u32 RGB_LOW_BITS_MASK; rlm@1: rlm@1: void Pixelate2x16(u8 *srcPtr, u32 srcPitch, u8 *deltaPtr, rlm@1: u8 *dstPtr, u32 dstPitch, int width, int height) rlm@1: { rlm@1: u8 *nextLine, *finish; rlm@1: u32 colorMask = ~(RGB_LOW_BITS_MASK | (RGB_LOW_BITS_MASK << 16)); rlm@1: colorMask = (colorMask >> 2) & (colorMask >> 1); rlm@1: rlm@1: nextLine = dstPtr + dstPitch; rlm@1: rlm@1: do rlm@1: { rlm@1: u32 *bP = (u32 *) srcPtr; rlm@1: u32 *xP = (u32 *) deltaPtr; rlm@1: u32 *dP = (u32 *) dstPtr; rlm@1: u32 *nL = (u32 *) nextLine; rlm@1: u32 currentPixel; rlm@1: u32 nextPixel; rlm@1: u32 currentDelta; rlm@1: u32 nextDelta; rlm@1: rlm@1: finish = (u8 *) bP + ((width+2) << 1); rlm@1: nextPixel = *bP++; rlm@1: nextDelta = *xP++; rlm@1: rlm@1: do rlm@1: { rlm@1: currentPixel = nextPixel; rlm@1: currentDelta = nextDelta; rlm@1: nextPixel = *bP++; rlm@1: nextDelta = *xP++; rlm@1: rlm@1: if ((nextPixel != nextDelta) || (currentPixel != currentDelta)) rlm@1: { rlm@1: u32 colorA, colorB, product; rlm@1: rlm@1: *(xP - 2) = currentPixel; rlm@1: #ifdef WORDS_BIGENDIAN rlm@1: colorA = currentPixel >> 16; rlm@1: colorB = currentPixel & 0xffff; rlm@1: #else rlm@1: colorA = currentPixel & 0xffff; rlm@1: colorB = currentPixel >> 16; rlm@1: #endif rlm@1: product = (colorA >> 2) & colorMask; rlm@1: rlm@1: #ifdef WORDS_BIGENDIAN rlm@1: *(nL) = (product << 16) | (product); rlm@1: *(dP) = (colorA << 16) | product; rlm@1: #else rlm@1: *(nL) = product | (product << 16); rlm@1: *(dP) = colorA | (product << 16); rlm@1: #endif rlm@1: rlm@1: #ifdef WORDS_BIGENDIAN rlm@1: colorA = nextPixel >> 16; rlm@1: #else rlm@1: colorA = nextPixel & 0xffff; rlm@1: #endif rlm@1: product = (colorB >> 2) & colorMask; rlm@1: #ifdef WORDS_BIGENDIAN rlm@1: *(nL + 1) = (product << 16) | (product); rlm@1: *(dP + 1) = (colorB << 16) | (product); rlm@1: #else rlm@1: *(nL + 1) = (product) | (product << 16); rlm@1: *(dP + 1) = (colorB) | (product << 16); rlm@1: #endif rlm@1: } rlm@1: rlm@1: dP += 2; rlm@1: nL += 2; rlm@1: } rlm@1: while ((u8 *) bP < finish); rlm@1: rlm@1: deltaPtr += srcPitch; rlm@1: srcPtr += srcPitch; rlm@1: dstPtr += dstPitch << 1; rlm@1: nextLine += dstPitch << 1; rlm@1: } rlm@1: while (--height); rlm@1: } rlm@1: rlm@1: void Pixelate2x32(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */, rlm@1: u8 *dstPtr, u32 dstPitch, int width, int height) rlm@1: { rlm@1: u8 *nextLine, *finish; rlm@1: u32 colorMask = ((u32)~RGB_LOW_BITS_MASK >> 2) & ((u32)~RGB_LOW_BITS_MASK >> 1); rlm@1: rlm@1: nextLine = dstPtr + dstPitch; rlm@1: rlm@1: do rlm@1: { rlm@1: u32 *bP = (u32 *) srcPtr; rlm@1: // u32 *xP = (u32 *) deltaPtr; rlm@1: u32 *dP = (u32 *) dstPtr; rlm@1: u32 *nL = (u32 *) nextLine; rlm@1: u32 currentPixel; rlm@1: u32 nextPixel; rlm@1: rlm@1: finish = (u8 *) bP + ((width+1) << 2); rlm@1: nextPixel = *bP++; rlm@1: rlm@1: do rlm@1: { rlm@1: u32 product; rlm@1: rlm@1: currentPixel = nextPixel; rlm@1: nextPixel = *bP++; rlm@1: product = (currentPixel >> 2) & colorMask; rlm@1: *(nL) = product; rlm@1: *(nL+1) = product; rlm@1: *(dP) = currentPixel; rlm@1: *(dP+1) = product; rlm@1: rlm@1: currentPixel = nextPixel; rlm@1: nextPixel = *bP++; rlm@1: product = (currentPixel >> 2) & colorMask; rlm@1: *(nL + 2) = product; rlm@1: *(nL + 3) = product; rlm@1: *(dP + 2) = currentPixel; rlm@1: *(dP + 3) = product; rlm@1: rlm@1: dP += 4; rlm@1: nL += 4; rlm@1: } rlm@1: while ((u8 *) bP < finish); rlm@1: rlm@1: srcPtr += srcPitch; rlm@1: dstPtr += dstPitch << 1; rlm@1: nextLine += dstPitch << 1; rlm@1: } rlm@1: while (--height); rlm@1: } rlm@1: rlm@1: // generic Pixelate Nx magnification filter rlm@1: template rlm@1: void PixelateNx(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */, rlm@1: u8 *dstPtr, u32 dstPitch, int width, int height) rlm@1: { rlm@1: ColorType colorMask = ((ColorType)~RGB_LOW_BITS_MASK >> 2) & ((ColorType)~RGB_LOW_BITS_MASK >> 1); rlm@1: rlm@1: srcPitch = srcPitch / sizeof(ColorType) - width; rlm@1: u32 dstNextP = dstPitch / sizeof(ColorType); rlm@1: u32 dstNextL = (dstNextP - width) * magnification; // skip to the next magnificated 'line' rlm@1: dstNextP -= magnification; rlm@1: rlm@1: u32 offset = (dstPitch + sizeof(ColorType)) * magnification - dstPitch; rlm@1: rlm@1: ColorType *src = (ColorType *)srcPtr; rlm@1: ColorType *dst = (ColorType *)dstPtr; rlm@1: rlm@1: do // per src line rlm@1: { rlm@1: u8 *finishP = (u8 *)dst + offset; rlm@1: for (int x = 0; x < width; ++x) // per pixel in line rlm@1: { rlm@1: ColorType col = *src; rlm@1: ColorType *dst2 = dst; rlm@1: u8 *finishM = (u8 *)(dst + magnification); rlm@1: rlm@1: ColorType product = (col >> 2) & colorMask; rlm@1: do rlm@1: { rlm@1: *dst2 = product; rlm@1: } while ((u8 *)++dst2 < finishM); rlm@1: dst2 += dstNextP; rlm@1: finishM += dstPitch; rlm@1: do // dst magnificated pixel rlm@1: { rlm@1: *dst2++ = product; rlm@1: do rlm@1: { rlm@1: *dst2 = col; rlm@1: } while ((u8 *)++dst2 < finishM); rlm@1: dst2 += dstNextP; rlm@1: finishM += dstPitch; rlm@1: } while ((u8 *)dst2 < finishP); rlm@1: rlm@1: ++src; rlm@1: dst += magnification; rlm@1: finishP += magnification * sizeof(ColorType); rlm@1: } rlm@1: src += srcPitch; rlm@1: dst += dstNextL; rlm@1: } while (--height); rlm@1: } rlm@1: rlm@1: typedef void (*PixelateNxFP)(u8*, u32, u8*, u8*, u32, int, int); rlm@1: rlm@1: PixelateNxFP Pixelate3x16 = PixelateNx<3, u16>; rlm@1: PixelateNxFP Pixelate3x32 = PixelateNx<3, u32>; rlm@1: PixelateNxFP Pixelate4x16 = PixelateNx<4, u16>; rlm@1: PixelateNxFP Pixelate4x32 = PixelateNx<4, u32>;