Blender  V2.93
freestyle/intern/image/Image.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #pragma once
18 
24 #include <string.h> // for memcpy
25 
26 #ifdef WITH_CXX_GUARDEDALLOC
27 # include "MEM_guardedalloc.h"
28 #endif
29 
30 namespace Freestyle {
31 
32 //
33 // Image base class, for all types of images
34 //
36 
42 class FrsImage {
43  public:
46  {
47  _storedWidth = 0;
48  _storedHeight = 0;
49  _width = 0;
50  _height = 0;
51  _Ox = 0;
52  _Oy = 0;
53  }
54 
56  FrsImage(const FrsImage &brother)
57  {
58  _storedWidth = brother._storedWidth;
59  _storedHeight = brother._storedHeight;
60  _width = brother._width;
61  _height = brother._height;
62  _Ox = brother._Ox;
63  _Oy = brother._Oy;
64  }
65 
69  FrsImage(unsigned w, unsigned h)
70  {
71  _width = w;
72  _height = h;
73  _storedWidth = w;
74  _storedHeight = h;
75  _Ox = 0;
76  _Oy = 0;
77  }
78 
93  FrsImage(unsigned w, unsigned h, unsigned sw, unsigned sh, unsigned ox, unsigned oy)
94  {
95  _width = w;
96  _height = h;
97  _storedWidth = sw;
98  _storedHeight = sh;
99  _Ox = ox;
100  _Oy = oy;
101  }
102 
104  FrsImage &operator=(const FrsImage &brother)
105  {
106  _width = brother._width;
107  _height = brother._height;
108  _storedWidth = brother._storedWidth;
109  _storedHeight = brother._storedHeight;
110  _Ox = brother._Ox;
111  _Oy = brother._Oy;
112  return *this;
113  }
114 
116  virtual ~FrsImage()
117  {
118  }
119 
121  inline unsigned width() const
122  {
123  return _width;
124  }
125 
127  inline unsigned height() const
128  {
129  return _height;
130  }
131 
133  virtual float pixel(unsigned x, unsigned y) const = 0;
134 
154  virtual void setArray(float *array,
155  unsigned width,
156  unsigned height,
157  unsigned sw,
158  unsigned sh,
159  unsigned x,
160  unsigned y,
161  bool copy = true) = 0;
162 
166  virtual float *getArray() = 0;
167 
168  protected:
169  unsigned _width;
170  unsigned _height;
171  unsigned _storedWidth;
172  unsigned _storedHeight;
173  unsigned _Ox; // origin of the stored part
174  unsigned _Oy; // origin of the stored part
175 
176 #ifdef WITH_CXX_GUARDEDALLOC
177  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:FrsImage")
178 #endif
179 };
180 
181 //
182 // RGBImage
183 //
185 class RGBImage : public FrsImage {
186  public:
188  {
189  _rgb = 0;
190  }
191 
192  RGBImage(const RGBImage &brother) : FrsImage(brother)
193  {
194  _rgb = new float[3 * _storedWidth * _storedHeight];
195  memcpy(_rgb, brother._rgb, 3 * _storedWidth * _storedHeight * sizeof(float));
196  }
197 
198  RGBImage(unsigned w, unsigned h) : FrsImage(w, h)
199  {
200  _rgb = new float[3 * _width * _height];
201  }
202 
203  RGBImage(float *rgb, unsigned w, unsigned h) : FrsImage(w, h)
204  {
205  _rgb = new float[3 * _width * _height];
206  memcpy(_rgb, rgb, 3 * _width * _height * sizeof(float));
207  }
208 
223  RGBImage(float *rgb, unsigned w, unsigned h, unsigned sw, unsigned sh, unsigned ox, unsigned oy)
224  : FrsImage(w, h, sw, sh, ox, oy)
225  {
226  _rgb = new float[3 * _storedWidth * _storedHeight];
227  memcpy(_rgb, rgb, 3 * _storedWidth * _storedHeight * sizeof(float));
228  }
229 
230  RGBImage &operator=(const RGBImage &brother)
231  {
232  dynamic_cast<FrsImage &>(*this) = brother;
233  _rgb = new float[3 * _storedWidth * _storedHeight];
234  memcpy(_rgb, brother._rgb, 3 * _storedWidth * _storedHeight * sizeof(float));
235  return *this;
236  }
237 
238  virtual ~RGBImage()
239  {
240  if (_rgb) {
241  delete[] _rgb;
242  }
243  }
244 
245  inline float getR(unsigned x, unsigned y) const
246  {
247  return _rgb[3 * (y - _Oy) * _storedWidth + (x - _Ox) * 3];
248  }
249 
250  inline float getG(unsigned x, unsigned y) const
251  {
252  return _rgb[3 * (y - _Oy) * _storedWidth + (x - _Ox) * 3 + 1];
253  }
254 
255  inline float getB(unsigned x, unsigned y) const
256  {
257  return _rgb[3 * (y - _Oy) * _storedWidth + (x - _Ox) * 3 + 2];
258  }
259 
260  virtual void setPixel(unsigned x, unsigned y, float r, float g, float b)
261  {
262  float *tmp = &(_rgb[3 * (y - _Oy) * _storedWidth + (x - _Ox) * 3]);
263  *tmp = r;
264  tmp++;
265  *tmp = g;
266  tmp++;
267  *tmp = b;
268  }
269 
270  virtual float pixel(unsigned x, unsigned y) const
271  {
272  float res = 0.0f;
273  float *tmp = &(_rgb[3 * (y - _Oy) * _storedWidth + (x - _Ox) * 3]);
274  res += 11.0f * (*tmp);
275  tmp++;
276  res += 16.0f * (*tmp);
277  tmp++;
278  res += 5.0f * (*tmp);
279  return res / 32.0f;
280  }
281 
286  virtual void setArray(float *rgb,
287  unsigned width,
288  unsigned height,
289  unsigned sw,
290  unsigned sh,
291  unsigned x,
292  unsigned y,
293  bool copy = true)
294  {
295  _width = width;
296  _height = height;
297  _storedWidth = sw;
298  _storedHeight = sh;
299  _Ox = x;
300  _Oy = y;
301  if (!copy) {
302  _rgb = rgb;
303  return;
304  }
305 
306  memcpy(_rgb, rgb, 3 * _storedWidth * _storedHeight * sizeof(float));
307  }
308 
309  virtual float *getArray()
310  {
311  return _rgb;
312  }
313 
314  protected:
315  float *_rgb;
316 };
317 
318 //
319 // GrayImage
320 //
322 
323 class GrayImage : public FrsImage {
324  public:
326  {
327  _lvl = 0;
328  }
329 
330  GrayImage(const GrayImage &brother) : FrsImage(brother)
331  {
332  _lvl = new float[_storedWidth * _storedHeight];
333  memcpy(_lvl, brother._lvl, _storedWidth * _storedHeight * sizeof(*_lvl));
334  }
335 
337  GrayImage(unsigned w, unsigned h) : FrsImage(w, h)
338  {
339  _lvl = new float[_width * _height];
340  }
341 
342  GrayImage(float *lvl, unsigned w, unsigned h) : FrsImage(w, h)
343  {
344  _lvl = new float[_width * _height];
345  memcpy(_lvl, lvl, _width * _height * sizeof(*_lvl));
346  }
347 
362  GrayImage(float *lvl, unsigned w, unsigned h, unsigned sw, unsigned sh, unsigned ox, unsigned oy)
363  : FrsImage(w, h, sw, sh, ox, oy)
364  {
365  _lvl = new float[_storedWidth * _storedHeight];
366  memcpy(_lvl, lvl, _storedWidth * _storedHeight * sizeof(float));
367  }
368 
369  GrayImage &operator=(const GrayImage &brother)
370  {
371  dynamic_cast<FrsImage &>(*this) = brother;
372  _lvl = new float[_storedWidth * _storedHeight];
373  memcpy(_lvl, brother._lvl, _storedWidth * _storedHeight * sizeof(float));
374  return *this;
375  }
376 
377  virtual ~GrayImage()
378  {
379  if (_lvl) {
380  delete[] _lvl;
381  }
382  }
383 
384  inline void setPixel(unsigned x, unsigned y, float v)
385  {
386  _lvl[(y - _Oy) * _storedWidth + (x - _Ox)] = v;
387  }
388 
389  inline float pixel(unsigned x, unsigned y) const
390  {
391  return _lvl[(y - _Oy) * _storedWidth + (x - _Ox)];
392  }
393 
398  void setArray(float *lvl,
399  unsigned width,
400  unsigned height,
401  unsigned sw,
402  unsigned sh,
403  unsigned x,
404  unsigned y,
405  bool copy = true)
406  {
407  _width = width;
408  _height = height;
409  _storedWidth = sw;
410  _storedHeight = sh;
411  _Ox = x;
412  _Oy = y;
413  if (!copy) {
414  _lvl = lvl;
415  return;
416  }
417 
418  memcpy(_lvl, lvl, _storedWidth * _storedHeight * sizeof(float));
419  }
420 
422  virtual float *getArray()
423  {
424  return _lvl;
425  }
426 
427  protected:
428  float *_lvl;
429 };
430 
431 } /* 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
inherits from class Rep
Definition: AppCanvas.cpp:32
static unsigned x[3]
Definition: RandGen.cpp:87
static void copy(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node)