App

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

- File List
- File Members

TLinearFInt.cpp
Go to the documentation of this file.
1
6 #include "TLinearFInt.hpp"
7
8 namespace app {
9
10 template class TLinearFInt<px_1x8bit, px_1x8bit> ;
11 template class TLinearFInt<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 TLinearFInt<TPIXEL, TCHANNEL>::~TLinearFInt() {
60 if (xReindex != NULL) {
61 free(xReindex);
62 }
63 if (yReindex != NULL) {
64 free(yReindex);
65 }
66 }
67
68 template<typename TPIXEL, typename TCHANNEL>
69 int TLinearFInt<TPIXEL, TCHANNEL>::resampleTo_4ch(TBitmap<TPIXEL, TCHANNEL> &dst) const {
70 if (srcData == NULL) {
71 return 1;
72 }
73
74 TPIXEL * const dstData = dst.getData();
75 if (dstData == NULL) {
76 return 2;
77 }
78
79 if (!isInitOk()) {
80 return 3;
81 }
82
83 unsigned origWidth = srcWidth;
84 unsigned origHeight = srcHeight;
85 unsigned dstWidth = dst.getWidth();
86 unsigned dstHeight = dst.getHeight();
87 unsigned tmpWidth = srcHeight;
88 unsigned tmpHeight = dstWidth;
89
90 TPIXEL * const tmpData = (TPIXEL *) malloc((unsigned long) (tmpWidth * tmpHeight * sizeof(TPIXEL)));
91 if (tmpData == NULL) {
92 return 3;
93 }
94
95 double xDelta = srcWidth / (double) dstWidth;
96 double xMin = xDelta / 2.0;
97 double yDelta = srcHeight / (double) dstHeight;
98 double yMin = yDelta / 2.0;
99
100 REINDEXED_INTERPOLATION_GENERAL_ALGORITHM(
101 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 * px1; TCHANNEL * px2; TCHANNEL * dpx; TCHANNEL p1; TCHANNEL p2; int X; double nx;,
102
103 nx = x + 0.5; X = nx; nx -= X; px1 = (TCHANNEL *)(sPtrRowBgn + reindexer[X++]); px2 = (TCHANNEL *)(sPtrRowBgn + reindexer[X]); dpx = (TCHANNEL *)dPtr;
104
105 p1 = *(px1++); p2 = *(px2++); INTERPOLATE_LINEAR(p1, p2, nx, *dpx); dpx++;
106
107 p1 = *(px1++); p2 = *(px2++); INTERPOLATE_LINEAR(p1, p2, nx, *dpx); dpx++;
108
109 p1 = *(px1++); p2 = *(px2++); INTERPOLATE_LINEAR(p1, p2, nx, *dpx); dpx++;
110
111 p1 = *(px1); p2 = *(px2); INTERPOLATE_LINEAR(p1, p2, nx, *dpx);,
112
113 nx = x - 0.5; X = nx; nx -= X; sPtr = sPtrRowBgn + X; px1 = (TCHANNEL *) sPtr++; px2 = (TCHANNEL *) sPtr; dpx = (TCHANNEL *)dPtr;
114
115 p1 = *(px1++); p2 = *(px2++); INTERPOLATE_LINEAR(p1, p2, nx, *dpx); dpx++;
116
117 p1 = *(px1++); p2 = *(px2++); INTERPOLATE_LINEAR(p1, p2, nx, *dpx); dpx++;
118
119 p1 = *(px1++); p2 = *(px2++); INTERPOLATE_LINEAR(p1, p2, nx, *dpx); dpx++;
120
121 p1 = *(px1); p2 = *(px2); INTERPOLATE_LINEAR(p1, p2, nx, *dpx);)
122
123 REINDEXED_INTERPOLATION_GENERAL_ALGORITHM(
124 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 * px1; TCHANNEL * px2; TCHANNEL * dpx; TCHANNEL p1; TCHANNEL p2; int X; double nx;,
125
126 nx = x + 0.5; X = nx; nx -= X; px1 = (TCHANNEL *)(sPtrRowBgn + reindexer[X++]); px2 = (TCHANNEL *)(sPtrRowBgn + reindexer[X]); dpx = (TCHANNEL *)dPtr;
127
128 p1 = *(px1++); p2 = *(px2++); INTERPOLATE_LINEAR(p1, p2, nx, *dpx); dpx++;
129
130 p1 = *(px1++); p2 = *(px2++); INTERPOLATE_LINEAR(p1, p2, nx, *dpx); dpx++;
131
132 p1 = *(px1++); p2 = *(px2++); INTERPOLATE_LINEAR(p1, p2, nx, *dpx); dpx++;
133
134 p1 = *(px1); p2 = *(px2); INTERPOLATE_LINEAR(p1, p2, nx, *dpx);,
135
136 nx = x - 0.5; X = nx; nx -= X; sPtr = sPtrRowBgn + X; px1 = (TCHANNEL *) sPtr++; px2 = (TCHANNEL *) sPtr; dpx = (TCHANNEL *)dPtr;
137
138 p1 = *(px1++); p2 = *(px2++); INTERPOLATE_LINEAR(p1, p2, nx, *dpx); dpx++;
139
140 p1 = *(px1++); p2 = *(px2++); INTERPOLATE_LINEAR(p1, p2, nx, *dpx); dpx++;
141
142 p1 = *(px1++); p2 = *(px2++); INTERPOLATE_LINEAR(p1, p2, nx, *dpx); dpx++;
143
144 p1 = *(px1); p2 = *(px2); INTERPOLATE_LINEAR(p1, p2, nx, *dpx);)
145
146 free(tmpData);
147
148 return 0;
149 }
150
151 template<typename TPIXEL, typename TCHANNEL>
152 int TLinearFInt<TPIXEL, TCHANNEL>::resampleTo_1ch(TBitmap<TPIXEL, TCHANNEL> &dst) const {
153
154 if (srcData == NULL) {
155 return 1;
156 }
157
158 TPIXEL * const dstData = dst.getData();
159 if (dstData == NULL) {
160 return 2;
161 }
162
163 if (!isInitOk()) {
164 return 3;
165 }
166
167 unsigned origWidth = srcWidth;
168 unsigned origHeight = srcHeight;
169 unsigned dstWidth = dst.getWidth();
170 unsigned dstHeight = dst.getHeight();
171 unsigned tmpWidth = srcHeight;
172 unsigned tmpHeight = dstWidth;
173
174 TPIXEL * const tmpData = (TPIXEL *) malloc((unsigned long) (tmpWidth * tmpHeight * sizeof(TPIXEL)));
175 if (tmpData == NULL) {
176 return 3;
177 }
178
179 double xDelta = srcWidth / (double) dstWidth;
180 double xMin = xDelta / 2.0;
181 double yDelta = srcHeight / (double) dstHeight;
182 double yMin = yDelta / 2.0;
183
184 REINDEXED_INTERPOLATION_GENERAL_ALGORITHM(
185 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 p1; TCHANNEL p2; int X; double nx;,
186
187 nx = x + 0.5; X = nx; nx -= X; p1 = sPtrRowBgn[reindexer[X++]]; p2 = sPtrRowBgn[reindexer[X]]; INTERPOLATE_LINEAR(p1, p2, nx, *dPtr);,
188
189 nx = x - 0.5; X = nx; nx -= X; sPtr = sPtrRowBgn + X; p1 = *(sPtr++); p2 = *(sPtr); INTERPOLATE_LINEAR(p1, p2, nx, *dPtr);)
190
191 REINDEXED_INTERPOLATION_GENERAL_ALGORITHM(
192 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 p1; TCHANNEL p2; int X; double nx;,
193
194 nx = x + 0.5; X = nx; nx -= X; p1 = sPtrRowBgn[reindexer[X++]]; p2 = sPtrRowBgn[reindexer[X]]; INTERPOLATE_LINEAR(p1, p2, nx, *dPtr);,
195
196 nx = x - 0.5; X = nx; nx -= X; sPtr = sPtrRowBgn + X; p1 = *(sPtr++); p2 = *(sPtr); INTERPOLATE_LINEAR(p1, p2, nx, *dPtr);)
197
198 free(tmpData);
199
200 return 0;
201 }
202
203 } /* namespace appdemo */