App

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

- File List
- File Members

TLUT.hpp
Go to the documentation of this file.
1 namespace app {
2 template<typename TPIXEL, typename TCHANNEL> class TLUT;
3 }
4
5
6
7 #ifndef TLUT_HPP_
8 #define TLUT_HPP_
9
10 #include <cstdlib>
11
12 #include "../typedefs.hpp"
13 #include "../bitmaps/TBitmap.hpp"
14
15 namespace app {
16
17 template<typename TPIXEL, typename TCHANNEL>
18 class TLUT {
19 protected:
20
21 TCHANNEL * values[4];
22 int initOk;
23
24 virtual int applyTo_4ch(TBitmap<TPIXEL, TCHANNEL> &dst, Rect dstRect);
25 virtual int applyTo_4ch(TBitmap<TPIXEL, TCHANNEL> &dst, Rect dstRect, double alpha);
26 virtual int applyTo_4ch(TBitmap<TPIXEL, TCHANNEL> &dst, const TBitmap<TCHANNEL, TCHANNEL> & msk, Rect mskRect, Point mskOrig);
27 virtual int applyTo_4ch(TBitmap<TPIXEL, TCHANNEL> &dst, const TBitmap<TCHANNEL, TCHANNEL> & msk, Rect mskRect, Point mskOrig, double alpha);
28
29 public:
30
31 static const unsigned chCount;
32 static const TCHANNEL maxVal;
33 static const unsigned numVals;
34
35 TLUT(int init = 0) {
36 int dim = (chCount <= 4) ? chCount : 4;
37 int i = 0;
38 initOk = 1;
39 while (i < dim) {
40 values[i] = (TCHANNEL *) malloc((unsigned long int) (numVals * sizeof(TCHANNEL))); // ANDROID_SPECIFIC přetypování v malloc
41 if (values[i] == NULL) {
42 initOk = 0;
43 }
44 if (init) {
45 if (i == 0) {
46 TCHANNEL * ptr = values[i];
47 TCHANNEL * ptrEnd = ptr + numVals;
48 TCHANNEL j = 0;
49 while (ptr < ptrEnd) {
50 *ptr = j++;
51 ptr++;
52 }
53 } else {
54 memcpy(values[i], values[0], (numVals) * sizeof(TCHANNEL));
55 }
56 }
57 i++;
58 }
59 if (initOk) {
60 while (i < 4) {
61 values[i] = NULL;
62 i++;
63 }
64 } else {
65 for (int i = 0; i < 4; i++) {
66 if (values[i] != NULL) {
67 free(values[i]);
68 values[i] = NULL;
69 }
70 }
71 }
72 }
73 virtual ~TLUT();
74
75 TCHANNEL ** getValues() {
76 return values;
77 }
78
79 int isInitOk() {
80 return initOk;
81 }
82
83 int applyTo(TBitmap<TPIXEL, TCHANNEL> &dst, Rect dstRect) {
84 switch (chCount) {
85 case 4:
86 return applyTo_4ch(dst, dstRect);
87 break;
88 default:
89 return 1000;
90 break;
91 }
92 }
93 int applyTo(TBitmap<TPIXEL, TCHANNEL> &dst, Rect dstRect, double alpha) {
94 switch (chCount) {
95 case 4:
96 return applyTo_4ch(dst, dstRect, alpha);
97 break;
98 default:
99 return 1000;
100 break;
101 }
102 }
103 int applyTo(TBitmap<TPIXEL, TCHANNEL> &dst, const TBitmap<TCHANNEL, TCHANNEL> & msk, Rect mskRect, Point mskOrig) {
104 switch (chCount) {
105 case 4:
106 return applyTo_4ch(dst, msk, mskRect, mskOrig);
107 break;
108 default:
109 return 1000;
110 break;
111 }
112 }
113 int applyTo(TBitmap<TPIXEL, TCHANNEL> &dst, const TBitmap<TCHANNEL, TCHANNEL> & msk, Rect mskRect, Point mskOrig, double alpha) {
114 switch (chCount) {
115 case 4:
116 return applyTo_4ch(dst, msk, mskRect, mskOrig, alpha);
117 break;
118 default:
119 return 1000;
120 break;
121 }
122 }
123
124 };
125
126 template<typename TPIXEL, typename TCHANNEL>
127 const unsigned TLUT<TPIXEL, TCHANNEL>::chCount = sizeof(TPIXEL) / sizeof(TCHANNEL);
128
129 template<typename TPIXEL, typename TCHANNEL>
130 const TCHANNEL TLUT<TPIXEL, TCHANNEL>::maxVal = ~0;
131
132 template<typename TPIXEL, typename TCHANNEL>
133 const unsigned TLUT<TPIXEL, TCHANNEL>::numVals = maxVal + 1;
134
135 } /* namespace app */
136 #endif /* TLUT_HPP_ */