Blender  V2.93
COM_MultilayerImageOperation.cc
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  * Copyright 2011, Blender Foundation.
17  */
18 
20 
21 #include "IMB_imbuf.h"
22 #include "IMB_imbuf_types.h"
23 
24 namespace blender::compositor {
25 
27  RenderPass *render_pass,
28  int view)
29 {
30  this->m_passId = BLI_findindex(&render_layer->passes, render_pass);
31  this->m_view = view;
32  this->m_renderLayer = render_layer;
33  this->m_renderPass = render_pass;
34 }
35 
37 {
38  /* temporarily changes the view to get the right ImBuf */
39  int view = this->m_imageUser->view;
40 
41  this->m_imageUser->view = this->m_view;
42  this->m_imageUser->pass = this->m_passId;
43 
44  if (BKE_image_multilayer_index(this->m_image->rr, this->m_imageUser)) {
46  this->m_imageUser->view = view;
47  return ibuf;
48  }
49 
50  this->m_imageUser->view = view;
51  return nullptr;
52 }
53 
54 std::unique_ptr<MetaData> MultilayerColorOperation::getMetaData()
55 {
56  BLI_assert(this->m_buffer);
57  MetaDataExtractCallbackData callback_data = {nullptr};
58  RenderResult *render_result = this->m_image->rr;
59  if (render_result && render_result->stamp_data) {
60  RenderLayer *render_layer = this->m_renderLayer;
61  RenderPass *render_pass = this->m_renderPass;
62  std::string full_layer_name =
63  std::string(render_layer->name,
64  BLI_strnlen(render_layer->name, sizeof(render_layer->name))) +
65  "." +
66  std::string(render_pass->name, BLI_strnlen(render_pass->name, sizeof(render_pass->name)));
67  blender::StringRef cryptomatte_layer_name =
69  callback_data.setCryptomatteKeys(cryptomatte_layer_name);
70 
71  BKE_stamp_info_callback(&callback_data,
72  render_result->stamp_data,
74  false);
75  }
76 
77  return std::move(callback_data.meta_data);
78 }
79 
81  float x,
82  float y,
83  PixelSampler sampler)
84 {
85  if (this->m_imageFloatBuffer == nullptr) {
86  zero_v4(output);
87  }
88  else {
89  if (this->m_numberOfChannels == 4) {
90  switch (sampler) {
92  nearest_interpolation_color(this->m_buffer, nullptr, output, x, y);
93  break;
95  bilinear_interpolation_color(this->m_buffer, nullptr, output, x, y);
96  break;
98  bicubic_interpolation_color(this->m_buffer, nullptr, output, x, y);
99  break;
100  }
101  }
102  else {
103  int yi = y;
104  int xi = x;
105  if (xi < 0 || yi < 0 || (unsigned int)xi >= this->getWidth() ||
106  (unsigned int)yi >= this->getHeight()) {
107  zero_v4(output);
108  }
109  else {
110  int offset = (yi * this->getWidth() + xi) * 3;
111  copy_v3_v3(output, &this->m_imageFloatBuffer[offset]);
112  }
113  }
114  }
115 }
116 
118  float x,
119  float y,
120  PixelSampler /*sampler*/)
121 {
122  if (this->m_imageFloatBuffer == nullptr) {
123  output[0] = 0.0f;
124  }
125  else {
126  int yi = y;
127  int xi = x;
128  if (xi < 0 || yi < 0 || (unsigned int)xi >= this->getWidth() ||
129  (unsigned int)yi >= this->getHeight()) {
130  output[0] = 0.0f;
131  }
132  else {
133  float result = this->m_imageFloatBuffer[yi * this->getWidth() + xi];
134  output[0] = result;
135  }
136  }
137 }
138 
140  float x,
141  float y,
142  PixelSampler /*sampler*/)
143 {
144  if (this->m_imageFloatBuffer == nullptr) {
145  output[0] = 0.0f;
146  }
147  else {
148  int yi = y;
149  int xi = x;
150  if (xi < 0 || yi < 0 || (unsigned int)xi >= this->getWidth() ||
151  (unsigned int)yi >= this->getHeight()) {
152  output[0] = 0.0f;
153  }
154  else {
155  int offset = (yi * this->getWidth() + xi) * 3;
156  copy_v3_v3(output, &this->m_imageFloatBuffer[offset]);
157  }
158  }
159 }
160 
161 } // namespace blender::compositor
struct RenderPass * BKE_image_multilayer_index(struct RenderResult *rr, struct ImageUser *iuser)
Definition: image.c:3813
void BKE_stamp_info_callback(void *data, struct StampData *stamp_data, StampCallback callback, bool noskip)
Definition: image.c:2686
#define BLI_assert(a)
Definition: BLI_assert.h:58
int BLI_findindex(const struct ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void zero_v4(float r[4])
size_t BLI_strnlen(const char *str, const size_t maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: string.c:878
static AppView * view
_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 bicubic_interpolation_color(struct ImBuf *in, unsigned char outI[4], float outF[4], float u, float v)
Definition: imageprocess.c:98
void bilinear_interpolation_color(struct ImBuf *in, unsigned char outI[4], float outF[4], float u, float v)
Definition: imageprocess.c:130
void nearest_interpolation_color(struct ImBuf *in, unsigned char outI[4], float outF[4], float u, float v)
Definition: imageprocess.c:242
Contains defines and structs used throughout the imbuf module.
#define output
struct RenderResult * rr
MultilayerBaseOperation(RenderLayer *render_layer, RenderPass *render_pass, int view)
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override
calculate a single pixel
std::unique_ptr< MetaData > getMetaData() override
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override
calculate a single pixel
void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override
calculate a single pixel
StringRef BKE_cryptomatte_extract_layer_name(const StringRef render_pass_name)
Definition: cryptomatte.cc:496
ListBase passes
Definition: RE_pipeline.h:108
char name[RE_MAXNAME]
Definition: RE_pipeline.h:100
char name[64]
Definition: RE_pipeline.h:80
struct StampData * stamp_data
Definition: RE_pipeline.h:157
void setCryptomatteKeys(blender::StringRef cryptomatte_layer_name)
Definition: COM_MetaData.cc:82
static void extract_cryptomatte_meta_data(void *_data, const char *propname, char *propvalue, int UNUSED(len))
Definition: COM_MetaData.cc:92