App
THistogram.hpp
Go to the documentation of this file.
1 
6 // forward declaration
7 namespace app {
8  template <typename TPIXEL, typename TCHANNEL> class THistogram;
9 }
10 
11 #ifndef THISTOGRAM_HPP_
12 #define THISTOGRAM_HPP_
13 
14 #include <cstdlib>
15 
16 #include "../typedefs.hpp"
17 #include "../bitmaps/TBitmap.hpp"
18 
21 
22 namespace app {
23 
25 
29 template <typename TPIXEL, typename TCHANNEL>
30 class THistogram {
31 protected:
33 
41  unsigned * data[5];
42  int calcErr;
43  unsigned maxIndex;
44 
46 
51  virtual int calculate_4ch(const TBitmap<TPIXEL, TCHANNEL> &bitmap);
52 
54 
59  virtual int calculate_1ch(const TBitmap<TPIXEL, TCHANNEL> &bitmap);
60 
61 
62 public:
63  static const TCHANNEL maxVal;
64  static const unsigned valsCount;
65  static const unsigned factor;
66  static const unsigned chCount;
67 
69 
74  switch (chCount) {
75  case 1:
76  data[0] = (unsigned *) malloc((unsigned long int)(valsCount * sizeof(unsigned))); // ANDROID_SPECIFIC přetypování v malloc
77  data[1] = NULL;
78  data[2] = NULL;
79  data[3] = NULL;
80  data[4] = NULL;
81  calcErr = calculate_1ch(bitmap);
82  maxIndex = 0;
83  break;
84  case 4:
85  data[0] = (unsigned *) malloc((unsigned long int)(valsCount * sizeof(unsigned))); // ANDROID_SPECIFIC přetypování v malloc
86  data[1] = (unsigned *) malloc((unsigned long int)(valsCount * sizeof(unsigned))); // ANDROID_SPECIFIC přetypování v malloc
87  data[2] = (unsigned *) malloc((unsigned long int)(valsCount * sizeof(unsigned))); // ANDROID_SPECIFIC přetypování v malloc
88  data[3] = (unsigned *) malloc((unsigned long int)(valsCount * sizeof(unsigned))); // ANDROID_SPECIFIC přetypování v malloc
89  data[4] = (unsigned *) malloc((unsigned long int)(valsCount * sizeof(unsigned))); // ANDROID_SPECIFIC přetypování v malloc
90  calcErr = calculate_4ch(bitmap);
91  maxIndex = 4;
92  break;
93  default:
94  break;
95  }
96  }
97 
99 
104  unsigned * getChannel(unsigned index) {
105  if (calcErr || index > maxIndex) { return NULL; }
106  return data[index];
107  }
108 
110  virtual ~THistogram();
111 };
112 
113 template <typename TPIXEL, typename TCHANNEL>
114 const TCHANNEL THistogram<TPIXEL, TCHANNEL>::maxVal = ~0;
115 
116 template <typename TPIXEL, typename TCHANNEL>
117 const unsigned THistogram<TPIXEL, TCHANNEL>::valsCount = 128;
118 
119 template <typename TPIXEL, typename TCHANNEL>
120 const unsigned THistogram<TPIXEL, TCHANNEL>::factor = (maxVal + 1) / valsCount;
121 
122 template <typename TPIXEL, typename TCHANNEL>
123 const unsigned THistogram<TPIXEL, TCHANNEL>::chCount = sizeof(TPIXEL) / sizeof(TCHANNEL);
124 
125 } /* namespace app */
126 #endif /* THISTOGRAM_HPP_ */