• 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 
00165         Image copy() const;
00166 
00168 
00174 
00184         Image(Size, ImageFormat, unsigned char *, int srcBytesPerRow=-1);
00185         Image(int, int, ImageFormat, unsigned char *, int srcBytesPerRow=-1);
00186 
00188         Image();
00189 
00193         Image(const Image &other); 
00194 
00202         Image subImage(unsigned int x, unsigned int y, Size) const;
00203 
00208         const Image &operator=(const Image &other);
00209 
00211 
00218 
00227         inline unsigned char *operator()(unsigned int x, unsigned int y) const {
00228             return data + bytesPerPixel()*x + bytesPerRow()*y;
00229         }
00230 
00241         void copyFrom(const Image &);
00243 
00303         bool lock(int timeout = -1);
00304 
00306         void unlock();
00307 
00314         bool operator==(const Image &) const;
00315 
00319         void debug(const char *name="") const;
00320 
00322     private:
00323         Size _size;
00324         ImageFormat _type;
00325         unsigned int _bytesPerPixel;
00326         unsigned int _bytesPerRow;
00327 
00334         unsigned char *data;
00335         
00340         unsigned char *buffer;
00341 
00342         // Reference counting mechanisms
00343         unsigned int *refCount;
00344         pthread_mutex_t *mutex; 
00345 
00346         // Is this a weak reference to somebody else's data?
00347         bool weak() {
00348             return (buffer == NULL);
00349         }
00350 
00351         // Does this reference currently have the image locked?
00352         bool holdingLock;
00353 
00357         void setBuffer(unsigned char *b, unsigned char *d=NULL);
00358 
00359     };
00360 
00361 }
00362 
00366 #define FCAM_IMAGE_DEBUG(i) (i).debug(#i)
00367 
00368 #endif
00369 

Generated on Thu Jul 15 2010 17:51:28 for FCam by  doxygen 1.7.1