App

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

- File List
- File Members

TNearestFInt.hpp
Go to the documentation of this file.
1
6 namespace app {
7 template<typename TPIXEL, typename TCHANNEL> class TNearestFInt;
8 }
9
10 #ifndef TNEARESTFINT_HPP_
11 #define TNEARESTFINT_HPP_
12
13 #include <cstdlib>
14 #include "../typedefs.hpp"
15 #include "../bitmaps/TBitmap.hpp"
16
17 #include "TFInterpolator.hpp"
18
19 namespace app {
20
21 template<typename TPIXEL, typename TCHANNEL>
22 class TNearestFInt : public TFInterpolator<TPIXEL, TCHANNEL>{
23 protected:
24 TPIXEL * srcData;
25 unsigned srcWidth;
26 unsigned srcHeight;
27
28 virtual int resampleTo_4ch(TBitmap<TPIXEL, TCHANNEL> &dst) const;
29 virtual int resampleTo_1ch(TBitmap<TPIXEL, TCHANNEL> &dst) const;
30
31
32 virtual TFInterpolator<TPIXEL, TCHANNEL> * newInstance(const TBitmap<TPIXEL, TCHANNEL> &over) const {
33 return new TNearestFInt<TPIXEL, TCHANNEL>(over);
34 }
35
36
37 public:
38 static const unsigned chCount;
39 static const TCHANNEL maxVal;
40
41 TNearestFInt(const TBitmap<TPIXEL, TCHANNEL> &over) {
42 srcData = over.getData();
43 srcWidth = over.getWidth();
44 srcHeight = over.getHeight();
45 }
46
47 virtual TPIXEL * getSrcData() const {
48 return srcData;
49 }
50
51 virtual unsigned getSrcWidth() const {
52 return srcWidth;
53 }
54 virtual unsigned getSrcHeight() const {
55 return srcHeight;
56 }
57
58 virtual ~TNearestFInt();
59
60 virtual int isInitOk() const {
61 return 1;
62 }
63
64 TPIXEL getAt(double x, double y) {
65 if (x >= 0 && y >= 0 && x < srcWidth && y < srcHeight) {
66 return srcData[((int)y) * srcWidth + (int)x];
67 } else {
68 return 0;
69 }
70 }
71 };
72
73 template<typename TPIXEL, typename TCHANNEL>
74 const unsigned TNearestFInt<TPIXEL, TCHANNEL>::chCount = sizeof(TPIXEL) / sizeof(TCHANNEL);
75
76 template<typename TPIXEL, typename TCHANNEL>
77 const TCHANNEL TNearestFInt<TPIXEL, TCHANNEL>::maxVal = ~0;
78
79 }
80 #endif