Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/compositor/operations/COM_ScaleOperation.h')
-rw-r--r--source/blender/compositor/operations/COM_ScaleOperation.h64
1 files changed, 47 insertions, 17 deletions
diff --git a/source/blender/compositor/operations/COM_ScaleOperation.h b/source/blender/compositor/operations/COM_ScaleOperation.h
index 04fa4fe62d1..2f33bbb5032 100644
--- a/source/blender/compositor/operations/COM_ScaleOperation.h
+++ b/source/blender/compositor/operations/COM_ScaleOperation.h
@@ -47,24 +47,49 @@ class BaseScaleOperation : public MultiThreadedOperation {
class ScaleOperation : public BaseScaleOperation {
public:
- static constexpr float MIN_SCALE = 0.0001f;
+ static constexpr float MIN_SCALE_FACTOR = 0.0001f;
+ static constexpr float MAX_CANVAS_SCALE_FACTOR = 2.0f;
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_inputXOperation;
SocketReader *m_inputYOperation;
- float m_centerX;
- float m_centerY;
+ float canvas_center_x_;
+ float canvas_center_y_;
+ float input_width_scaled_;
+ float input_height_scaled_;
+ float scale_offset_x_;
+ float scale_offset_y_;
public:
ScaleOperation();
ScaleOperation(DataType data_type);
- static float scale_coord(const float coord, const float center, const float relative_scale)
+ /** Scale a coordinate from a center inverting given relative scale . */
+ static float scale_coord_inverted(const float coord,
+ const float center,
+ const float relative_scale)
+ {
+ return center + (coord - center) / MAX2(relative_scale, MIN_SCALE_FACTOR);
+ }
+
+ static float scale_coord(float coord, float scale_offset, float relative_scale)
{
- return center + (coord - center) / MAX2(relative_scale, MIN_SCALE);
+ return (scale_offset + coord) /
+ (relative_scale < MIN_SCALE_FACTOR ? MIN_SCALE_FACTOR : relative_scale);
}
- static void scale_area(rcti &rect, float center_x, float center_y, float scale_x, float scale_y);
+
+ static void scale_area(rcti &rect,
+ float scale_offset_x,
+ float scale_offset_y,
+ float relative_scale_x,
+ float relative_scale_y);
+ static void scale_area_inverted(
+ rcti &rect, float center_x, float center_y, float scale_x, float scale_y);
void init_data() override;
void initExecution() override;
@@ -75,15 +100,16 @@ class ScaleOperation : public BaseScaleOperation {
const rcti &area,
Span<MemoryBuffer *> inputs) override;
+ void determine_canvas(const rcti &preferred_area, rcti &r_area) override;
+
protected:
- virtual float get_relative_scale_x_factor() = 0;
- virtual float get_relative_scale_y_factor() = 0;
+ virtual float get_relative_scale_x_factor(float width) = 0;
+ virtual float get_relative_scale_y_factor(float height) = 0;
private:
float get_constant_scale(int input_op_idx, float factor);
- float get_constant_scale_x();
- float get_constant_scale_y();
- void scale_area(rcti &rect, float scale_x, float scale_y);
+ float get_constant_scale_x(float width);
+ float get_constant_scale_y(float height);
};
class ScaleRelativeOperation : public ScaleOperation {
@@ -94,11 +120,13 @@ class ScaleRelativeOperation : public ScaleOperation {
ReadBufferOperation *readOperation,
rcti *output) 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;
}
- float get_relative_scale_y_factor() override
+
+ float get_relative_scale_y_factor(float height) override
{
return 1.0f;
}
@@ -110,13 +138,15 @@ class ScaleAbsoluteOperation : public ScaleOperation {
ReadBufferOperation *readOperation,
rcti *output) 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;
}
};