• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

include/FCam/Image.h

Go to the documentation of this file.
00001 #ifndef FCAM_IMAGE_H
00002 #define FCAM_IMAGE_H
00003 
00004 #include "Base.h"
00005 #include <stdio.h>
00006 #include <pthread.h>
00007 #include <string>
00008 
00012 namespace FCam {
00013 
00034     class Image {
00035     public:
00043 
00051         inline Size size() const {
00052             return _size;
00053         }
00054 
00056         inline unsigned int width() const {
00057             return _size.width;
00058         }
00059 
00061         inline unsigned int height() const {
00062             return _size.height;
00063         }
00064 
00067         inline ImageFormat type() const {
00068             return _type;
00069         }
00070 
00076         inline unsigned int bytesPerPixel() const {
00077             return _bytesPerPixel;
00078         }
00079 
00091         inline unsigned int bytesPerRow() const {
00092             return _bytesPerRow;
00093         }
00094 
00097         inline bool valid() const {
00098             return (data != Image::Discard && data != Image::AutoAllocate);
00099         }
00100 
00111         inline bool discard() const {
00112             return data == Image::Discard;
00113         }
00114 
00128         inline bool autoAllocate() const {
00129             return data == Image::AutoAllocate;
00130         }
00131 
00133 
00138         static unsigned char *Discard;
00139 
00145         static unsigned char *AutoAllocate;
00146 
00147         ~Image();
00148 
00156         Image(Size, ImageFormat);
00157         Image(int, int, ImageFormat);
00158 
00172     Image(int fd, int offset, Size, ImageFormat, bool writeThrough = false);
00173 
00180         Image copy() const;
00181 
00183 
00189 
00199         Image(Size, ImageFormat, unsigned char *, int srcBytesPerRow=-1);
00200         Image(int, int, ImageFormat, unsigned char *, int srcBytesPerRow=-1);
00201 
00203         Image();
00204 
00208         Image(const Image &other); 
00209 
00217         Image subImage(unsigned int x, unsigned int y, Size) const;
00218 
00223         const Image &operator=(const Image &other);
00224 
00226 
00233 
00242         inline unsigned char *operator()(unsigned int x, unsigned int y) const {
00243             return data + bytesPerPixel()*x + bytesPerRow()*y;
00244         }
00245 
00256         void copyFrom(const Image &);
00258 
00318         bool lock(int timeout = -1);
00319 
00321         void unlock();
00322 
00329         bool operator==(const Image &) const;
00330 
00334         void debug(const char *name="") const;
00335 
00337     private:
00338         Size _size;
00339         ImageFormat _type;
00340         unsigned int _bytesPerPixel;
00341         unsigned int _bytesPerRow;
00342 
00349         unsigned char *data;
00350         
00355         unsigned char *buffer;
00356         unsigned int bytesAllocated;
00357 
00358         // Reference counting mechanisms
00359         unsigned int *refCount;
00360         pthread_mutex_t *mutex; 
00361 
00362         // Is this a weak reference to somebody else's data?
00363         bool weak() {
00364             return (buffer == NULL);
00365         }
00366 
00367     // Is this a memory mapped image?
00368     bool memMapped;
00369 
00370         // Does this reference currently have the image locked?
00371         bool holdingLock;
00372 
00376         void setBuffer(unsigned char *b, unsigned char *d=NULL);
00377 
00378     };
00379 
00380 }
00381 
00385 #define FCAM_IMAGE_DEBUG(i) (i).debug(#i)
00386 
00387 #endif
00388 

Generated on Mon Aug 16 2010 14:25:45 for FCam by  doxygen 1.7.1