Changeset View
Changeset View
Standalone View
Standalone View
source/blender/compositor/operations/COM_ScaleOperation.h
| Show All 18 Lines | |||||
| #pragma once | #pragma once | ||||
| #include "COM_MultiThreadedOperation.h" | #include "COM_MultiThreadedOperation.h" | ||||
| namespace blender::compositor { | namespace blender::compositor { | ||||
| class BaseScaleOperation : public MultiThreadedOperation { | class BaseScaleOperation : public MultiThreadedOperation { | ||||
| public: | public: | ||||
| static constexpr float DEFAULT_MAX_SCALE_CANVAS_SIZE = 12000; | |||||
| public: | |||||
| void setSampler(PixelSampler sampler) | void setSampler(PixelSampler sampler) | ||||
| { | { | ||||
| this->m_sampler = (int)sampler; | this->m_sampler = (int)sampler; | ||||
| } | } | ||||
| void setVariableSize(bool variable_size) | void setVariableSize(bool variable_size) | ||||
| { | { | ||||
| m_variable_size = variable_size; | m_variable_size = variable_size; | ||||
| }; | }; | ||||
| void set_scale_canvas_max_size(Size2f size); | |||||
| protected: | protected: | ||||
| BaseScaleOperation(); | BaseScaleOperation(); | ||||
| PixelSampler getEffectiveSampler(PixelSampler sampler) | PixelSampler getEffectiveSampler(PixelSampler sampler) | ||||
| { | { | ||||
| return (m_sampler == -1) ? sampler : (PixelSampler)m_sampler; | return (m_sampler == -1) ? sampler : (PixelSampler)m_sampler; | ||||
| } | } | ||||
| Size2f max_scale_canvas_size_ = {DEFAULT_MAX_SCALE_CANVAS_SIZE, DEFAULT_MAX_SCALE_CANVAS_SIZE}; | |||||
| int m_sampler; | int m_sampler; | ||||
| /* TODO(manzanilla): to be removed with tiled implementation. */ | |||||
| bool m_variable_size; | bool m_variable_size; | ||||
| }; | }; | ||||
| class ScaleOperation : public BaseScaleOperation { | class ScaleOperation : public BaseScaleOperation { | ||||
| public: | public: | ||||
| static constexpr float MIN_SCALE = 0.0001f; | static constexpr float MIN_RELATIVE_SCALE = 0.0001f; | ||||
| protected: | protected: | ||||
| static constexpr int IMAGE_INPUT_INDEX = 0; | |||||
| static constexpr int X_INPUT_INDEX = 1; | |||||
| static constexpr int Y_INPUT_INDEX = 2; | |||||
| SocketReader *m_inputOperation; | SocketReader *m_inputOperation; | ||||
| SocketReader *m_inputXOperation; | SocketReader *m_inputXOperation; | ||||
| SocketReader *m_inputYOperation; | SocketReader *m_inputYOperation; | ||||
| float m_centerX; | float canvas_center_x_; | ||||
| float m_centerY; | float canvas_center_y_; | ||||
| public: | public: | ||||
| ScaleOperation(); | ScaleOperation(); | ||||
| ScaleOperation(DataType data_type); | ScaleOperation(DataType data_type); | ||||
| static float scale_coord(const float coord, const float center, const float relative_scale) | static float scale_coord(const float coord, const float center, const float relative_scale) | ||||
| { | { | ||||
| return center + (coord - center) / MAX2(relative_scale, MIN_SCALE); | return center + (coord - center) * MAX2(relative_scale, MIN_RELATIVE_SCALE); | ||||
| } | } | ||||
| static void scale_area(rcti &rect, float center_x, float center_y, float scale_x, float scale_y); | |||||
| static float scale_coord_inverted(const float coord, | |||||
| const float center, | |||||
| const float relative_scale) | |||||
| { | |||||
| return center + (coord - center) / MAX2(relative_scale, MIN_RELATIVE_SCALE); | |||||
| } | |||||
| static void get_scale_offset(const rcti &input_canvas, | |||||
| const rcti &scale_canvas, | |||||
| float &r_scale_offset_x, | |||||
| float &r_scale_offset_y); | |||||
| static void scale_area(rcti &area, float relative_scale_x, float relative_scale_y); | |||||
| static void get_scale_area_of_interest(const rcti &input_canvas, | |||||
| const rcti &scale_canvas, | |||||
| const float relative_scale_x, | |||||
| const float relative_scale_y, | |||||
| const rcti &output_area, | |||||
| rcti &r_input_area); | |||||
| static void clamp_area_size_max(rcti &area, Size2f max_size); | |||||
| void init_data() override; | void init_data() override; | ||||
| void initExecution() override; | void initExecution() override; | ||||
| void deinitExecution() override; | void deinitExecution() override; | ||||
| void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override; | void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override; | ||||
| void update_memory_buffer_partial(MemoryBuffer *output, | void update_memory_buffer_partial(MemoryBuffer *output, | ||||
| const rcti &area, | const rcti &area, | ||||
| Span<MemoryBuffer *> inputs) override; | Span<MemoryBuffer *> inputs) override; | ||||
| void determine_canvas(const rcti &preferred_area, rcti &r_area) override; | |||||
| protected: | protected: | ||||
| virtual float get_relative_scale_x_factor() = 0; | virtual float get_relative_scale_x_factor(float width) = 0; | ||||
| virtual float get_relative_scale_y_factor() = 0; | virtual float get_relative_scale_y_factor(float height) = 0; | ||||
| private: | private: | ||||
| bool is_scaling_variable(); | |||||
| float get_constant_scale(int input_op_idx, float factor); | float get_constant_scale(int input_op_idx, float factor); | ||||
| float get_constant_scale_x(); | float get_constant_scale_x(float width); | ||||
| float get_constant_scale_y(); | float get_constant_scale_y(float height); | ||||
| void scale_area(rcti &rect, float scale_x, float scale_y); | |||||
| }; | }; | ||||
| class ScaleRelativeOperation : public ScaleOperation { | class ScaleRelativeOperation : public ScaleOperation { | ||||
| public: | public: | ||||
| ScaleRelativeOperation(); | ScaleRelativeOperation(); | ||||
| ScaleRelativeOperation(DataType data_type); | ScaleRelativeOperation(DataType data_type); | ||||
| bool determineDependingAreaOfInterest(rcti *input, | bool determineDependingAreaOfInterest(rcti *input, | ||||
| ReadBufferOperation *readOperation, | ReadBufferOperation *readOperation, | ||||
| rcti *output) override; | rcti *output) override; | ||||
| void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override; | void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override; | ||||
| float get_relative_scale_x_factor() override | |||||
| float get_relative_scale_x_factor(float UNUSED(width)) override | |||||
| { | { | ||||
| return 1.0f; | return 1.0f; | ||||
| } | } | ||||
| float get_relative_scale_y_factor() override | |||||
| float get_relative_scale_y_factor(float UNUSED(height)) override | |||||
| { | { | ||||
| return 1.0f; | return 1.0f; | ||||
| } | } | ||||
| }; | }; | ||||
| class ScaleAbsoluteOperation : public ScaleOperation { | class ScaleAbsoluteOperation : public ScaleOperation { | ||||
| public: | public: | ||||
| bool determineDependingAreaOfInterest(rcti *input, | bool determineDependingAreaOfInterest(rcti *input, | ||||
| ReadBufferOperation *readOperation, | ReadBufferOperation *readOperation, | ||||
| rcti *output) override; | rcti *output) override; | ||||
| void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override; | void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override; | ||||
| float get_relative_scale_x_factor() override | |||||
| float get_relative_scale_x_factor(float width) override | |||||
| { | { | ||||
| return 1.0f / getWidth(); | return 1.0f / width; | ||||
| } | } | ||||
| float get_relative_scale_y_factor() override | |||||
| float get_relative_scale_y_factor(float height) override | |||||
| { | { | ||||
| return 1.0f / getHeight(); | return 1.0f / height; | ||||
| } | } | ||||
| }; | }; | ||||
| class ScaleFixedSizeOperation : public BaseScaleOperation { | class ScaleFixedSizeOperation : public BaseScaleOperation { | ||||
| SocketReader *m_inputOperation; | SocketReader *m_inputOperation; | ||||
| int m_newWidth; | int m_newWidth; | ||||
| int m_newHeight; | int m_newHeight; | ||||
| float m_relX; | float m_relX; | ||||
| float m_relY; | float m_relY; | ||||
| /* center is only used for aspect correction */ | /* center is only used for aspect correction */ | ||||
| float m_offsetX; | float m_offsetX; | ||||
| float m_offsetY; | float m_offsetY; | ||||
| bool m_is_aspect; | bool m_is_aspect; | ||||
| bool m_is_crop; | bool m_is_crop; | ||||
| /* set from other properties on initialization, | /* set from other properties on initialization, | ||||
| * check if we need to apply offset */ | * check if we need to apply offset */ | ||||
| bool m_is_offset; | bool m_is_offset; | ||||
| public: | public: | ||||
| ScaleFixedSizeOperation(); | ScaleFixedSizeOperation(); | ||||
| bool determineDependingAreaOfInterest(rcti *input, | bool determineDependingAreaOfInterest(rcti *input, | ||||
| ReadBufferOperation *readOperation, | ReadBufferOperation *readOperation, | ||||
| rcti *output) override; | rcti *output) override; | ||||
| void determineResolution(unsigned int resolution[2], | void determine_canvas(const rcti &preferred_area, rcti &r_area) override; | ||||
| unsigned int preferredResolution[2]) override; | |||||
| void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override; | void executePixelSampled(float output[4], float x, float y, PixelSampler sampler) override; | ||||
| void init_data() override; | |||||
| void initExecution() override; | void initExecution() override; | ||||
| void deinitExecution() override; | void deinitExecution() override; | ||||
| void setNewWidth(int width) | void setNewWidth(int width) | ||||
| { | { | ||||
| this->m_newWidth = width; | this->m_newWidth = width; | ||||
| } | } | ||||
| void setNewHeight(int height) | void setNewHeight(int height) | ||||
| { | { | ||||
| Show All 12 Lines | void setOffset(float x, float y) | ||||
| this->m_offsetX = x; | this->m_offsetX = x; | ||||
| this->m_offsetY = y; | this->m_offsetY = y; | ||||
| } | } | ||||
| void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override; | void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override; | ||||
| void update_memory_buffer_partial(MemoryBuffer *output, | void update_memory_buffer_partial(MemoryBuffer *output, | ||||
| const rcti &area, | const rcti &area, | ||||
| Span<MemoryBuffer *> inputs) override; | Span<MemoryBuffer *> inputs) override; | ||||
| private: | |||||
| void init_data(const rcti &input_canvas); | |||||
| }; | }; | ||||
| } // namespace blender::compositor | } // namespace blender::compositor | ||||