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