annotate src/filters/simple2x.cpp @ 284:57e0314e488d

script: bought 96 burn heals
author Robert McIntyre <rlm@mit.edu>
date Wed, 28 Mar 2012 05:08:24 -0500
parents f9f4f1b99eed
children
rev   line source
rlm@1 1 #include "../Port.h"
rlm@1 2
rlm@1 3 void Simple2x16(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
rlm@1 4 u8 *dstPtr, u32 dstPitch, int width, int height)
rlm@1 5 {
rlm@1 6 u8 *nextLine, *finish;
rlm@1 7
rlm@1 8 nextLine = dstPtr + dstPitch;
rlm@1 9
rlm@1 10 do
rlm@1 11 {
rlm@1 12 u32 *bP = (u32 *) srcPtr;
rlm@1 13 u32 *dP = (u32 *) dstPtr;
rlm@1 14 u32 *nL = (u32 *) nextLine;
rlm@1 15 u32 currentPixel;
rlm@1 16
rlm@1 17 finish = (u8 *) bP + ((width + 2) << 1);
rlm@1 18 currentPixel = *bP++;
rlm@1 19
rlm@1 20 do
rlm@1 21 {
rlm@1 22 #ifdef WORDS_BIGENDIAN
rlm@1 23 u32 color = currentPixel >> 16;
rlm@1 24 #else
rlm@1 25 u32 color = currentPixel & 0xffff;
rlm@1 26 #endif
rlm@1 27
rlm@1 28 color = color | (color << 16);
rlm@1 29
rlm@1 30 *(dP) = color;
rlm@1 31 *(nL) = color;
rlm@1 32
rlm@1 33 #ifdef WORDS_BIGENDIAN
rlm@1 34 color = currentPixel & 0xffff;
rlm@1 35 #else
rlm@1 36 color = currentPixel >> 16;
rlm@1 37 #endif
rlm@1 38 color = color | (color << 16);
rlm@1 39 *(dP + 1) = color;
rlm@1 40 *(nL + 1) = color;
rlm@1 41
rlm@1 42 currentPixel = *bP++;
rlm@1 43
rlm@1 44 dP += 2;
rlm@1 45 nL += 2;
rlm@1 46 }
rlm@1 47 while ((u8 *) bP < finish);
rlm@1 48
rlm@1 49 srcPtr += srcPitch;
rlm@1 50 dstPtr += dstPitch << 1;
rlm@1 51 nextLine += dstPitch << 1;
rlm@1 52 }
rlm@1 53 while (--height);
rlm@1 54 }
rlm@1 55
rlm@1 56 void Simple2x32(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
rlm@1 57 u8 *dstPtr, u32 dstPitch, int width, int height)
rlm@1 58 {
rlm@1 59 u8 *nextLine, *finish;
rlm@1 60
rlm@1 61 nextLine = dstPtr + dstPitch;
rlm@1 62
rlm@1 63 do
rlm@1 64 {
rlm@1 65 u32 *bP = (u32 *) srcPtr;
rlm@1 66 u32 *dP = (u32 *) dstPtr;
rlm@1 67 u32 *nL = (u32 *) nextLine;
rlm@1 68 u32 currentPixel;
rlm@1 69
rlm@1 70 finish = (u8 *) bP + ((width + 1) << 2);
rlm@1 71 currentPixel = *bP++;
rlm@1 72
rlm@1 73 do
rlm@1 74 {
rlm@1 75 u32 color = currentPixel;
rlm@1 76
rlm@1 77 *(dP) = color;
rlm@1 78 *(dP + 1) = color;
rlm@1 79 *(nL) = color;
rlm@1 80 *(nL + 1) = color;
rlm@1 81
rlm@1 82 currentPixel = *bP++;
rlm@1 83
rlm@1 84 dP += 2;
rlm@1 85 nL += 2;
rlm@1 86 }
rlm@1 87 while ((u8 *) bP < finish);
rlm@1 88
rlm@1 89 srcPtr += srcPitch;
rlm@1 90 dstPtr += dstPitch << 1;
rlm@1 91 nextLine += dstPitch << 1;
rlm@1 92 }
rlm@1 93 while (--height);
rlm@1 94 }
rlm@1 95
rlm@1 96 #if 0
rlm@1 97 // generic Simple Nx magnification filter
rlm@1 98 template <int magnification, typename ColorType>
rlm@1 99 void SimpleNx(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
rlm@1 100 u8 *dstPtr, u32 dstPitch, int width, int height)
rlm@1 101 {
rlm@1 102 srcPitch = srcPitch / sizeof(ColorType) - width;
rlm@1 103 u32 dstNextP = dstPitch / sizeof(ColorType);
rlm@1 104 u32 dstNextL = (dstNextP - width) * magnification; // skip to the next magnificated 'line'
rlm@1 105 dstNextP -= magnification;
rlm@1 106
rlm@1 107 u32 offset = (dstPitch + sizeof(ColorType)) * magnification - dstPitch;
rlm@1 108
rlm@1 109 ColorType *src = (ColorType *)srcPtr;
rlm@1 110 ColorType *dst = (ColorType *)dstPtr;
rlm@1 111
rlm@1 112 do // per src line
rlm@1 113 {
rlm@1 114 u8 *finishP = (u8 *)dst + offset;
rlm@1 115 for (int x = 0; x < width; ++x) // per pixel in line
rlm@1 116 {
rlm@1 117 ColorType col = *src;
rlm@1 118 ColorType *dst2 = dst;
rlm@1 119 u8 * finishM = (u8 *)(dst + magnification);
rlm@1 120 do // dst magnificated pixel
rlm@1 121 {
rlm@1 122 do
rlm@1 123 {
rlm@1 124 *dst2 = col;
rlm@1 125 }
rlm@1 126 while ((u8 *)++dst2 < finishM);
rlm@1 127 dst2 += dstNextP;
rlm@1 128 finishM += dstPitch;
rlm@1 129 }
rlm@1 130 while ((u8 *)dst2 < finishP);
rlm@1 131
rlm@1 132 ++src;
rlm@1 133 dst += magnification;
rlm@1 134 finishP += magnification * sizeof(ColorType);
rlm@1 135 }
rlm@1 136 src += srcPitch;
rlm@1 137 dst += dstNextL;
rlm@1 138 }
rlm@1 139 while (--height);
rlm@1 140 }
rlm@1 141
rlm@1 142 #else
rlm@1 143
rlm@1 144 // generic Simple Nx magnification filter
rlm@1 145 template <int magnification, typename ColorType>
rlm@1 146 void SimpleNx(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
rlm@1 147 u8 *dstPtr, u32 dstPitch, int width, int height)
rlm@1 148 {
rlm@1 149 srcPitch = srcPitch / sizeof(ColorType) - width;
rlm@1 150 dstPitch /= sizeof(ColorType);
rlm@1 151 u32 dstBlank = (dstPitch - width) * magnification; // skip to the next magnificated 'line'
rlm@1 152 dstPitch -= magnification;
rlm@1 153
rlm@1 154 ColorType *src = (ColorType *)srcPtr;
rlm@1 155 ColorType *dst = (ColorType *)dstPtr;
rlm@1 156
rlm@1 157 do // per src line
rlm@1 158 {
rlm@1 159 for (int x = 0; x < width; ++x) // per pixel in src line
rlm@1 160 {
rlm@1 161 ColorType col = *src;
rlm@1 162 ColorType *dst2 = dst;
rlm@1 163 for (int dy = 0; dy < magnification; ++dy) // dst magnificated pixel
rlm@1 164 {
rlm@1 165 for (int dx = 0; dx < magnification; ++dx)
rlm@1 166 {
rlm@1 167 *dst2 = col;
rlm@1 168 ++dst2;
rlm@1 169 }
rlm@1 170 dst2 += dstPitch;
rlm@1 171 }
rlm@1 172
rlm@1 173 ++src;
rlm@1 174 dst += magnification;
rlm@1 175 }
rlm@1 176 src += srcPitch;
rlm@1 177 dst += dstBlank;
rlm@1 178 }
rlm@1 179 while (--height);
rlm@1 180 }
rlm@1 181
rlm@1 182 #endif
rlm@1 183
rlm@1 184 typedef void (*SimpleNxFP)(u8 *, u32, u8 *, u8 *, u32, int, int);
rlm@1 185
rlm@1 186 SimpleNxFP Simple3x16 = SimpleNx<3, u16>;
rlm@1 187 SimpleNxFP Simple3x32 = SimpleNx<3, u32>;
rlm@1 188 SimpleNxFP Simple4x16 = SimpleNx<4, u16>;
rlm@1 189 SimpleNxFP Simple4x32 = SimpleNx<4, u32>;