App

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

- File List
- File Members

TNearestFInt.cpp
Go to the documentation of this file.
1
6 #include "TNearestFInt.hpp"
7
8 namespace app {
9
10 template class TNearestFInt<px_1x8bit, px_1x8bit> ;
11 template class TNearestFInt<px_4x8bit, px_1x8bit> ;
12
13 template<typename TPIXEL, typename TCHANNEL>
14 TNearestFInt<TPIXEL, TCHANNEL>::~TNearestFInt() {
15 }
16
17 template<typename TPIXEL, typename TCHANNEL>
18 int TNearestFInt<TPIXEL, TCHANNEL>::resampleTo_4ch(TBitmap<TPIXEL, TCHANNEL> &dst) const {
19 return resampleTo_1ch(dst);
20 }
21
22 template<typename TPIXEL, typename TCHANNEL>
23 int TNearestFInt<TPIXEL, TCHANNEL>::resampleTo_1ch(TBitmap<TPIXEL, TCHANNEL> &dst) const {
24
25 TPIXEL * sPtr;
26 if (srcData == NULL) {
27 return 2;
28 }
29
30 unsigned dstWidth = dst.getWidth();
31 unsigned dstHeight = dst.getHeight();
32 TPIXEL * dstData = dst.getData();
33 if (dstData == NULL) {
34 return 3;
35 }
36 TPIXEL * dPtr = (TPIXEL *) dstData;
37 TPIXEL * dPtrRowEnd = (TPIXEL *) (dstData + dstWidth);
38 TPIXEL * dPtrEnd = (TPIXEL *) (dstData + dstWidth * dstHeight);
39
40 double dx = srcWidth / (double) dstWidth;
41 double x0 = dx / 2.0;
42 double x = x0;
43 double dy = srcHeight / (double) dstHeight;
44 double y0 = dy / 2.0;
45 double y = y0;
46
47 while (dPtr < dPtrEnd) {
48 x = x0;
49 sPtr = srcData + srcWidth * ((int) y);
50 while (dPtr < dPtrRowEnd) {
51 *dPtr = sPtr[(int) x];
52 dPtr++;
53 x += dx;
54 }
55 y += dy;
56 dPtrRowEnd += dstWidth;
57 }
58
59 return 0;
60 }
61
62 } /* namespace appdemo */