faithtools/faith/image.h

Go to the documentation of this file.
00001 #ifndef KDE__IMAGE_H
00002 #define KDE__IMAGE_H
00003 
00004 #include <faith/size.h>
00005 #include <faith/rect.h>
00006 
00007 namespace Faith
00008 {
00009 
00010 typedef unsigned int Rgb;
00011 
00012 
00013 
00020 inline int qRed(Faith::Rgb rgb)
00021 {
00022         return (rgb >> 16) & 0xff;
00023 }
00024 
00031 inline int qGreen(Faith::Rgb rgb)
00032 {
00033         return (rgb >> 8) & 0xff;
00034 }
00035 
00042 inline int qBlue(Faith::Rgb rgb)
00043 {
00044         return rgb & 0xff;
00045 }
00046 
00047 inline int qAlpha(Faith::Rgb rgb)
00048 {
00049         return (rgb >> 24) & 0xff;
00050 }
00051 
00060 inline Faith::Rgb qRgb(int red, int green, int blue, int alpha=0xff)
00061 {
00062         return (blue & 0xff)
00063                 | ((green & 0xff) << 8)
00064                 | ((red & 0xff) << 16)
00065                 | ((alpha & 0xff) << 24);
00066 }
00067 
00068 
00077 inline int qGray(int red, int green, int blue)
00078 {
00079         return ((red & 0xff)*11 + (green & 0xff)*16 + (blue & 0xff)*5) / 32;
00080 }
00081 
00088 inline int qGray(Faith::Rgb rgb)
00089 {
00090         return qGray(qRed(rgb), qGreen(rgb), qBlue(rgb));
00091 }
00092 
00093 
00094 class FAITH_TOOLS_EXPORT Image
00095 {
00096         struct KDEImageShared;
00097         mutable KDEImageShared *d;
00098 
00099 public:
00100         enum Endian
00101         {
00102                 IgnoreEndian,
00103                 BigEndian,
00104                 LittleEndian
00105         };
00106 
00107         Image();
00108         ~Image();
00109         Image(const Size &sz, int depth, int numColor = 0, Endian bitOrder = IgnoreEndian);
00110         Image(int w, int h, int depth, int numColor = 0, Endian bitOrder = IgnoreEndian);
00111         Image(const Image &copy);
00124         Image(unsigned char *data, int w, int h, int depth, int pitch, Endian bitOrder);
00125 
00126         Image(const char *filename);
00127 
00128         void create(int w, int h, int depth, int numColor = 0, Endian bitOrder = IgnoreEndian);
00129 
00130         Image &operator =(const Image &copy);
00131 
00132         bool operator ==(const Image &other) const;
00133         bool operator !=(const Image &other) const { return !operator==(other); }
00134 
00135         void detach();
00136 
00137         bool hasAlpha() const;
00141         void setAlpha(bool enabled);
00142 
00147         bool isNull() const;
00148 
00153         Faith::Image createAlphaMask() const;
00154 
00155         int width() const;
00156         int height() const;
00157 
00161         int pitch() const;
00162         int bytesPerLine() const { return pitch(); }
00163 
00164         int numBytes() const;
00165 
00169         int depth() const;
00170 
00174         Size size() const;
00178         Rect rect() const;
00179 
00184         unsigned char *scanLine(int i);
00185         const unsigned char *scanLine(int i) const;
00186         unsigned char *bits() { return scanLine(0); }
00187         const unsigned char *bits() const { return scanLine(0); }
00188 
00192         const unsigned char * const *jumpTable() const;
00193 
00194         
00202         unsigned int pixelIndex(int x, int y) const;
00203         
00207         Rgb pixel(int x, int y) const;
00208 
00217         void setPixel(int x, int y, unsigned int pixel);
00218 
00222         void reset();
00223 
00228         Rgb color(int i) const;
00229 
00230         void setColor(int i, Rgb color);
00231 
00232         void save(const char *filename) const;
00233 };
00234 
00235 
00236 typedef bool (*tryLoadImage)(Image &image, const char *filename);
00237 
00238 }
00239 
00240 #endif

Generated on Fri Sep 1 00:23:07 2006 for Faith by  doxygen 1.4.7