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 "TIL_Defines.h"
17 #include <PXL/PXL_Raster.h>
18 #include <UT/UT_FilterType.h>
19 #include <UT/UT_VectorTypes.h>
20 #include <SYS/SYS_Types.h>
21 
22 
23 class IMG_Raster;
24 class UT_TokenString;
25 
26 #define TIL_RASTER_COMPLETE 0
27 #define TIL_RASTER_INCOMPLETE 1
28 #define TIL_RASTER_CORRUPT -1
29 
31 {
32 public:
33  TIL_Raster();
35  TIL_Raster(const PXL_Raster &raster);
36  TIL_Raster(const IMG_Raster &raster, bool copy = true);
37  TIL_Raster(const TIL_Raster &raster,
38  exint x1, exint y1, exint x2, exint y2);
40  exint xres = 0, exint yres = 0, int clear = 0,
41  int alloc = 1);
42  ~TIL_Raster() override;
43 
44  int64 getMemoryUsage(bool inclusive) const override;
45 
46  // takes ownership.
47  void setID(UT_TokenString *token);
48  const UT_TokenString *getID() const { return myID; }
49 
50  void copy(const PXL_Raster &src) override;
51 
52  /// copies only the raster properties (res, type, etc), not the data, nor
53  /// does this method allocate memory for a raster.
54  void copyProperties(const PXL_Raster &src) override;
55 
56  /// Transfers the raster to a PXL_Raster. Data is moved and no longer owned.
57  UT_UniquePtr<PXL_Raster> moveToPXL();
58  /// Grabs the raster from a PXL_Raster. Data is moved and no longer owned by
59  /// 'raster'.
60  static UT_UniquePtr<TIL_Raster> moveFromPXL(PXL_Raster *raster);
61 
62  // deletes the image memory. If full = 1, everything is reset - xres/yres
63  // to 0, packing and format to invalid.
64  void reset(int full = 0) override;
65 
66  // Scale this raster to another output raster.
67  // You can't do format conversions here.
68  void scaleFromRasterToSize(TIL_Raster *scaled,
69  exint xres,exint yres,
71  bool try_preserve_bit_values=false) const;
72 
73  void scaleFromRasterToScale(TIL_Raster *scaled,
74  float xsc,float ysc,
76  bool try_preserve_bit_values=false) const;
77 
78  /// Scales the source raster window to the destination window size and
79  /// inserts the result at (tox, toy) location of this raster. Incoming
80  /// coordinates and sizes should be compatible with the respective
81  /// rasters.
82  /// You can't do format conversions here.
83  void scaledInsertFromRaster(const PXL_Raster* source,
84  UT_FilterType ftype,
85  exint fromx, exint fromy,
86  exint fromsizex, exint fromsizey,
87  exint tox, exint toy,
88  exint tosizex, exint tosizey);
89 
90 
91  static void scaleRasterToSize(PXL_Raster *scaled,
92  const PXL_Raster *source,
93  exint xres, exint yres,
95  bool try_preserve_bit_values=false);
96  static void scaleRasterToScale(PXL_Raster *scaled,
97  const PXL_Raster *source,
98  float xsc, float ysc,
100 
101 
102 
103  // applyEmulation is like applyLUT but does not use a look up table and
104  // instead performs the calculations on each pixel.
105  // It is currently only implemented for FLOAT32 rasters, for anything else
106  // you should use applyLUT.
107  void applyEmulation(const TIL_Raster *src,
108  float black, float white,
109  float scale, float shift,
110  float gamma, exint comp = -1);
111 
112  void adjustGamma(float gamma,
113  bool red = true,
114  bool green = true,
115  bool blue = true,
116  bool alpha = false);
117 
118  // Raster diff functions. Source rasters must be the same format, packing
119  // and size as this raster.
120  void splitHRaster(const TIL_Raster *r1,
121  const TIL_Raster *r2, float fract);
122  void splitVRaster(const TIL_Raster *r1,
123  const TIL_Raster *r2, float fract);
124  void blendRaster(const TIL_Raster *r1,
125  const TIL_Raster *r2, float fract);
126  void diffRaster(const TIL_Raster *r1,const TIL_Raster *r2);
127  void subRaster(const TIL_Raster *r1,const TIL_Raster *r2);
128  void highlightRaster(const TIL_Raster *r1,
129  const TIL_Raster *r2, float threshold);
130 
131  void setUserData(void *data) { myUserData = data; }
132  void *getUserData() { return myUserData; }
133 
134  // returns true if an edge > tolerance was found within distance pixels
135  // of (x,y). The location of the edge is returned in (x,y). If dir and
136  // pos are specified, points along the dir vector from pos are favoured.
137  bool getClosestEdge(exint &x, exint &y, exint distance,
138  float tolerance = 0.1f,
139  UT_Vector2 *pos = 0,
140  UT_Vector2 *dir = 0);
141 
142  // TIL_RASTER_COMPLETE - raster is filled & okay
143  // TIL_RASTER_INCOMPLETE- raster was user-interrupted during construction.
144  // TIL_RASTER_CORRUPT - an error occurred during construction.
145  void setIncomplete(int inc = 1);
146  int isIncomplete() const { return myIncompleteState; }
147 
148 protected:
149  void attemptRealloc(int64 size) override;
150 
151  void initialize() override;
152 
153 private:
154  // optional.
155  UT_TokenString *myID = nullptr;
156  void *myUserData;
157  int myIncompleteState;
158 };
159 
160 #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
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
int isIncomplete() const
Definition: TIL_Raster.h:146
#define TIL_Packing
Definition: TIL_Defines.h:72
GA_API const UT_StringHolder scale
virtual void initialize()
GLfloat f
Definition: glcorearb.h:1926
#define TIL_DataFormat
Definition: TIL_Defines.h:64
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:48
HUSD_API const char * raster()
long long int64
Definition: SYS_Types.h:116
void * getUserData()
Definition: TIL_Raster.h:132
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:131
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:1821
GLenum src
Definition: glcorearb.h:1793