App

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

TCubicFInt.cpp
Go to the documentation of this file.
1
6 #include "TCubicFInt.hpp"
7
8 namespace app {
9
10 template class TCubicFInt<px_1x8bit, px_1x8bit> ;
11 template class TCubicFInt<px_4x8bit, px_1x8bit> ;
12
13 #define REINDEXED_INTERPOLATION_GENERAL_ALGORITHM(INIT, REINDEXED_ACTION, NON_REINDEXED_ACTION) \
14 {\
15 INIT\
16 \
17 TPIXEL * dPtr;\
18 TPIXEL * dColBgnPtr = dData;\
19 TPIXEL * dColBgnPtrEnd = dColBgnPtr + dWidth;\
20 \
21 double firstNoReindexDstIndex = (noReindexFrom - x0) / dx;\
22 firstNoReindexDstIndex = (firstNoReindexDstIndex < 0) ? 0 : firstNoReindexDstIndex + 2;\
23 \
24 TPIXEL * dPtrNoReindexFrom = dColBgnPtr + ((int) firstNoReindexDstIndex) * dWidth;\
25 int firstReindexDstIndex = (noReindexTo - x0) / dx + 1;\
26 TPIXEL * dPtrNoReindexTo = dColBgnPtr + firstReindexDstIndex * dWidth;\
27 TPIXEL * dPtrEnd = dColBgnPtr + dWidth * dHeight;\
28 \
29 TPIXEL * sPtrRowBgn = sData;\
30 TPIXEL * sPtr;\
31 \
32 double x;\
33 \
34 while (dColBgnPtr < dColBgnPtrEnd) {\
35 x = x0;\
36 dPtr = dColBgnPtr++;\
37 while (dPtr < dPtrNoReindexFrom) {\
38 REINDEXED_ACTION\
39 dPtr += dWidth;\
40 x += dx;\
41 }\
42 while (dPtr < dPtrNoReindexTo) {\
43 NON_REINDEXED_ACTION\
44 dPtr += dWidth;\
45 x += dx;\
46 }\
47 while (dPtr < dPtrEnd) {\
48 REINDEXED_ACTION\
49 dPtr += dWidth;\
50 x += dx;\
51 }\
52 sPtrRowBgn += sWidth;\
53 dPtrNoReindexFrom++;\
54 dPtrNoReindexTo++;\
55 }\
56 }
57
58 template<typename TPIXEL, typename TCHANNEL>
59 TCubicFInt<TPIXEL, TCHANNEL>::~TCubicFInt() {
60 if (xReindex != NULL) {
61 free(xReindex);
62 }
63 if (yReindex != NULL) {
64 free(yReindex);
65 }
66
67 }
68
69 template<typename TPIXEL, typename TCHANNEL>
70 int TCubicFInt<TPIXEL, TCHANNEL>::resampleTo_4ch(TBitmap<TPIXEL, TCHANNEL> &dst) const {
71 if (srcData == NULL) {
72 return 1;
73 }
74
75 TPIXEL * const dstData = dst.getData();
76 if (dstData == NULL) {
77 return 2;
78 }
79
80 if (!isInitOk()) {
81 return 3;
82 }
83
84 unsigned origWidth = srcWidth;
85 unsigned origHeight = srcHeight;
86 unsigned dstWidth = dst.getWidth();
87 unsigned dstHeight = dst.getHeight();
88 unsigned tmpWidth = srcHeight;
89 unsigned tmpHeight = dstWidth;
90
91 TPIXEL * const tmpData = (TPIXEL *) malloc((unsigned long) (tmpWidth * tmpHeight * sizeof(TPIXEL)));
92 if (tmpData == NULL) {
93 return 3;
94 }
95
96 double xDelta = srcWidth / (double) dstWidth;
97 double xMin = xDelta / 2.0;
98 double yDelta = srcHeight / (double) dstHeight;
99 double yMin = yDelta / 2.0;
100
101 REINDEXED_INTERPOLATION_GENERAL_ALGORITHM(
102 TPIXEL * sData = srcData; int sWidth = origWidth; int sHeight = origHeight; TPIXEL * dData = tmpData; int dWidth = tmpWidth; int dHeight = tmpHeight; double x0 = xMin; double dx = xDelta; int * reindexer = xReindex; double noReindexFrom = xNoReindexFrom; double noReindexTo = xNoReindexTo; TCHANNEL * px0; TCHANNEL * px1; TCHANNEL * px2; TCHANNEL * px3; TCHANNEL * dpx; double clamp; TCHANNEL p0; TCHANNEL p1; TCHANNEL p2; TCHANNEL p3; int X; double nx;,
103
104 nx = x + 0.5; X = nx; nx -= X; px0 = (TCHANNEL *)(sPtrRowBgn + reindexer[X++]); px1 = (TCHANNEL *)(sPtrRowBgn + reindexer[X++]); px2 = (TCHANNEL *)(sPtrRowBgn + reindexer[X++]); px3 = (TCHANNEL *)(sPtrRowBgn + reindexer[X]); dpx = (TCHANNEL *)dPtr;
105
106 p0 = *(px0++); p1 = *(px1++); p2 = *(px2++); p3 = *(px3++); INTERPOLATE_CUBIC(p0, p1, p2, p3, nx, clamp); *dpx = (clamp > maxVal) ? maxVal : (clamp < 0) ? 0 : clamp; dpx++;
107
108 p0 = *(px0++); p1 = *(px1++); p2 = *(px2++); p3 = *(px3++); INTERPOLATE_CUBIC(p0, p1, p2, p3, nx, clamp); *dpx = (clamp > maxVal) ? maxVal : (clamp < 0) ? 0 : clamp; dpx++;
109
110 p0 = *(px0++); p1 = *(px1++); p2 = *(px2++); p3 = *(px3++); INTERPOLATE_CUBIC(p0, p1, p2, p3, nx, clamp); *dpx = (clamp > maxVal) ? maxVal : (clamp < 0) ? 0 : clamp; dpx++;
111
112 p0 = *(px0); p1 = *(px1); p2 = *(px2); p3 = *(px3); INTERPOLATE_CUBIC(p0, p1, p2, p3, nx, clamp); *dpx = (clamp > maxVal) ? maxVal : (clamp < 0) ? 0 : clamp;,
113
114 nx = x - 1.5; X = nx; nx -= X; sPtr = sPtrRowBgn + X; px0 = (TCHANNEL *) sPtr++; px1 = (TCHANNEL *) sPtr++; px2 = (TCHANNEL *) sPtr++; px3 = (TCHANNEL *) sPtr; dpx = (TCHANNEL *)dPtr;
115
116 p0 = *(px0++); p1 = *(px1++); p2 = *(px2++); p3 = *(px3++); INTERPOLATE_CUBIC(p0, p1, p2, p3, nx, clamp); *dpx = (clamp > maxVal) ? maxVal : (clamp < 0) ? 0 : clamp; dpx++;
117
118 p0 = *(px0++); p1 = *(px1++); p2 = *(px2++); p3 = *(px3++); INTERPOLATE_CUBIC(p0, p1, p2, p3, nx, clamp); *dpx = (clamp > maxVal) ? maxVal : (clamp < 0) ? 0 : clamp; dpx++;
119
120 p0 = *(px0++); p1 = *(px1++); p2 = *(px2++); p3 = *(px3++); INTERPOLATE_CUBIC(p0, p1, p2, p3, nx, clamp); *dpx = (clamp > maxVal) ? maxVal : (clamp < 0) ? 0 : clamp; dpx++;
121
122 p0 = *(px0); p1 = *(px1); p2 = *(px2); p3 = *(px3); INTERPOLATE_CUBIC(p0, p1, p2, p3, nx, clamp); *dpx = (clamp > maxVal) ? maxVal : (clamp < 0) ? 0 : clamp;)
123
124 REINDEXED_INTERPOLATION_GENERAL_ALGORITHM(
125 TPIXEL * sData = tmpData; int sWidth = tmpWidth; int sHeight = tmpHeight; TPIXEL * dData = dstData; int dWidth = dstWidth; int dHeight = dstHeight; double x0 = yMin; double dx = yDelta; int * reindexer = yReindex; double noReindexFrom = yNoReindexFrom; double noReindexTo = yNoReindexTo; TCHANNEL * px0; TCHANNEL * px1; TCHANNEL * px2; TCHANNEL * px3; TCHANNEL * dpx; double clamp; TCHANNEL p0; TCHANNEL p1; TCHANNEL p2; TCHANNEL p3; int X; double nx;,
126
127 nx = x + 0.5; X = nx; nx -= X; px0 = (TCHANNEL *)(sPtrRowBgn + reindexer[X++]); px1 = (TCHANNEL *)(sPtrRowBgn + reindexer[X++]); px2 = (TCHANNEL *)(sPtrRowBgn + reindexer[X++]); px3 = (TCHANNEL *)(sPtrRowBgn + reindexer[X]); dpx = (TCHANNEL *)dPtr;
128
129 p0 = *(px0++); p1 = *(px1++); p2 = *(px2++); p3 = *(px3++); INTERPOLATE_CUBIC(p0, p1, p2, p3, nx, clamp); *dpx = (clamp > maxVal) ? maxVal : (clamp < 0) ? 0 : clamp; dpx++;
130
131 p0 = *(px0++); p1 = *(px1++); p2 = *(px2++); p3 = *(px3++); INTERPOLATE_CUBIC(p0, p1, p2, p3, nx, clamp); *dpx = (clamp > maxVal) ? maxVal : (clamp < 0) ? 0 : clamp; dpx++;
132
133 p0 = *(px0++); p1 = *(px1++); p2 = *(px2++); p3 = *(px3++); INTERPOLATE_CUBIC(p0, p1, p2, p3, nx, clamp); *dpx = (clamp > maxVal) ? maxVal : (clamp < 0) ? 0 : clamp; dpx++;
134
135 p0 = *(px0); p1 = *(px1); p2 = *(px2); p3 = *(px3); INTERPOLATE_CUBIC(p0, p1, p2, p3, nx, clamp); *dpx = (clamp > maxVal) ? maxVal : (clamp < 0) ? 0 : clamp;,
136
137 nx = x - 1.5; X = nx; nx -= X; sPtr = sPtrRowBgn + X; px0 = (TCHANNEL *) sPtr++; px1 = (TCHANNEL *) sPtr++; px2 = (TCHANNEL *) sPtr++; px3 = (TCHANNEL *) sPtr; dpx = (TCHANNEL *)dPtr;
138
139 p0 = *(px0++); p1 = *(px1++); p2 = *(px2++); p3 = *(px3++); INTERPOLATE_CUBIC(p0, p1, p2, p3, nx, clamp); *dpx = (clamp > maxVal) ? maxVal : (clamp < 0) ? 0 : clamp; dpx++;
140
141 p0 = *(px0++); p1 = *(px1++); p2 = *(px2++); p3 = *(px3++); INTERPOLATE_CUBIC(p0, p1, p2, p3, nx, clamp); *dpx = (clamp > maxVal) ? maxVal : (clamp < 0) ? 0 : clamp; dpx++;
142
143 p0 = *(px0++); p1 = *(px1++); p2 = *(px2++); p3 = *(px3++); INTERPOLATE_CUBIC(p0, p1, p2, p3, nx, clamp); *dpx = (clamp > maxVal) ? maxVal : (clamp < 0) ? 0 : clamp; dpx++;
144
145 p0 = *(px0); p1 = *(px1); p2 = *(px2); p3 = *(px3); INTERPOLATE_CUBIC(p0, p1, p2, p3, nx, clamp); *dpx = (clamp > maxVal) ? maxVal : (clamp < 0) ? 0 : clamp;)
146
147 free(tmpData);
148
149 return 0;
150 }
151
152 template<typename TPIXEL, typename TCHANNEL>
153 int TCubicFInt<TPIXEL, TCHANNEL>::resampleTo_1ch(TBitmap<TPIXEL, TCHANNEL> &dst) const {
154
155 if (srcData == NULL) {
156 return 1;
157 }
158
159 TPIXEL * const dstData = dst.getData();
160 if (dstData == NULL) {
161 return 2;
162 }
163
164 if (!isInitOk()) {
165 return 3;
166 }
167
168 unsigned origWidth = srcWidth;
169 unsigned origHeight = srcHeight;
170 unsigned dstWidth = dst.getWidth();
171 unsigned dstHeight = dst.getHeight();
172 unsigned tmpWidth = srcHeight;
173 unsigned tmpHeight = dstWidth;
174
175 TPIXEL * const tmpData = (TPIXEL *) malloc((unsigned long) (tmpWidth * tmpHeight * sizeof(TPIXEL)));
176 if (tmpData == NULL) {
177 return 3;
178 }
179
180 double xDelta = srcWidth / (double) dstWidth;
181 double xMin = xDelta / 2.0;
182 double yDelta = srcHeight / (double) dstHeight;
183 double yMin = yDelta / 2.0;
184
185 REINDEXED_INTERPOLATION_GENERAL_ALGORITHM(
186 TPIXEL * sData = srcData; int sWidth = origWidth; int sHeight = origHeight; TPIXEL * dData = tmpData; int dWidth = tmpWidth; int dHeight = tmpHeight; double x0 = xMin; double dx = xDelta; int * reindexer = xReindex; double noReindexFrom = xNoReindexFrom; double noReindexTo = xNoReindexTo; TCHANNEL p0; TCHANNEL p1; TCHANNEL p2; TCHANNEL p3; double clamp; int X; double nx;,
187
188 nx = x + 0.5; X = nx; nx -= X; p0 = sPtrRowBgn[reindexer[X++]]; p1 = sPtrRowBgn[reindexer[X++]]; p2 = sPtrRowBgn[reindexer[X++]]; p3 = sPtrRowBgn[reindexer[X]]; INTERPOLATE_CUBIC(p0, p1, p2, p3, nx, clamp); *dPtr = (clamp > maxVal) ? maxVal : (clamp < 0) ? 0 : clamp;,
189
190 nx = x - 1.5; X = nx; nx -= X; sPtr = sPtrRowBgn + X; p0 = *(sPtr++); p1 = *(sPtr++); p2 = *(sPtr++); p3 = *(sPtr); INTERPOLATE_CUBIC(p0, p1, p2, p3, nx, clamp); *dPtr = (clamp > maxVal) ? maxVal : (clamp < 0) ? 0 : clamp;)
191
192 REINDEXED_INTERPOLATION_GENERAL_ALGORITHM(
193 TPIXEL * sData = tmpData; int sWidth = tmpWidth; int sHeight = tmpHeight; TPIXEL * dData = dstData; int dWidth = dstWidth; int dHeight = dstHeight; double x0 = yMin; double dx = yDelta; int * reindexer = yReindex; double noReindexFrom = yNoReindexFrom; double noReindexTo = yNoReindexTo; TCHANNEL p0; TCHANNEL p1; TCHANNEL p2; TCHANNEL p3; double clamp; int X; double nx;,
194
195 nx = x + 0.5; X = nx; nx -= X; p0 = sPtrRowBgn[reindexer[X++]]; p1 = sPtrRowBgn[reindexer[X++]]; p2 = sPtrRowBgn[reindexer[X++]]; p3 = sPtrRowBgn[reindexer[X]]; INTERPOLATE_CUBIC(p0, p1, p2, p3, nx, clamp); *dPtr = (clamp > maxVal) ? maxVal : (clamp < 0) ? 0 : clamp;,
196
197 nx = x - 1.5; X = nx; nx -= X; sPtr = sPtrRowBgn + X; p0 = *(sPtr++); p1 = *(sPtr++); p2 = *(sPtr++); p3 = *(sPtr); INTERPOLATE_CUBIC(p0, p1, p2, p3, nx, clamp); *dPtr = (clamp > maxVal) ? maxVal : (clamp < 0) ? 0 : clamp;)
198
199 free(tmpData);
200
201 return 0;
202 }
203
204 } /* namespace app */