Blender  V3.3
COM_ImageOperation.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2011 Blender Foundation. */
3 
4 #include "COM_ImageOperation.h"
5 
6 #include "BKE_scene.h"
7 
8 #include "IMB_colormanagement.h"
9 #include "IMB_imbuf.h"
10 #include "IMB_imbuf_types.h"
11 
12 namespace blender::compositor {
13 
15 {
16  image_ = nullptr;
17  buffer_ = nullptr;
18  image_float_buffer_ = nullptr;
19  image_byte_buffer_ = nullptr;
20  image_user_ = nullptr;
21  imagewidth_ = 0;
22  imageheight_ = 0;
23  framenumber_ = 0;
24  image_depth_buffer_ = nullptr;
25  depth_buffer_ = nullptr;
27  rd_ = nullptr;
28  view_name_ = nullptr;
29 }
31 {
33 }
35 {
37 }
39 {
41 }
42 
44 {
45  ImBuf *ibuf;
46  ImageUser iuser = *image_user_;
47 
48  if (image_ == nullptr) {
49  return nullptr;
50  }
51 
52  /* local changes to the original ImageUser */
53  if (BKE_image_is_multilayer(image_) == false) {
55  }
56 
57  ibuf = BKE_image_acquire_ibuf(image_, &iuser, nullptr);
58  if (ibuf == nullptr || (ibuf->rect == nullptr && ibuf->rect_float == nullptr)) {
59  BKE_image_release_ibuf(image_, ibuf, nullptr);
60  return nullptr;
61  }
62  return ibuf;
63 }
64 
66 {
67  ImBuf *stackbuf = get_im_buf();
68  buffer_ = stackbuf;
69  if (stackbuf) {
70  image_float_buffer_ = stackbuf->rect_float;
71  image_byte_buffer_ = stackbuf->rect;
72  image_depth_buffer_ = stackbuf->zbuf_float;
73  if (stackbuf->zbuf_float) {
74  depth_buffer_ = new MemoryBuffer(stackbuf->zbuf_float, 1, stackbuf->x, stackbuf->y);
75  }
76  imagewidth_ = stackbuf->x;
77  imageheight_ = stackbuf->y;
78  number_of_channels_ = stackbuf->channels;
79  }
80 }
81 
83 {
84  image_float_buffer_ = nullptr;
85  image_byte_buffer_ = nullptr;
87  if (depth_buffer_) {
88  delete depth_buffer_;
89  depth_buffer_ = nullptr;
90  }
91 }
92 
93 void BaseImageOperation::determine_canvas(const rcti &UNUSED(preferred_area), rcti &r_area)
94 {
95  ImBuf *stackbuf = get_im_buf();
96 
97  r_area = COM_AREA_NONE;
98 
99  if (stackbuf) {
100  BLI_rcti_init(&r_area, 0, stackbuf->x, 0, stackbuf->y);
101  }
102 
103  BKE_image_release_ibuf(image_, stackbuf, nullptr);
104 }
105 
107  ImBuf *ibuf, float x, float y, PixelSampler sampler, bool make_linear_rgb, float color[4])
108 {
109  if (ibuf->rect_float) {
110  switch (sampler) {
112  nearest_interpolation_color(ibuf, nullptr, color, x, y);
113  break;
115  bilinear_interpolation_color(ibuf, nullptr, color, x, y);
116  break;
118  bicubic_interpolation_color(ibuf, nullptr, color, x, y);
119  break;
120  }
121  }
122  else {
123  unsigned char byte_color[4];
124  switch (sampler) {
126  nearest_interpolation_color(ibuf, byte_color, nullptr, x, y);
127  break;
129  bilinear_interpolation_color(ibuf, byte_color, nullptr, x, y);
130  break;
132  bicubic_interpolation_color(ibuf, byte_color, nullptr, x, y);
133  break;
134  }
135  rgba_uchar_to_float(color, byte_color);
136  if (make_linear_rgb) {
138  }
139  }
140 }
141 
143 {
144  int ix = x, iy = y;
145  if (image_float_buffer_ == nullptr && image_byte_buffer_ == nullptr) {
146  zero_v4(output);
147  }
148  else if (ix < 0 || iy < 0 || ix >= buffer_->x || iy >= buffer_->y) {
149  zero_v4(output);
150  }
151  else {
153  }
154 }
155 
157  const rcti &area,
159 {
160  output->copy_from(buffer_, area, true);
161 }
162 
164  float x,
165  float y,
167 {
168  float tempcolor[4];
169 
170  if (image_float_buffer_ == nullptr && image_byte_buffer_ == nullptr) {
171  output[0] = 0.0f;
172  }
173  else {
174  tempcolor[3] = 1.0f;
175  sample_image_at_location(buffer_, x, y, sampler, false, tempcolor);
176  output[0] = tempcolor[3];
177  }
178 }
179 
181  const rcti &area,
183 {
184  output->copy_from(buffer_, area, 3, COM_DATA_TYPE_VALUE_CHANNELS, 0);
185 }
186 
188  float x,
189  float y,
190  PixelSampler /*sampler*/)
191 {
192  if (image_depth_buffer_ == nullptr) {
193  output[0] = 0.0f;
194  }
195  else {
196  if (x < 0 || y < 0 || x >= this->get_width() || y >= this->get_height()) {
197  output[0] = 0.0f;
198  }
199  else {
200  int offset = y * get_width() + x;
202  }
203  }
204 }
205 
207  const rcti &area,
209 {
210  if (depth_buffer_) {
211  output->copy_from(depth_buffer_, area);
212  }
213  else {
214  output->fill(area, COM_VALUE_ZERO);
215  }
216 }
217 
218 } // namespace blender::compositor
void BKE_image_release_ibuf(struct Image *ima, struct ImBuf *ibuf, void *lock)
struct ImBuf * BKE_image_acquire_ibuf(struct Image *ima, struct ImageUser *iuser, void **r_lock)
bool BKE_image_is_multilayer(const struct Image *ima)
int BKE_scene_multiview_view_id_get(const struct RenderData *rd, const char *viewname)
void rgba_uchar_to_float(float r_col[4], const unsigned char col_ub[4])
Definition: math_color.c:383
MINLINE void zero_v4(float r[4])
void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax)
Definition: rct.c:417
#define UNUSED(x)
_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
void IMB_colormanagement_colorspace_to_scene_linear_v4(float pixel[4], bool predivide, struct ColorSpace *colorspace)
void bicubic_interpolation_color(const struct ImBuf *in, unsigned char outI[4], float outF[4], float u, float v)
Definition: imageprocess.c:80
void nearest_interpolation_color(const struct ImBuf *in, unsigned char outI[4], float outF[4], float u, float v)
Definition: imageprocess.c:278
void bilinear_interpolation_color(const struct ImBuf *in, unsigned char outI[4], float outF[4], float u, float v)
Definition: imageprocess.c:128
Contains defines and structs used throughout the imbuf module.
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert a color
Base class for all image operations.
void determine_canvas(const rcti &preferred_area, rcti &r_area) override
void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span< MemoryBuffer * > inputs) override
void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override
calculate a single pixel
void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override
calculate a single pixel
void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span< MemoryBuffer * > inputs) override
void update_memory_buffer_partial(MemoryBuffer *output, const rcti &area, Span< MemoryBuffer * > inputs) override
void execute_pixel_sampled(float output[4], float x, float y, PixelSampler sampler) override
calculate a single pixel
a MemoryBuffer contains access to the data of a chunk
void add_output_socket(DataType datatype)
depth_tx sampler(1, ImageType::FLOAT_2D, "combined_tx") .sampler(2
ccl_global KernelShaderEvalInput ccl_global float * output
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
static void area(int d1, int d2, int e1, int e2, float weights[2])
constexpr int COM_DATA_TYPE_VALUE_CHANNELS
Definition: COM_defines.h:60
constexpr float COM_VALUE_ZERO[1]
Definition: COM_defines.h:67
constexpr rcti COM_AREA_NONE
Definition: COM_defines.h:112
static void sample_image_at_location(ImBuf *ibuf, float x, float y, PixelSampler sampler, bool make_linear_rgb, float color[4])
static bNodeSocketTemplate inputs[]
float * zbuf_float
int channels
struct ColorSpace * rect_colorspace
unsigned int * rect
float * rect_float
short multi_index