Blender  V3.3
freestyle/intern/image/Image.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #pragma once
4 
10 #include <string.h> // for memcpy
11 
12 #ifdef WITH_CXX_GUARDEDALLOC
13 # include "MEM_guardedalloc.h"
14 #endif
15 
16 namespace Freestyle {
17 
18 //
19 // Image base class, for all types of images
20 //
22 
28 class FrsImage {
29  public:
32  {
33  _storedWidth = 0;
34  _storedHeight = 0;
35  _width = 0;
36  _height = 0;
37  _Ox = 0;
38  _Oy = 0;
39  }
40 
42  FrsImage(const FrsImage &brother)
43  {
44  _storedWidth = brother._storedWidth;
45  _storedHeight = brother._storedHeight;
46  _width = brother._width;
47  _height = brother._height;
48  _Ox = brother._Ox;
49  _Oy = brother._Oy;
50  }
51 
55  FrsImage(unsigned w, unsigned h)
56  {
57  _width = w;
58  _height = h;
59  _storedWidth = w;
60  _storedHeight = h;
61  _Ox = 0;
62  _Oy = 0;
63  }
64 
79  FrsImage(unsigned w, unsigned h, unsigned sw, unsigned sh, unsigned ox, unsigned oy)
80  {
81  _width = w;
82  _height = h;
83  _storedWidth = sw;
84  _storedHeight = sh;
85  _Ox = ox;
86  _Oy = oy;
87  }
88 
90  FrsImage &operator=(const FrsImage &brother)
91  {
92  _width = brother._width;
93  _height = brother._height;
94  _storedWidth = brother._storedWidth;
95  _storedHeight = brother._storedHeight;
96  _Ox = brother._Ox;
97  _Oy = brother._Oy;
98  return *this;
99  }
100 
102  virtual ~FrsImage()
103  {
104  }
105 
107  inline unsigned width() const
108  {
109  return _width;
110  }
111 
113  inline unsigned height() const
114  {
115  return _height;
116  }
117 
119  virtual float pixel(unsigned x, unsigned y) const = 0;
120 
140  virtual void setArray(float *array,
141  unsigned width,
142  unsigned height,
143  unsigned sw,
144  unsigned sh,
145  unsigned x,
146  unsigned y,
147  bool copy = true) = 0;
148 
152  virtual float *getArray() = 0;
153 
154  protected:
155  unsigned _width;
156  unsigned _height;
157  unsigned _storedWidth;
158  unsigned _storedHeight;
159  unsigned _Ox; // origin of the stored part
160  unsigned _Oy; // origin of the stored part
161 
162 #ifdef WITH_CXX_GUARDEDALLOC
163  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:FrsImage")
164 #endif
165 };
166 
167 //
168 // RGBImage
169 //
171 class RGBImage : public FrsImage {
172  public:
174  {
175  _rgb = 0;
176  }
177 
178  RGBImage(const RGBImage &brother) : FrsImage(brother)
179  {
180  _rgb = new float[3 * _storedWidth * _storedHeight];
181  memcpy(_rgb, brother._rgb, 3 * _storedWidth * _storedHeight * sizeof(float));
182  }
183 
184  RGBImage(unsigned w, unsigned h) : FrsImage(w, h)
185  {
186  _rgb = new float[3 * _width * _height];
187  }
188 
189  RGBImage(float *rgb, unsigned w, unsigned h) : FrsImage(w, h)
190  {
191  _rgb = new float[3 * _width * _height];
192  memcpy(_rgb, rgb, 3 * _width * _height * sizeof(float));
193  }
194 
209  RGBImage(float *rgb, unsigned w, unsigned h, unsigned sw, unsigned sh, unsigned ox, unsigned oy)
210  : FrsImage(w, h, sw, sh, ox, oy)
211  {
212  _rgb = new float[3 * _storedWidth * _storedHeight];
213  memcpy(_rgb, rgb, 3 * _storedWidth * _storedHeight * sizeof(float));
214  }
215 
216  RGBImage &operator=(const RGBImage &brother)
217  {
218  dynamic_cast<FrsImage &>(*this) = brother;
219  _rgb = new float[3 * _storedWidth * _storedHeight];
220  memcpy(_rgb, brother._rgb, 3 * _storedWidth * _storedHeight * sizeof(float));
221  return *this;
222  }
223 
224  virtual ~RGBImage()
225  {
226  if (_rgb) {
227  delete[] _rgb;
228  }
229  }
230 
231  inline float getR(unsigned x, unsigned y) const
232  {
233  return _rgb[3 * (y - _Oy) * _storedWidth + (x - _Ox) * 3];
234  }
235 
236  inline float getG(unsigned x, unsigned y) const
237  {
238  return _rgb[3 * (y - _Oy) * _storedWidth + (x - _Ox) * 3 + 1];
239  }
240 
241  inline float getB(unsigned x, unsigned y) const
242  {
243  return _rgb[3 * (y - _Oy) * _storedWidth + (x - _Ox) * 3 + 2];
244  }
245 
246  virtual void setPixel(unsigned x, unsigned y, float r, float g, float b)
247  {
248  float *tmp = &(_rgb[3 * (y - _Oy) * _storedWidth + (x - _Ox) * 3]);
249  *tmp = r;
250  tmp++;
251  *tmp = g;
252  tmp++;
253  *tmp = b;
254  }
255 
256  virtual float pixel(unsigned x, unsigned y) const
257  {
258  float res = 0.0f;
259  float *tmp = &(_rgb[3 * (y - _Oy) * _storedWidth + (x - _Ox) * 3]);
260  res += 11.0f * (*tmp);
261  tmp++;
262  res += 16.0f * (*tmp);
263  tmp++;
264  res += 5.0f * (*tmp);
265  return res / 32.0f;
266  }
267 
272  virtual void setArray(float *rgb,
273  unsigned width,
274  unsigned height,
275  unsigned sw,
276  unsigned sh,
277  unsigned x,
278  unsigned y,
279  bool copy = true)
280  {
281  _width = width;
282  _height = height;
283  _storedWidth = sw;
284  _storedHeight = sh;
285  _Ox = x;
286  _Oy = y;
287  if (!copy) {
288  _rgb = rgb;
289  return;
290  }
291 
292  memcpy(_rgb, rgb, 3 * _storedWidth * _storedHeight * sizeof(float));
293  }
294 
295  virtual float *getArray()
296  {
297  return _rgb;
298  }
299 
300  protected:
301  float *_rgb;
302 };
303 
304 //
305 // GrayImage
306 //
308 
309 class GrayImage : public FrsImage {
310  public:
312  {
313  _lvl = 0;
314  }
315 
316  GrayImage(const GrayImage &brother) : FrsImage(brother)
317  {
318  _lvl = new float[_storedWidth * _storedHeight];
319  memcpy(_lvl, brother._lvl, _storedWidth * _storedHeight * sizeof(*_lvl));
320  }
321 
323  GrayImage(unsigned w, unsigned h) : FrsImage(w, h)
324  {
325  _lvl = new float[_width * _height];
326  }
327 
328  GrayImage(float *lvl, unsigned w, unsigned h) : FrsImage(w, h)
329  {
330  _lvl = new float[_width * _height];
331  memcpy(_lvl, lvl, _width * _height * sizeof(*_lvl));
332  }
333 
348  GrayImage(float *lvl, unsigned w, unsigned h, unsigned sw, unsigned sh, unsigned ox, unsigned oy)
349  : FrsImage(w, h, sw, sh, ox, oy)
350  {
351  _lvl = new float[_storedWidth * _storedHeight];
352  memcpy(_lvl, lvl, _storedWidth * _storedHeight * sizeof(float));
353  }
354 
355  GrayImage &operator=(const GrayImage &brother)
356  {
357  dynamic_cast<FrsImage &>(*this) = brother;
358  _lvl = new float[_storedWidth * _storedHeight];
359  memcpy(_lvl, brother._lvl, _storedWidth * _storedHeight * sizeof(float));
360  return *this;
361  }
362 
363  virtual ~GrayImage()
364  {
365  if (_lvl) {
366  delete[] _lvl;
367  }
368  }
369 
370  inline void setPixel(unsigned x, unsigned y, float v)
371  {
372  _lvl[(y - _Oy) * _storedWidth + (x - _Ox)] = v;
373  }
374 
375  inline float pixel(unsigned x, unsigned y) const
376  {
377  return _lvl[(y - _Oy) * _storedWidth + (x - _Ox)];
378  }
379 
384  void setArray(float *lvl,
385  unsigned width,
386  unsigned height,
387  unsigned sw,
388  unsigned sh,
389  unsigned x,
390  unsigned y,
391  bool copy = true)
392  {
393  _width = width;
394  _height = height;
395  _storedWidth = sw;
396  _storedHeight = sh;
397  _Ox = x;
398  _Oy = y;
399  if (!copy) {
400  _lvl = lvl;
401  return;
402  }
403 
404  memcpy(_lvl, lvl, _storedWidth * _storedHeight * sizeof(float));
405  }
406 
408  virtual float *getArray()
409  {
410  return _lvl;
411  }
412 
413  protected:
414  float *_lvl;
415 };
416 
417 } /* namespace Freestyle */
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble GLdouble r _GL_VOID_RET _GL_VOID GLfloat GLfloat r _GL_VOID_RET _GL_VOID GLint GLint r _GL_VOID_RET _GL_VOID GLshort GLshort r _GL_VOID_RET _GL_VOID GLdouble GLdouble r
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
Read Guarded memory(de)allocation.
ATTR_WARN_UNUSED_RESULT const BMVert * v
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition: btQuadWord.h:119
FrsImage(const FrsImage &brother)
FrsImage(unsigned w, unsigned h, unsigned sw, unsigned sh, unsigned ox, unsigned oy)
FrsImage(unsigned w, unsigned h)
FrsImage & operator=(const FrsImage &brother)
virtual float pixel(unsigned x, unsigned y) const =0
virtual void setArray(float *array, unsigned width, unsigned height, unsigned sw, unsigned sh, unsigned x, unsigned y, bool copy=true)=0
virtual float * getArray()=0
float pixel(unsigned x, unsigned y) const
GrayImage(float *lvl, unsigned w, unsigned h)
GrayImage(unsigned w, unsigned h)
void setPixel(unsigned x, unsigned y, float v)
void setArray(float *lvl, unsigned width, unsigned height, unsigned sw, unsigned sh, unsigned x, unsigned y, bool copy=true)
GrayImage(float *lvl, unsigned w, unsigned h, unsigned sw, unsigned sh, unsigned ox, unsigned oy)
GrayImage(const GrayImage &brother)
GrayImage & operator=(const GrayImage &brother)
float getG(unsigned x, unsigned y) const
RGBImage(unsigned w, unsigned h)
float getB(unsigned x, unsigned y) const
RGBImage & operator=(const RGBImage &brother)
virtual float pixel(unsigned x, unsigned y) const
RGBImage(float *rgb, unsigned w, unsigned h)
RGBImage(const RGBImage &brother)
RGBImage(float *rgb, unsigned w, unsigned h, unsigned sw, unsigned sh, unsigned ox, unsigned oy)
virtual void setArray(float *rgb, unsigned width, unsigned height, unsigned sw, unsigned sh, unsigned x, unsigned y, bool copy=true)
virtual void setPixel(unsigned x, unsigned y, float r, float g, float b)
float getR(unsigned x, unsigned y) const
ccl_gpu_kernel_postfix ccl_global float int int int sw
ccl_gpu_kernel_postfix ccl_global float int int int int sh
inherits from class Rep
Definition: AppCanvas.cpp:18
static unsigned x[3]
Definition: RandGen.cpp:73
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
static const pxr::TfToken g("g", pxr::TfToken::Immortal)
static const pxr::TfToken rgb("rgb", pxr::TfToken::Immortal)
static void copy(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node)