PortablePixmap.hpp

Go to the documentation of this file.
00001 #ifndef LOPER_PORTABLEPIXMAP
00002 #define LOPER_PORTABLEPIXMAP
00003 
00014 #include "standard.hpp"
00015 #include <vector>
00016 #include <algorithm>
00017 #include "PortablePicture.hpp"
00018 #include "PortableBitmap.hpp"
00019 
00020 #ifndef UBYTE
00021 #define UBYTE unsigned char
00022 #endif
00023 
00024 
00025 
00026 class PortablePixel
00027 {
00028 public:
00029 
00030     PortablePixel() {}
00031     PortablePixel (UBYTE r, UBYTE g, UBYTE b)
00032     {
00033         this->red = r;
00034         this->green = g;
00035         this->blue = b;
00036     }
00037 
00038     UBYTE & operator[](int index) { return (&red)[index]; }
00039 
00040     void operator*=(float f)
00041     {
00042         red   = (UBYTE)(f * red);
00043         green = (UBYTE)(f * green);
00044         blue  = (UBYTE)(f * blue);
00045     }
00046 
00047     PortablePixel operator* (float f)
00048     {
00049         PortablePixel result = *this;
00050         result *= f;
00051         return result;
00052     }
00053 
00054 
00055     void operator+=(const PortablePixel &p)
00056     {
00057         red   += p.red;
00058         green += p.green;
00059         blue  += p.blue;
00060     }
00061 
00062     PortablePixel operator+ (const PortablePixel &p)
00063     {
00064         PortablePixel result = *this;
00065         result += p;
00066 
00067         return result;
00068     }
00069 
00070     UBYTE red, green, blue; 
00071 };
00072 
00073 
00074 
00075 
00076 class PortablePixmap : public PortablePicture< PortablePixel >
00077 {
00078 public:
00079 
00080     PortablePixmap ();
00081     PortablePixmap (int width, int height) { resize (width, height); }
00082 
00083 /*
00084  * File operations
00085  */
00086     void loadFromFile (const char *filename);
00087     void loadFromFileRescaled (const char *filename);
00088     void saveAsPpm (const char *filename);
00089     PortablePixmap(const char *filename) { loadFromFile(filename); }
00090 
00091 /*
00092  * Mutators
00093  */
00094 
00095     void setToBlack() { pixels.assign(pixels.size(), PortablePixel(0,0,0)); } 
00096 /*
00097  * Image processing
00098  */
00099     PortablePixmap getDilatedImage() const;
00100     PortablePixmap getInvertedImage();
00101     PortableBitmap getThresholdedImage (int thresh) const;
00102     PortableBitmap getAdaptivelyThresholdedImage();
00103     PortablePixmap getSubImage (int left, int top, int width, int height) const;
00104     PortablePixmap getBoxBlurredImage(int filterWidth, int filterHeight);
00105 
00106     void getFramedImage(PortablePixmap & imgOut) const;
00107 
00108     void getRescaledImage(PortablePixmap &imgOut) const;
00109 
00110     PortablePixmap getEdgeDetectedImage();
00111     PortablePixel getModeBrightness();
00112     PortablePixel getInterpolated (float row, float col) const;
00113 };
00114 
00115 #endif // LOPER_PORTABLEPIXMAP

Generated on Mon May 26 11:19:28 2003 for CamChecker by doxygen1.3