HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TIL_Raster.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: TIL_Raster.h (Tile Image Library, C++)
7  *
8  * COMMENTS:
9  * Defines a more generic raster for texture maps & display. This class
10  * is designed to be a raster container, not a raster manipulation class.
11  */
12 #ifndef TIL_RASTER_H
13 #define TIL_RASTER_H
14 
15 #include "TIL_API.h"
16 #include <PXL/PXL_Raster.h>
17 #include <UT/UT_VectorTypes.h>
18 #include <IMG/IMG_RasterFilter.h>
19 
20 #include "TIL_Defines.h"
21 
22 class IMG_Raster;
23 class UT_TokenString;
24 
25 #define TIL_RASTER_COMPLETE 0
26 #define TIL_RASTER_INCOMPLETE 1
27 #define TIL_RASTER_CORRUPT -1
28 
30 {
31 public:
32  TIL_Raster();
33  TIL_Raster(const TIL_Raster &);
34  TIL_Raster(const PXL_Raster &);
35  TIL_Raster(const IMG_Raster &, bool copy = true);
36  TIL_Raster(const TIL_Raster &,
37  exint x1, exint y1, exint x2, exint y2);
39  exint xres = 0, exint yres = 0, int clear = 0,
40  int alloc = 1);
41  ~TIL_Raster() override;
42 
43  int64 getMemoryUsage(bool inclusive) const override;
44 
45  // takes ownership.
46  void setID(UT_TokenString *token);
47  const UT_TokenString *getID() const { return myID; }
48 
49  void copy(const PXL_Raster &src) override;
50 
51  /// copies only the raster properties (res, type, etc), not the data, nor
52  /// does this method allocate memory for a raster.
53  void copyProperties(const PXL_Raster &src) override;
54 
55  // deletes the image memory. If full = 1, everything is reset - xres/yres
56  // to 0, packing and format to invalid.
57  void reset(int full = 0) override;
58 
59  // Scale this raster to another output raster.
60  // You can't do format conversions here.
61  void scaleFromRasterToSize(TIL_Raster *scaled,
62  exint xres,exint yres,
63  UT_FilterType flt=UT_FILTER_BOX) const;
64 
65  void scaleFromRasterToScale(TIL_Raster *scaled,
66  float xsc,float ysc,
67  UT_FilterType flt=UT_FILTER_BOX) const;
68 
69  /// Scales the source raster window to the destination window size and
70  /// inserts the result at (tox, toy) location of this raster. Incoming
71  /// coordinates and sizes should be compatible with the respective
72  /// rasters.
73  /// You can't do format conversions here.
74  void scaledInsertFromRaster(const PXL_Raster* source,
75  UT_FilterType ftype,
76  exint fromx, exint fromy,
77  exint fromsizex, exint fromsizey,
78  exint tox, exint toy,
79  exint tosizex, exint tosizey);
80 
81 
82  static void scaleRasterToSize(PXL_Raster *scaled,
83  const PXL_Raster *source,
84  exint xres, exint yres,
86  static void scaleRasterToScale(PXL_Raster *scaled,
87  const PXL_Raster *source,
88  float xsc, float ysc,
90 
91 
92 
93  // applyEmulation is like applyLUT but does not use a look up table and
94  // instead performs the calculations on each pixel.
95  // It is currently only implemented for FLOAT32 rasters, for anything else
96  // you should use applyLUT.
97  void applyEmulation(const TIL_Raster *src,
98  float black, float white,
99  float scale, float shift,
100  float gamma, exint comp = -1);
101 
102  void adjustGamma(float gamma,
103  bool red = true,
104  bool green = true,
105  bool blue = true,
106  bool alpha = false);
107 
108  // Raster diff functions. Source rasters must be the same format, packing
109  // and size as this raster.
110  void splitHRaster(const TIL_Raster *r1,
111  const TIL_Raster *r2, float fract);
112  void splitVRaster(const TIL_Raster *r1,
113  const TIL_Raster *r2, float fract);
114  void blendRaster(const TIL_Raster *r1,
115  const TIL_Raster *r2, float fract);
116  void diffRaster(const TIL_Raster *r1,const TIL_Raster *r2);
117  void subRaster(const TIL_Raster *r1,const TIL_Raster *r2);
118  void highlightRaster(const TIL_Raster *r1,
119  const TIL_Raster *r2, float threshold);
120 
121  void setUserData(void *data) { myUserData = data; }
122  void *getUserData() { return myUserData; }
123 
124  // returns true if an edge > tolerance was found within distance pixels
125  // of (x,y). The location of the edge is returned in (x,y). If dir and
126  // pos are specified, points along the dir vector from pos are favoured.
127  bool getClosestEdge(exint &x, exint &y, exint distance,
128  float tolerance = 0.1f,
129  UT_Vector2 *pos = 0,
130  UT_Vector2 *dir = 0);
131 
132  // TIL_RASTER_COMPLETE - raster is filled & okay
133  // TIL_RASTER_INCOMPLETE- raster was user-interrupted during construction.
134  // TIL_RASTER_CORRUPT - an error occurred during construction.
135  void setIncomplete(int inc = 1);
136  int isIncomplete() const { return myIncompleteState; }
137 
138 protected:
139  void attemptRealloc(int64 size) override;
140 
141  void initialize() override;
142 
143 private:
144  // optional.
145  UT_TokenString *myID;
146  void *myUserData;
147  int myIncompleteState;
148 };
149 
150 #endif
GLboolean * data
Definition: glcorearb.h:131
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
virtual void reset(int full=0)
int64 exint
Definition: SYS_Types.h:125
virtual void copy(const PXL_Raster &src)
virtual void attemptRealloc(int64 size)
GLint y
Definition: glcorearb.h:103
UT_FilterType
Definition: UT_FilterType.h:16
GLdouble GLdouble x2
Definition: glad.h:2349
int isIncomplete() const
Definition: TIL_Raster.h:136
#define TIL_Packing
Definition: TIL_Defines.h:73
GA_API const UT_StringHolder scale
virtual void initialize()
GLfloat f
Definition: glcorearb.h:1926
#define TIL_DataFormat
Definition: TIL_Defines.h:65
GLfloat green
Definition: glcorearb.h:112
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
GLdouble y1
Definition: glad.h:2349
const UT_TokenString * getID() const
Definition: TIL_Raster.h:47
long long int64
Definition: SYS_Types.h:116
void * getUserData()
Definition: TIL_Raster.h:122
GLfloat GLfloat GLfloat alpha
Definition: glcorearb.h:112
GLint GLenum GLint x
Definition: glcorearb.h:409
GLsizeiptr size
Definition: glcorearb.h:664
virtual void copyProperties(const PXL_Raster &src)
void setUserData(void *data)
Definition: TIL_Raster.h:121
GLfloat GLfloat blue
Definition: glcorearb.h:112
virtual int64 getMemoryUsage(bool inclusive) const
GLdouble GLdouble GLdouble y2
Definition: glad.h:2349
SIM_API const UT_StringHolder distance
#define TIL_API
Definition: TIL_API.h:10
png_structrp int png_fixed_point red
Definition: png.h:1083
Definition: format.h:895
GLenum src
Definition: glcorearb.h:1793