00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef PXL_RASTER_H
00021 #define PXL_RASTER_H
00022
00023 #include <iostream.h>
00024 #include <UT/UT_Rect.h>
00025 #include "PXL_API.h"
00026 #include "PXL_Common.h"
00027 #include <UT/UT_SmallObject.h>
00028
00029 class UT_IStream;
00030
00031 #define PXL_ROFF 16
00032
00033 enum PXL_StreakComponents {
00034 PXL_STREAK_ALL = 0,
00035 PXL_STREAK_RGB,
00036 PXL_STREAK_A
00037 };
00038
00039 class PXL_API PXL_Raster
00040 : public UT_SmallObject<PXL_Raster,
00041 UT_SMALLOBJECT_CLEANPAGES_OFF, 250,
00042 UT_SMALLOBJECT_THREADSAFE_ON>
00043 {
00044 public:
00045 PXL_Raster();
00046 PXL_Raster(const PXL_Raster &);
00047 PXL_Raster(const PXL_Raster &,
00048 int x1, int y1, int x2, int y2);
00049 PXL_Raster(PXL_Packing p, PXL_DataFormat f,
00050 int xres = 0, int yres = 0, int clear = 0,
00051 int alloc = 1);
00052 virtual ~PXL_Raster();
00053
00054
00055
00056 virtual void copy(const PXL_Raster &src);
00057
00058
00059
00060 void setPacking(PXL_Packing p);
00061 void setFormat(PXL_DataFormat f);
00062 void setRes(int x, int y);
00063 void setBWPoints(float black, float white);
00064
00065 void init();
00066
00067
00068
00069 void setRaster(void *r, bool give_ownership = true,
00070 bool use_offset = false);
00071
00072
00073
00074 void * steal();
00075
00076
00077 int isValid() const { return myRaster ? 1 : 0; }
00078
00079 int getXres() const { return myXres; }
00080 int getYres() const { return myYres; }
00081 int getNumPixels() const { return myXres * myYres; }
00082 int64 getStride() const { return myStride; }
00083 int64 getSize() const { return myRasterSize; }
00084 PXL_DataFormat getFormat() const { return myFormat; }
00085 PXL_Packing getPacking() const { return myPacking; }
00086 void getBWPoints(float &black, float &white) const;
00087
00088
00089 void setDataWindow(const UT_DimRect &new_rect);
00090 const UT_DimRect & getDataWindow() const
00091 { return myDataWindow; }
00092 bool hasDataWindow() const
00093 { return !myDataWindow.isEmpty(); }
00094
00095
00096
00097
00098
00099 void getRange(float &min, float &max,
00100 float black = 0.0f, float white = 1.0f,
00101 int comp = -1,
00102 bool ignore_farthest = false) const;
00103
00104
00105 void * getPixels()
00106 { return (unsigned char *)myRaster+myRasterOffset; }
00107
00108 const void * getPixels() const
00109 { return (unsigned char *)myRaster+myRasterOffset; }
00110
00111
00112 const void * getRawPixels() const
00113 { return myRaster; }
00114
00115
00116 void * getPixel(int x, int y, int comp = 0);
00117 const void * getPixel(int x, int y, int comp = 0) const;
00118
00119 void getPixelValue(int x, int y, float *vals) const;
00120
00121
00122 int isInterleaved() const;
00123
00124
00125 int areComponentsRenderable() const;
00126
00127
00128 int64 getNonInterleavedSize() const;
00129
00130
00131
00132
00133
00134
00135 void clear(void *color = 0);
00136 void clearNormal(float *color,
00137 unsigned ib = 0,
00138 unsigned iw = 0);
00139
00140
00141
00142
00143 void readFromRow(int y, void *data) const;
00144
00145
00146
00147 void writeToRow(int y, const void *data);
00148
00149
00150
00151
00152 void writeToColumn(int x, const void *data);
00153
00154
00155
00156 virtual void reset(int full = 0);
00157
00158 void extract(const PXL_Raster &from,
00159 int x1, int y1, int x2, int y2);
00160
00161 void applyLUT(const PXL_Raster *src, float *lptr[4],
00162 int comp, float lstart, float lend);
00163
00164 void streakEdges(int x1,int y1, int x2,int y2,
00165 PXL_StreakComponents streak_comps = PXL_STREAK_ALL);
00166 void convert8Bit(unsigned b, unsigned w);
00167
00168 void adjustSaturation(float sat);
00169
00170 bool load(UT_IStream &is);
00171 int save(ostream &os, int binary = 1) const;
00172
00173 int getProxyIndex() const { return myProxyIndex; }
00174
00175 void setDataWritten(bool written = true)
00176 { myWriteFlag = written; }
00177 bool getDataWritten() const { return myWriteFlag; }
00178
00179 void setTextureID(unsigned int id) { myTextureID = id; }
00180 unsigned int getTextureID() const;
00181 void clearTextureID();
00182
00183
00184
00185
00186 void dither(const UT_DimRect &crop);
00187 void dither();
00188
00189 protected:
00190 virtual void initialize();
00191 void allocRaster(int alloc_mem = 1);
00192
00193 void applyLUT8(const PXL_Raster *src, float *lptr[4],
00194 int comp, float lscale, float lshift,
00195 int size);
00196 void applyLUT16(const PXL_Raster *src, float *lptr[4],
00197 int comp, float lscale, float lshift,
00198 int size);
00199
00200 virtual void attemptRealloc(int64 size);
00201
00202 PXL_DataFormat myFormat;
00203 PXL_Packing myPacking;
00204 unsigned int myRasterOffset;
00205 int myXres, myYres;
00206 int64 myStride;
00207 int64 myRasterSize;
00208 float myBlack, myWhite;
00209 void *myRaster;
00210 bool myAmOwner;
00211 int myProxyIndex;
00212 bool myWriteFlag;
00213 unsigned int myTextureID;
00214
00215 UT_DimRect myDataWindow;
00216 };
00217 #endif