From 76377f0176b9561a7fc8f46b4ed704c631ddd90d Mon Sep 17 00:00:00 2001 From: Manuel Castilla Date: Tue, 28 Sep 2021 19:32:49 +0200 Subject: Compositor: Replace resolution concept by canvas This is a code refactor in preparation of supporting canvas compositing. See {D12466}. No functional changes, all canvases are at (0,0) position matching tiled implementation. Differential Revision: https://developer.blender.org/D12465 --- .../blender/compositor/intern/COM_NodeOperation.h | 92 +++++++++------------- 1 file changed, 36 insertions(+), 56 deletions(-) (limited to 'source/blender/compositor/intern/COM_NodeOperation.h') diff --git a/source/blender/compositor/intern/COM_NodeOperation.h b/source/blender/compositor/intern/COM_NodeOperation.h index ef7cf319222..9f113b60345 100644 --- a/source/blender/compositor/intern/COM_NodeOperation.h +++ b/source/blender/compositor/intern/COM_NodeOperation.h @@ -130,7 +130,7 @@ class NodeOperationInput { SocketReader *getReader(); - void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]); + bool determine_canvas(const rcti &preferred_area, rcti &r_area); #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("COM:NodeOperation") @@ -158,12 +158,7 @@ class NodeOperationOutput { return m_datatype; } - /** - * \brief determine the resolution of this data going through this socket - * \param resolution: the result of this operation - * \param preferredResolution: the preferable resolution as no resolution could be determined - */ - void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]); + void determine_canvas(const rcti &preferred_area, rcti &r_area); #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("COM:NodeOperation") @@ -211,9 +206,9 @@ struct NodeOperationFlags { bool use_viewer_border : 1; /** - * Is the resolution of the operation set. + * Is the canvas of the operation set. */ - bool is_resolution_set : 1; + bool is_canvas_set : 1; /** * Is this a set operation (value, color, vector). @@ -257,7 +252,7 @@ struct NodeOperationFlags { open_cl = false; use_render_border = false; use_viewer_border = false; - is_resolution_set = false; + is_canvas_set = false; is_set_operation = false; is_read_buffer_operation = false; is_write_buffer_operation = false; @@ -324,11 +319,11 @@ class NodeOperation { bool is_hash_output_params_implemented_; /** - * \brief the index of the input socket that will be used to determine the resolution + * \brief the index of the input socket that will be used to determine the canvas */ - unsigned int m_resolutionInputSocketIndex; + unsigned int canvas_input_index_; - std::function modify_determined_resolution_fn_; + std::function modify_determined_canvas_fn_; /** * \brief mutex reference for very special node initializations @@ -352,15 +347,7 @@ class NodeOperation { */ eExecutionModel execution_model_; - /** - * Width of the output of this operation. - */ - unsigned int m_width; - - /** - * Height of the output of this operation. - */ - unsigned int m_height; + rcti canvas_; /** * Flags how to evaluate this operation. @@ -374,11 +361,6 @@ class NodeOperation { { } - void set_execution_model(const eExecutionModel model) - { - execution_model_ = model; - } - void set_name(const std::string name) { m_name = name; @@ -424,14 +406,7 @@ class NodeOperation { return getInputOperation(index); } - /** - * \brief determine the resolution of this node - * \note this method will not set the resolution, this is the responsibility of the caller - * \param resolution: the result of this operation - * \param preferredResolution: the preferable resolution as no resolution could be determined - */ - virtual void determineResolution(unsigned int resolution[2], - unsigned int preferredResolution[2]); + virtual void determine_canvas(const rcti &preferred_area, rcti &r_area); /** * \brief isOutputOperation determines whether this operation is an output of the @@ -453,6 +428,11 @@ class NodeOperation { return false; } + void set_execution_model(const eExecutionModel model) + { + execution_model_ = model; + } + void setbNodeTree(const bNodeTree *tree) { this->m_btree = tree; @@ -527,19 +507,19 @@ class NodeOperation { } virtual void deinitExecution(); - /** - * \brief set the resolution - * \param resolution: the resolution to set - */ - void setResolution(unsigned int resolution[2]) + void set_canvas(const rcti &canvas_area) { - if (!this->flags.is_resolution_set) { - this->m_width = resolution[0]; - this->m_height = resolution[1]; - this->flags.is_resolution_set = true; + if (!this->flags.is_canvas_set) { + canvas_ = canvas_area; + flags.is_canvas_set = true; } } + const rcti &get_canvas() const + { + return canvas_; + } + /** * \brief is this operation the active viewer output * user can select an ViewerNode to be active @@ -557,18 +537,18 @@ class NodeOperation { rcti *output); /** - * \brief set the index of the input socket that will determine the resolution of this + * \brief set the index of the input socket that will determine the canvas of this * operation \param index: the index to set */ - void setResolutionInputSocketIndex(unsigned int index); + void set_canvas_input_index(unsigned int index); /** - * Set a custom function to modify determined resolution from main input just before setting it - * as preferred resolution for the other inputs. + * Set a custom function to modify determined canvas from main input just before setting it + * as preferred for the other inputs. */ - void set_determined_resolution_modifier(std::function fn) + void set_determined_canvas_modifier(std::function fn) { - modify_determined_resolution_fn_ = fn; + modify_determined_canvas_fn_ = fn; } /** @@ -595,12 +575,12 @@ class NodeOperation { unsigned int getWidth() const { - return m_width; + return BLI_rcti_size_x(&canvas_); } unsigned int getHeight() const { - return m_height; + return BLI_rcti_size_y(&canvas_); } inline void readSampled(float result[4], float x, float y, PixelSampler sampler) @@ -699,13 +679,13 @@ class NodeOperation { void setWidth(unsigned int width) { - this->m_width = width; - this->flags.is_resolution_set = true; + canvas_.xmax = canvas_.xmin + width; + this->flags.is_canvas_set = true; } void setHeight(unsigned int height) { - this->m_height = height; - this->flags.is_resolution_set = true; + canvas_.ymax = canvas_.ymin + height; + this->flags.is_canvas_set = true; } SocketReader *getInputSocketReader(unsigned int inputSocketindex); NodeOperation *getInputOperation(unsigned int inputSocketindex); -- cgit v1.2.3 From f84fb12f5d72433780a96c3cc4381399f153cf1a Mon Sep 17 00:00:00 2001 From: Manuel Castilla Date: Tue, 28 Sep 2021 19:33:06 +0200 Subject: Compositor: Add support for canvas compositing This commit adds functionality for operations that require pixel translation or resizing on "Full Frame" mode, allowing to adjust their canvas. It fixes most cropping issues in translate, scale, rotate and transform nodes by adjusting their canvas to the result, instead of the input canvas. Operations output buffer is still always on (0,0) position for easier image algorithm implementation, even when the canvas is not. Current limitations (will be addressed on bcon2): - Displayed translation in Viewer node is limited to 6000px. - When scaling up the canvas size is limited to the scene resolution size x 1.5 . From that point it crops. If none of these limitations are hit, the Viewer node displays the full input with any translation. Differential Revision: https://developer.blender.org/D12466 --- .../blender/compositor/intern/COM_NodeOperation.h | 32 +++++++++++----------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'source/blender/compositor/intern/COM_NodeOperation.h') diff --git a/source/blender/compositor/intern/COM_NodeOperation.h b/source/blender/compositor/intern/COM_NodeOperation.h index 9f113b60345..f507665bee3 100644 --- a/source/blender/compositor/intern/COM_NodeOperation.h +++ b/source/blender/compositor/intern/COM_NodeOperation.h @@ -62,9 +62,13 @@ enum class ResizeMode { /** \brief Center the input image to the center of the working area of the node, no resizing * occurs */ Center = NS_CR_CENTER, - /** \brief The bottom left of the input image is the bottom left of the working area of the node, - * no resizing occurs */ + /** No resizing or translation. */ None = NS_CR_NONE, + /** + * Input image is translated so that its bottom left matches the bottom left of the working area + * of the node, no resizing occurs. + */ + Align = 100, /** \brief Fit the width of the input image to the width of the working area of the node */ FitWidth = NS_CR_FIT_WIDTH, /** \brief Fit the height of the input image to the height of the working area of the node */ @@ -381,6 +385,9 @@ class NodeOperation { return m_id; } + float get_constant_value_default(float default_value); + const float *get_constant_elem_default(const float *default_elem); + const NodeOperationFlags get_flags() const { return flags; @@ -507,18 +514,9 @@ class NodeOperation { } virtual void deinitExecution(); - void set_canvas(const rcti &canvas_area) - { - if (!this->flags.is_canvas_set) { - canvas_ = canvas_area; - flags.is_canvas_set = true; - } - } - - const rcti &get_canvas() const - { - return canvas_; - } + void set_canvas(const rcti &canvas_area); + const rcti &get_canvas() const; + void unset_canvas(); /** * \brief is this operation the active viewer output @@ -575,12 +573,12 @@ class NodeOperation { unsigned int getWidth() const { - return BLI_rcti_size_x(&canvas_); + return BLI_rcti_size_x(&get_canvas()); } unsigned int getHeight() const { - return BLI_rcti_size_y(&canvas_); + return BLI_rcti_size_y(&get_canvas()); } inline void readSampled(float result[4], float x, float y, PixelSampler sampler) @@ -677,6 +675,7 @@ class NodeOperation { void addInputSocket(DataType datatype, ResizeMode resize_mode = ResizeMode::Center); void addOutputSocket(DataType datatype); + /* TODO(manzanilla): to be removed with tiled implementation. */ void setWidth(unsigned int width) { canvas_.xmax = canvas_.xmin + width; @@ -687,6 +686,7 @@ class NodeOperation { canvas_.ymax = canvas_.ymin + height; this->flags.is_canvas_set = true; } + SocketReader *getInputSocketReader(unsigned int inputSocketindex); NodeOperation *getInputOperation(unsigned int inputSocketindex); -- cgit v1.2.3