HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IMG_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: IMG_Raster.h ( IMG Library, C++)
7  *
8  * COMMENTS:
9  * IMG_Raster is the utility class for containing a 2D raster.
10  *
11  * UT_DeepRaster contains 16 bit channels and is useful for maintaining
12  * extra color precision at low alpha values. Composite operations are
13  * provided in the IMG_Raster class for compositing both IMG_Raster's and
14  * IMG_DeepRaster's.
15  */
16 
17 #ifndef __IMG_Raster__
18 #define __IMG_Raster__
19 
20 #include "IMG_API.h"
21 #include "IMG_RasterTypes.h"
22 #include <UT/UT_FilterType.h>
23 #include <UT/UT_Raster.h>
24 #include <iosfwd>
25 
26 #define DEEP_OPS
27 
28 class UT_Color;
29 class UT_IStream;
30 class UT_ThreadSet;
31 class IMG_RasterHSVA;
32 class img_ioState;
33 class img_lineptrs;
34 
36 public:
37  float lightPos[3]; // Light position (should be +Z)
38  float lightColot[3]; // Light color (currently not used)
39 
40  float ambient; // Ambient contribution
41  float diffuse; // Diffuse coefficient
42  float specular; // Specular coefficient
43  float shiny; // Phong coefficient
44 
45  float bumpScale; // Scale of embossing
46 };
47 
48 //==========================================================================
49 
51 {
52 public:
53  IMG_Raster();
54  IMG_Raster(short xres, short yres, UT_RasterDepth depth);
55  IMG_Raster(short xres, short yres, UT_RGBA *image = 0);
56  IMG_Raster(short xres, short yres, UT_BIG_RGBA *image);
57  IMG_Raster(const IMG_Raster &r);
58  ~IMG_Raster() override;
59 
60  void setAlpha(float alpha);
61  void setCompositeOp(IMG_CompositeOp op);
62  IMG_CompositeOp getCompositeOp() const { return compositeOp; }
63 
64  void compositePixel(UT_RGBA *dest, UT_RGBA *op)
65  { (*compositebit_8_8)(dest, op, 1); }
66 
68  { (*compositebit_8_16)(dest, op, 1); }
69 
71  { (*compositebit_16_16)(dest, op, 1); }
72 
74  { (*compositebit_16_8)(dest, op, 1); }
75 
76  void composite(IMG_Raster *r, short x = 0, short y = 0);
77 
78  void filter(IMG_FilterOp op,
79  float arg = 0.5,
80  short x = 0,
81  short y = 0,
82  short w = 0, // Implies clip_w
83  short h = 0); // Implies clip_h
84  // Apply a filter in-place...
85  void convolveFilter(UT_FilterType xfilter, float xwidth,
86  UT_FilterType yfilter, float ywidth);
87 //
88 // Calling crop actually changes the size of the raster to the cropped size.
89 //
90  void size(short w, short h, void *newRaster = 0);
91  void crop(short x, short y, short w, short h);
92  void rgbaScale(float rrange[2],
93  float grange[2],
94  float brange[2],
95  float arange[2],
96  short x=0, short y=0, short w=0, short h=0);
97 
98 //
99 // Currently the channel mask only applies to blur operations.
100 // Non zero arguments enable the corresponding channel.
101 //
102  void setChannelMask(int r, int g, int b, int a);
103  void setEdgeChannel(IMG_Channel chan, unsigned options = 0);
104  void setChromaKey(const UT_HSVA c1,
105  const UT_HSVA c2,
106  const UT_HSVA delta,
107  int alpha);
108  void setEmbossParams(const IMG_EMBOSS_PARAMS &bp);
109  void getEmbossParams(IMG_EMBOSS_PARAMS *bp) const;
110 
111  virtual UT_RGBA *getPixel(short x, short y) const;
112  virtual UT_BIG_RGBA *getDeepPixel(short x, short y) const;
113  virtual void *getVoidPixel(short x, short y) const;
114 
115  // Scale the raster
116  void resize(short w, short h,
118  void resizeCopy(IMG_Raster *src, short w, short h,
120  float filter_width = 0.0F)
121  {
122  resizeCopy(src, w, h, filt, filter_width,
123  filt, filter_width);
124  }
125  void resizeCopy(IMG_Raster *src, short w, short h,
126  UT_FilterType xfilter, float xwidth,
127  UT_FilterType yfilter, float ywidth);
128 
129  void resizeCropCopy(IMG_Raster *src, short sl, short sb,
130  short sw, short sh, short w, short h);
131 
132  int save(const char *pathname, bool quiet = false);
133  int save(const char *pathname, int fullHeight, void *tag,
134  int (*more)(IMG_Raster *r,void *,int,int),
135  unsigned margin = 0);
136  int save(std::ostream &os, int binary = 1) const;
137 
138  void *openSave(const char *pathname, int fullHeight);
139  void *saveMore(void *handle);
140  void abortSave(void *handle);
141 
142  int load(const char *pathname,
143  IMG_ScaleOp scaled = IMG_SCALE_NONE,
145  short size = 100,
146  bool watermarked = false,
147  bool topremult = true);
148  int load(const char *pathname,
149  short xres,
150  short yres,
151  IMG_ScaleOp scaled = IMG_SCALE_SIZE,
153  short yJump = 0,
154  short yThrow = 0,
155  short xJump = 0,
156  short xThrow = 0,
157  short yHave = 0);
158  bool load(UT_IStream &is);
159 
160  int stat(const char *pathname,
161  short *xres,
162  short *yres);
163 
164  void setClipOffset(short x, short y);
165  void setClipSize (short w, short h);
166  short getClipX() const { return clip_x; }
167  short getClipY() const { return clip_y; }
168  short getClipW() const { return clip_w; }
169  short getClipH() const { return clip_h; }
170  void getClippedOp(short *x, short *y, short *w, short *h) const;
171 
172  static void mult_8_8( UT_RGBA *pixel, unsigned int alpha,
173  unsigned int *a, unsigned int *b,
174  unsigned int *g, unsigned int *r);
175  static void mult_8_16( UT_RGBA *pixel, unsigned int alpha,
176  unsigned int *a, unsigned int *b,
177  unsigned int *g, unsigned int *r,
178  unsigned int point_five);
179  static void mult_16_8( UT_BIG_RGBA *pixel, unsigned int alpha,
180  unsigned int *a, unsigned int *b,
181  unsigned int *g, unsigned int *r,
182  unsigned int point_five);
183  static void mult_16_16(UT_BIG_RGBA *pixel, unsigned int alpha,
184  unsigned int *a, unsigned int *b,
185  unsigned int *g, unsigned int *r);
186 
187  void operator=(const IMG_Raster &r);
188  void operator=(const IMG_RasterHSVA &r);
189 
190 protected:
191  void blurOp_8 (float weight = 0.5);
192  void blurOp_16(float weight = 0.5);
193  void bumpOp_8 (float weight = 0.5);
194  void bumpOp_16(float weight = 0.5);
195  void edgeOp_8 (float weight = 0.5);
196  void edgeOp_16(float weight = 0.5);
197  void sharpenOp_8 (float weight = 0.5);
198  void sharpenOp_16(float weight = 0.5);
199 
200  static unsigned short ut_chanR_8(UT_RGBA *p);
201  static unsigned short ut_chanG_8(UT_RGBA *p);
202  static unsigned short ut_chanB_8(UT_RGBA *p);
203  static unsigned short ut_chanA_8(UT_RGBA *p);
204  static unsigned short ut_chanL_8(UT_RGBA *p);
205  static unsigned short ut_chanH_8(UT_RGBA *p);
206  static unsigned short ut_chanS_8(UT_RGBA *p);
207  static unsigned short ut_chanV_8(UT_RGBA *p);
208 
209  static unsigned short ut_chanR_16(UT_BIG_RGBA *p);
210  static unsigned short ut_chanG_16(UT_BIG_RGBA *p);
211  static unsigned short ut_chanB_16(UT_BIG_RGBA *p);
212  static unsigned short ut_chanA_16(UT_BIG_RGBA *p);
213  static unsigned short ut_chanL_16(UT_BIG_RGBA *p);
214  static unsigned short ut_chanH_16(UT_BIG_RGBA *p);
215  static unsigned short ut_chanS_16(UT_BIG_RGBA *p);
216  static unsigned short ut_chanV_16(UT_BIG_RGBA *p);
217 
218  void composite_8_8 (IMG_Raster *, short x, short y);
219  void composite_8_16 (IMG_Raster *, short x, short y);
220  void composite_16_8 (IMG_Raster *, short x, short y);
221  void composite_16_16 (IMG_Raster *, short x, short y);
222 
223  static void *compositeThreadMgr( void *data );
224 
225  void setCompositeOp_8_8 (IMG_CompositeOp op);
226  void setCompositeOp_8_16 (IMG_CompositeOp op);
227  void setCompositeOp_16_8 (IMG_CompositeOp op);
228  void setCompositeOp_16_16(IMG_CompositeOp op);
229 
234 
236 
237  short channelMask;
238  short clip_x; // Active raster area
239  short clip_y;
240  short clip_w;
241  short clip_h;
242  short op_x; // Clip region of most recent composite
243  short op_y;
244  short op_w;
245  short op_h;
246 
247  img_ioState *io;
248 
249 public:
250  // Leave these two typedefs here if you want this program to compile
251  // under C++ >= 3.0.1. (Cristin)
252  typedef void (*img_3SumFunc_8)(
253  int sums[],
254  UT_RGBA *above,
255  UT_RGBA *center,
256  UT_RGBA *below);
257  typedef void (*img_3SumFunc_16)(
258  int sums[],
259  UT_BIG_RGBA *above,
261  UT_BIG_RGBA *below);
262 
263  typedef void (*img_3x3FilterFunc_8)(
264  UT_RGBA *out,
265  UT_RGBA *p, int r, int g, int b, int a);
266  typedef void (*img_3x3FilterFunc_16)(
267  UT_BIG_RGBA *out,
268  UT_BIG_RGBA *p, int r, int g, int b, int a);
269 
270  typedef void (*img_HpassFunc_8)(
271  img_3x3FilterFunc_8 do_pixel,
272  img_3SumFunc_8 do_sum,
273  UT_RGBA *output,
274  int length,
275  UT_RGBA *above,
276  UT_RGBA *center,
277  UT_RGBA *below);
278  typedef void (*img_HpassFunc_16)(
279  img_3x3FilterFunc_16 do_pixel,
280  img_3SumFunc_16 do_sum,
281  UT_BIG_RGBA *output,
282  int length,
283  UT_BIG_RGBA *above,
285  UT_BIG_RGBA *below);
286 private:
287 
288  void apply3x3_8(img_HpassFunc_8 hpass,
289  img_3x3FilterFunc_8 doit,
290  img_3SumFunc_8 do_sum,
291  UT_RGBA *r);
292  void apply3x3_16(img_HpassFunc_16 hpass,
293  img_3x3FilterFunc_16 doit,
294  img_3SumFunc_16 do_sum,
295  UT_BIG_RGBA *r);
296 
297  void initImg();
298 
299  static void *doVerticalPass_8 ( void* ); // thread callable
300  static void *doVerticalPass_16( void* ); // thread callable
301  static void *doHorizontalPass_8 ( void* ); // thread callable
302  static void *doHorizontalPass_16( void* ); // thread callable
303  void initBlurTables_8 (float weight);
304  void initBlurTables_16(float weight);
305 
306  void clearOutsideOpArea_8();
307  void clearOutsideOpArea_16();
308 
309  void rgbaScale_8( float rrange[2],
310  float grange[2],
311  float brange[2],
312  float arange[2],
313  short x=0,short y=0,short w=0, short h=0);
314 
315  void rgbaScale_16(float rrange[2],
316  float grange[2],
317  float brange[2],
318  float arange[2],
319  short x=0,short y=0,short w=0, short h=0);
320  void copy(IMG_Raster *src, short w, short h,
321  void *dst, UT_RasterDepth dst_depth,
322  UT_FilterType filt)
323  {
324  copy(src, w, h, dst, dst_depth,
325  filt, 0.0F, filt, 0.0F);
326  }
327  void copy(IMG_Raster *src, short w, short h,
328  void *dst, UT_RasterDepth dst_depth,
329  UT_FilterType xfilter, float xwidth,
330  UT_FilterType yfilter, float ywidth);
331 
332  UT_ThreadSet *getThreadSet();
333 };
334 
335 #endif
UT_RasterDepth
Definition: UT_Raster.h:25
short op_h
Definition: IMG_Raster.h:245
void
Definition: png.h:1083
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
const GLuint GLenum const void * binary
Definition: glcorearb.h:1924
IMG_Compositebit_16_8 compositebit_16_8
Definition: IMG_Raster.h:233
GLboolean GLboolean g
Definition: glcorearb.h:1222
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:795
GLenum GLenum GLsizei void * image
Definition: glad.h:5132
GLint y
Definition: glcorearb.h:103
void compositePixel(UT_BIG_RGBA *dest, UT_RGBA *op)
Definition: IMG_Raster.h:73
void compositePixel(UT_BIG_RGBA *dest, UT_BIG_RGBA *op)
Definition: IMG_Raster.h:70
UT_FilterType
Definition: UT_FilterType.h:16
auto arg(const Char *name, const T &arg) -> detail::named_arg< Char, T >
Definition: core.h:1736
short clip_h
Definition: IMG_Raster.h:241
#define IMG_API
Definition: IMG_API.h:10
short op_w
Definition: IMG_Raster.h:244
void(* IMG_Compositebit_16_16)(UT_BIG_RGBA *dest, UT_BIG_RGBA *op, int len)
short channelMask
Definition: IMG_Raster.h:237
IMG_Compositebit_8_8 compositebit_8_8
Definition: IMG_Raster.h:230
IMG_ScaleOp
GLfloat GLfloat GLfloat alpha
Definition: glcorearb.h:112
short getClipH() const
Definition: IMG_Raster.h:169
void compositePixel(UT_RGBA *dest, UT_BIG_RGBA *op)
Definition: IMG_Raster.h:67
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GLint GLenum GLint x
Definition: glcorearb.h:409
short getClipX() const
Definition: IMG_Raster.h:166
short getClipW() const
Definition: IMG_Raster.h:168
GLint GLint GLsizei GLsizei GLsizei depth
Definition: glcorearb.h:476
IMG_CompositeOp compositeOp
Definition: IMG_Raster.h:235
GLsizeiptr size
Definition: glcorearb.h:664
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
GLenum GLenum dst
Definition: glcorearb.h:1793
IMG_Compositebit_16_16 compositebit_16_16
Definition: IMG_Raster.h:232
ImageBuf OIIO_API resize(const ImageBuf &src, string_view filtername="", float filterwidth=0.0f, ROI roi={}, int nthreads=0)
short clip_w
Definition: IMG_Raster.h:240
short clip_y
Definition: IMG_Raster.h:239
void resizeCopy(IMG_Raster *src, short w, short h, UT_FilterType filt=UT_FILTER_POINT, float filter_width=0.0F)
Definition: IMG_Raster.h:118
void compositePixel(UT_RGBA *dest, UT_RGBA *op)
Definition: IMG_Raster.h:64
IMG_Channel
IMG_CompositeOp getCompositeOp() const
Definition: IMG_Raster.h:62
short op_y
Definition: IMG_Raster.h:243
IMG_CompositeOp
short clip_x
Definition: IMG_Raster.h:238
img_ioState * io
Definition: IMG_Raster.h:247
IMG_Compositebit_8_16 compositebit_8_16
Definition: IMG_Raster.h:231
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
void(* IMG_Compositebit_16_8)(UT_BIG_RGBA *dest, UT_RGBA *op, int len)
GLboolean r
Definition: glcorearb.h:1222
void(* IMG_Compositebit_8_8)(UT_RGBA *dest, UT_RGBA *op, int len)
IMG_FilterOp
ImageBuf OIIO_API crop(const ImageBuf &src, ROI roi={}, int nthreads=0)
void(* IMG_Compositebit_8_16)(UT_RGBA *dest, UT_BIG_RGBA *op, int len)
short getClipY() const
Definition: IMG_Raster.h:167
Definition: format.h:895
short op_x
Definition: IMG_Raster.h:242
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1297
GLenum src
Definition: glcorearb.h:1793