00001 #ifndef FCAM_BASE_H
00002 #define FCAM_BASE_H
00003
00004 #include <stdlib.h>
00005
00018 namespace FCam {
00019
00021 typedef enum {
00023 RGB24 = 0,
00024
00027 RGB16,
00028
00036 UYVY,
00037
00039 YUV24,
00040
00046 RAW,
00047
00049 UNKNOWN} ImageFormat;
00050
00052 int bytesPerPixel(ImageFormat);
00053
00056 struct Size {
00058 Size() : width(0), height(0) {}
00059
00061 Size(int w, int h) : width(w), height(h) {}
00062
00064 bool operator==(const Size &other) const {return width == other.width && height == other.height;}
00065
00067 bool operator!=(const Size &other) const {return width != other.width || height != other.height;}
00068
00069 int width;
00070 int height;
00071 };
00072
00074 struct Rect {
00076 Rect() : x(0), y(0), width(0), height(0) {}
00077
00080 Rect(int x_, int y_, int w_, int h_) : x(x_), y(y_), width(w_), height(h_) {}
00081
00083 bool operator==(const Rect &other) const {
00084 return (width == other.width &&
00085 height == other.height &&
00086 x == other.x &&
00087 y == other.y);
00088 }
00089
00091 bool operator!=(const Rect &other) const {
00092 return (width != other.width ||
00093 height != other.height ||
00094 x != other.x ||
00095 y != other.y);
00096 }
00097
00098 int x;
00099 int y;
00100 int width;
00101 int height;
00102 };
00103
00108 class HistogramConfig {
00109 public:
00112 HistogramConfig() : buckets(64), regions(0) {}
00113
00116 Rect region[4];
00117
00120 unsigned char buckets;
00121
00125 unsigned char regions;
00126
00129 bool operator==(const HistogramConfig &other) const {
00130 if (regions != other.regions) return false;
00131 if (buckets != other.buckets) return false;
00132 for (int i = 0; i < regions; i++) {
00133 if (region[i] != other.region[i]) return false;
00134 }
00135 return true;
00136 }
00137
00140 bool operator!=(const HistogramConfig &other) const {
00141 return !((*this) == other);
00142 }
00143 };
00144
00148 class SharpnessMapConfig {
00149 public:
00152 SharpnessMapConfig() : size(0, 0), enabled(false) {}
00153
00156 Size size;
00157
00159 bool enabled;
00160
00163 bool operator==(const SharpnessMapConfig &other) const {
00164 if (enabled != other.enabled) return false;
00165 if (enabled && size != other.size) return false;
00166 return true;
00167 }
00168
00171 bool operator!=(const SharpnessMapConfig &other) const {
00172 return !((*this) == other);
00173 }
00174 };
00175
00181 class Histogram : public HistogramConfig {
00182 public:
00183
00186 Histogram(): valid(false), channels(0), data(NULL) {
00187 }
00188
00197 unsigned operator()(int x, int c) {
00198 if (!valid) return 0;
00199 return data[buckets*c + x];
00200 }
00201
00204 unsigned operator()(int x) {
00205 if (!valid) return 0;
00206 unsigned result = 0;
00207 for (size_t c = 0; c < channels; c++)
00208 result += (*this)(x, c);
00209 return result;
00210 }
00211
00214 bool valid;
00215
00217 unsigned channels;
00218
00222 unsigned *data;
00223 };
00224
00229 class SharpnessMap : public SharpnessMapConfig {
00230 public:
00231
00233 SharpnessMap(): valid(false), channels(0), data(NULL) {
00234 }
00235
00244 unsigned operator()(int x, int y, int c) {
00245 return data[(y*size.width+x)*12 + c*4 + 1];
00246 }
00247
00250 unsigned operator()(int x, int y) {
00251 unsigned total = 0;
00252 for (size_t c = 0; c < channels; c++) {
00253 total += (*this)(x, y, c);
00254 }
00255 return total;
00256 }
00257
00259 bool valid;
00260
00262 unsigned channels;
00263
00277 unsigned *data;
00278 };
00279
00280 }
00281
00282
00283 #endif