00001 #ifndef FCAM_IMAGE_H
00002 #define FCAM_IMAGE_H
00003
00004 #include "Base.h"
00005 #include <stdio.h>
00006 #include <pthread.h>
00007
00011 namespace FCam {
00012
00024 class Image {
00025 public:
00031 Size size;
00032
00038 ImageFormat type;
00039
00044 unsigned char * const data;
00045
00046
00051 static unsigned char *Discard;
00052
00058 static unsigned char *AutoAllocate;
00059
00060 ~Image();
00061
00069 Image(Size, ImageFormat);
00070 Image(int, int, ImageFormat);
00072
00078
00084 Image(Size, ImageFormat, unsigned char *);
00085 Image(int, int, ImageFormat, unsigned char *);
00086
00088 Image();
00089
00093 Image(const Image &other);
00095
00100 const Image &operator=(const Image &other);
00101
00114 void setData(unsigned char *);
00115
00117 void debug() const {
00118 printf("Image at %x with dimensions %d %d type %d data %x refCount %x = (%d), mutex %x, holdingLock %d\n",
00119 (unsigned)this,
00120 size.width, size.height,
00121 type,
00122 (unsigned)data,
00123 (unsigned)refCount,
00124 refCount ? *refCount : 0,
00125 (unsigned)mutex,
00126 (holdingLock ? 1 : 0));
00127 };
00128
00130 bool valid() {
00131 return (data != Image::Discard && data != Image::AutoAllocate);
00132 }
00133
00190 bool lock(int timeout = -1);
00191
00193 void unlock();
00194
00195 private:
00196 unsigned int *refCount;
00197 pthread_mutex_t *mutex;
00198
00199
00200 bool weak;
00201
00202
00203 bool holdingLock;
00204
00205 };
00206
00207 }
00208
00209 #endif
00210