00001
00015 #ifndef __VU_FIXELMAP_H__
00016 #define __VU_FIXELMAP_H__
00017
00018 #include <stddef.h>
00019 #include <fstream.h>
00020 #include "vuSimpleTypes.h"
00021 #include "vuFixel.h"
00022 #include <GL/gl.h>
00023
00024 class vuFixelMap_ST
00025 {
00026 public:
00027 virtual const void* getBuffer() const = 0;
00028 virtual void* getBuffer() = 0;
00029 virtual dword getWidth() const = 0;
00030 virtual dword getHeight() const = 0;
00031 };
00032
00033 template <int SIZE, class TYPE>
00034 class vuFixelMap : public vuFixelMap_ST{
00035 private:
00036 TYPE *m_buffer;
00037 bool m_isBufferNewed;
00038 dword m_width;
00039 dword m_height;
00040
00041 public:
00042
00043 vuFixelMap();
00044
00045 vuFixelMap(dword width, dword height);
00046
00047
00048 virtual ~vuFixelMap();
00049
00050
00051 vuFixelMap(const vuFixelMap &other);
00052
00053
00054 void setWidthAndHeight(const dword sizx, const dword sizy);
00055
00056 dword getWidth() const;
00057
00058 dword getHeight() const;
00059
00060
00061 void setFixel(dword x, dword y, const vuFixel<SIZE,TYPE> &fixel);
00062
00063 vuFixel<SIZE,TYPE> getFixel(dword x, dword y);
00064
00065
00066 const TYPE* getBuffer() const;
00067
00068 TYPE* getBuffer();
00069
00070
00071 void getMinAndMaxValue(TYPE &minValue, TYPE &maxValue);
00072
00073 void getMinAndMaxValue(TYPE &minValue, TYPE &maxValue, word channel);
00074
00075 void scaleAndBias(float scale, TYPE bias = 0);
00076
00077 void copyMapToChannel(vuFixelMap<1,TYPE> *map, word channel=0);
00078
00080 void getChannel(vuFixelMap<1,TYPE>* &map, word channel);
00081
00082 void clear(vuFixel<SIZE,TYPE> clearColour);
00083
00084 bool hasSameDimensions(vuFixelMap_ST *other);
00085
00086
00087
00088
00090 void initOpenGL(void);
00091
00093 void glResize(dword width, dword height);
00094
00096 void glRender();
00097
00098
00099
00100
00101 vuFixelMap &operator=(const vuFixelMap &other);
00102
00103 vuFixelMap &operator=(const vuFixel<SIZE,TYPE> &fixel);
00104
00105
00106 vuFixelMap &operator+=(vuFixelMap &other);
00107
00108 vuFixelMap &operator-=(vuFixelMap &other);
00109
00110 vuFixelMap &operator+=(float bias);
00111
00112 vuFixelMap &operator-=(float bias);
00113
00114 vuFixelMap &operator*=(float scale);
00115
00116 vuFixelMap &operator/=(float scale);
00117
00118 bool writeToFileStream(ostream *out);
00119
00120 bool readFromFileStream(istream *in, dword width, dword height);
00121
00122 void assignBuffer(TYPE *buffer, dword width, dword height);
00123
00124 void writeBufferToFile(FILE *file);
00125
00126
00127
00128 void _shearX(float shear, vuFixelMap<SIZE,TYPE>* inMap,
00129 vuFixelMap<SIZE,TYPE>* &outMap);
00130 void _shearY(float shear, vuFixelMap<SIZE,TYPE>* inMap,
00131 vuFixelMap<SIZE,TYPE>* &outMap);
00132
00133 void rotate90();
00134 void rotate180();
00135 void rotate270();
00136
00137 void rotate(float angle);
00138
00139 inline dword index(dword width, dword height)
00140 {
00141 return (height * m_width + width) * SIZE;
00142 }
00143
00144
00145
00146
00147
00148
00149
00150 ostream &write(ostream& os);
00151
00152 istream &read(istream& is);
00153
00154 private:
00155 void _ensureBuffer(dword sizx, dword sizy, const TYPE* source=NULL);
00156 };
00157
00158 template class vuFixelMap<1,byte>;
00159 template class vuFixelMap<2,byte>;
00160 template class vuFixelMap<3,byte>;
00161
00162 template class vuFixelMap<1,float>;
00163 template class vuFixelMap<2,float>;
00164 template class vuFixelMap<3,float>;
00165
00166
00167 typedef vuFixelMap<1,byte> vuFixelMap1B;
00168 typedef vuFixelMap<2,byte> vuFixelMap2B;
00169 typedef vuFixelMap<3,byte> vuFixelMap3B;
00170
00171 typedef vuFixelMap<1,float> vuFixelMap1F;
00172 typedef vuFixelMap<2,float> vuFixelMap2F;
00173 typedef vuFixelMap<3,float> vuFixelMap3F;
00174
00175 #endif