framebuffer.h

Go to the documentation of this file.
00001 /*
00002  * File: framebuffer.h - Bitmap memory representation
00003  * Project: GED - bitmap editor (ICP)
00004  * Author: Kamil Dudka, xdudka00
00005  * Team: xdudka00, xfilak01, xhefka00, xhradi08
00006  * Created: 2006-03-10
00007  */
00008 
00009 #ifndef FRAMEBUFFER_H
00010 #define FRAMEBUFFER_H
00011 
00015 struct Pixel {
00016         unsigned char red;
00017         unsigned char green;
00018         unsigned char blue;
00019         unsigned char alpha;    
00020 };
00021 
00025 struct BoxSize {
00026         int width;              
00027         int height;             
00028 
00032         BoxSize (): width(0), height(0) { }
00033 
00039         BoxSize (int x, int y): width(x), height(y) { }
00040 
00044         int nPixels () const { return width*height; }
00045 
00047         bool operator== (const BoxSize &b) const
00048         {
00049                 return
00050                         width == b.width &&
00051                         height == b.height;
00052         }
00054         bool operator!= (const BoxSize &b) const { return !operator==(b); }
00055 };
00056 
00060 struct Point {
00061         int x;          
00062         int y;          
00063 
00067         Point (): x(0), y(0) { }
00068 
00074         Point (int ix, int iy): x(ix), y(iy) { }
00075 
00077         bool operator== (const Point &p) const { return x==p.x && y==p.y; }
00078 
00080         bool operator!= (const Point &p) const { return x!=p.x || y!=p.y; }
00081 
00083         Point &operator+= (const Point &p)
00084         {
00085                 x += p.x;
00086                 y += p.y;
00087                 return  *this;
00088         }
00089 
00091         Point &operator-= (const Point &p)
00092         {
00093                 x -= p.x;
00094                 y -= p.y;
00095                 return *this;
00096         }
00097 };
00098 
00100 inline Point operator+ (const Point &a, const Point &b) {
00101         Point tmp (a);
00102         return tmp+=b;
00103 }
00104 
00106 inline Point operator- (const Point &a, const Point &b) {
00107         Point tmp (a);
00108         return tmp-=b;
00109 }
00110 
00114 struct Rect {
00115         Point at;               
00116         BoxSize size;           
00117 
00121         Rect () { }
00122 
00128         Rect (Point p, BoxSize s): at(p), size(s) { }
00129 
00131         bool operator== (const Rect &r) const
00132         {
00133                 return
00134                         at == r.at &&
00135                         size == r.size;
00136         }
00138         bool operator!= (const Rect &r) const { return !operator==(r); }
00139 };
00140 
00146 class FrameBuffer {
00147 public:
00152         FrameBuffer (): _pBuff(0) { }
00153 
00158         FrameBuffer (const BoxSize &fbSize): _pBuff(0) { size (fbSize); }
00159 
00163         FrameBuffer (const FrameBuffer &fb);
00164 
00168         FrameBuffer &operator= (const FrameBuffer &fb);
00169 
00173         ~FrameBuffer () { delete[] _pBuff; }
00174 
00181         Pixel *pBuff ();
00182 
00190         void setPixel (Point pos, Pixel color);
00191 
00199         Pixel *operator[] (int y)
00200         {
00201                 return pBuff() + y*_size.width;
00202         }
00203 
00207         const BoxSize &size () const { return _size; }
00208 
00213         void resize (const BoxSize &newSize);
00214 
00220         void size (const BoxSize &fbSize);
00221 
00225         const Rect &select () const { return _select; }
00226 
00231         void select (const Rect &selectRect);
00232 
00236         void unSelect ();
00237 
00241         class ErrUnalloc { };
00242 
00243         friend class SharedObject;              
00244         friend class SharedFrameBuffer;         
00245 
00246 protected:
00247         Pixel *_pBuff;                          
00248 
00249 private:
00250         BoxSize _size;
00251         Rect _select;
00252 };
00253 
00254 #endif

Generated on Wed Aug 29 00:01:04 2007 for GED 2006 by  doxygen 1.5.2