Mercurial > vba-clojure
view src/filters/simple2x.cpp @ 135:eb6ba88088d3
Wrote a more efficient input-number-assembly program; 91 oc -> 60 oc.
author | Dylan Holmes <ocsenave@gmail.com> |
---|---|
date | Sun, 18 Mar 2012 05:13:19 -0500 |
parents | f9f4f1b99eed |
children |
line wrap: on
line source
1 #include "../Port.h"3 void Simple2x16(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,4 u8 *dstPtr, u32 dstPitch, int width, int height)5 {6 u8 *nextLine, *finish;8 nextLine = dstPtr + dstPitch;10 do11 {12 u32 *bP = (u32 *) srcPtr;13 u32 *dP = (u32 *) dstPtr;14 u32 *nL = (u32 *) nextLine;15 u32 currentPixel;17 finish = (u8 *) bP + ((width + 2) << 1);18 currentPixel = *bP++;20 do21 {22 #ifdef WORDS_BIGENDIAN23 u32 color = currentPixel >> 16;24 #else25 u32 color = currentPixel & 0xffff;26 #endif28 color = color | (color << 16);30 *(dP) = color;31 *(nL) = color;33 #ifdef WORDS_BIGENDIAN34 color = currentPixel & 0xffff;35 #else36 color = currentPixel >> 16;37 #endif38 color = color | (color << 16);39 *(dP + 1) = color;40 *(nL + 1) = color;42 currentPixel = *bP++;44 dP += 2;45 nL += 2;46 }47 while ((u8 *) bP < finish);49 srcPtr += srcPitch;50 dstPtr += dstPitch << 1;51 nextLine += dstPitch << 1;52 }53 while (--height);54 }56 void Simple2x32(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,57 u8 *dstPtr, u32 dstPitch, int width, int height)58 {59 u8 *nextLine, *finish;61 nextLine = dstPtr + dstPitch;63 do64 {65 u32 *bP = (u32 *) srcPtr;66 u32 *dP = (u32 *) dstPtr;67 u32 *nL = (u32 *) nextLine;68 u32 currentPixel;70 finish = (u8 *) bP + ((width + 1) << 2);71 currentPixel = *bP++;73 do74 {75 u32 color = currentPixel;77 *(dP) = color;78 *(dP + 1) = color;79 *(nL) = color;80 *(nL + 1) = color;82 currentPixel = *bP++;84 dP += 2;85 nL += 2;86 }87 while ((u8 *) bP < finish);89 srcPtr += srcPitch;90 dstPtr += dstPitch << 1;91 nextLine += dstPitch << 1;92 }93 while (--height);94 }96 #if 097 // generic Simple Nx magnification filter98 template <int magnification, typename ColorType>99 void SimpleNx(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,100 u8 *dstPtr, u32 dstPitch, int width, int height)101 {102 srcPitch = srcPitch / sizeof(ColorType) - width;103 u32 dstNextP = dstPitch / sizeof(ColorType);104 u32 dstNextL = (dstNextP - width) * magnification; // skip to the next magnificated 'line'105 dstNextP -= magnification;107 u32 offset = (dstPitch + sizeof(ColorType)) * magnification - dstPitch;109 ColorType *src = (ColorType *)srcPtr;110 ColorType *dst = (ColorType *)dstPtr;112 do // per src line113 {114 u8 *finishP = (u8 *)dst + offset;115 for (int x = 0; x < width; ++x) // per pixel in line116 {117 ColorType col = *src;118 ColorType *dst2 = dst;119 u8 * finishM = (u8 *)(dst + magnification);120 do // dst magnificated pixel121 {122 do123 {124 *dst2 = col;125 }126 while ((u8 *)++dst2 < finishM);127 dst2 += dstNextP;128 finishM += dstPitch;129 }130 while ((u8 *)dst2 < finishP);132 ++src;133 dst += magnification;134 finishP += magnification * sizeof(ColorType);135 }136 src += srcPitch;137 dst += dstNextL;138 }139 while (--height);140 }142 #else144 // generic Simple Nx magnification filter145 template <int magnification, typename ColorType>146 void SimpleNx(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,147 u8 *dstPtr, u32 dstPitch, int width, int height)148 {149 srcPitch = srcPitch / sizeof(ColorType) - width;150 dstPitch /= sizeof(ColorType);151 u32 dstBlank = (dstPitch - width) * magnification; // skip to the next magnificated 'line'152 dstPitch -= magnification;154 ColorType *src = (ColorType *)srcPtr;155 ColorType *dst = (ColorType *)dstPtr;157 do // per src line158 {159 for (int x = 0; x < width; ++x) // per pixel in src line160 {161 ColorType col = *src;162 ColorType *dst2 = dst;163 for (int dy = 0; dy < magnification; ++dy) // dst magnificated pixel164 {165 for (int dx = 0; dx < magnification; ++dx)166 {167 *dst2 = col;168 ++dst2;169 }170 dst2 += dstPitch;171 }173 ++src;174 dst += magnification;175 }176 src += srcPitch;177 dst += dstBlank;178 }179 while (--height);180 }182 #endif184 typedef void (*SimpleNxFP)(u8 *, u32, u8 *, u8 *, u32, int, int);186 SimpleNxFP Simple3x16 = SimpleNx<3, u16>;187 SimpleNxFP Simple3x32 = SimpleNx<3, u32>;188 SimpleNxFP Simple4x16 = SimpleNx<4, u16>;189 SimpleNxFP Simple4x32 = SimpleNx<4, u32>;