Blender V5.3
domain.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BLI_assert.hh"
6#include "BLI_bounds.hh"
7#include "BLI_bounds_types.hh"
8#include "BLI_math_matrix.hh"
11
12#include "BLT_translation.hh"
13
14#include "GPU_texture.hh"
15
16#include "COM_domain.hh"
17
18namespace blender::compositor {
19
20Domain::Domain(const int2 &size)
21 : data_size(size),
22 display_size(size),
23 data_offset(int2(0)),
25{
26}
27
32
33void Domain::transform(const float3x3 &input_transformation)
34{
35 transformation = input_transformation * transformation;
36}
37
39{
40 Domain domain = *this;
41 domain.data_size = int2(this->data_size.y, this->data_size.x);
42 domain.display_size = int2(this->display_size.y, this->display_size.x);
43 domain.data_offset = int2(this->data_offset.y, this->data_offset.x);
44 return domain;
45}
46
51
52bool Domain::is_equal(const Domain &a, const Domain &b, const float epsilon)
53{
54 return a.data_size == b.data_size && a.display_size == b.display_size &&
55 a.data_offset == b.data_offset &&
56 math::is_equal(a.transformation, b.transformation, epsilon);
57}
58
59Domain Domain::realize_transformation(const bool realize_translation) const
60{
61 /* If the domain is only infinitesimally rotated or scaled, only realize the translation if
62 * needed, otherwise, return as is. */
65 Domain realized_domain = *this;
66 realized_domain.transformation = realize_translation ? float3x3::identity() : translation;
67 return realized_domain;
68 }
69
70 /* Eliminate the translation component of the transformation. Translation is ignored since it has
71 * no effect on the size of the domain and will be restored later if needed. */
72 const float3x3 transformation = float3x3(float2x2(this->transformation));
73
74 /* Translate the input such that it is centered in the virtual compositing space. */
75 const float2 center_translation = -float2(this->display_size) / 2.0f;
76 const float3x3 centered_transformation = math::translate(transformation, center_translation);
77
78 /* Compute display window after transformation. */
79 const Bounds<float2> display_window = {float2(0.0f), float2(this->display_size)};
80 const Bounds<float2> new_display_window = bounds::transform_bounds(centered_transformation,
81 display_window);
82 const Bounds<int2> new_integer_display_window = {int2(math::floor(new_display_window.min)),
83 int2(math::ceil(new_display_window.max))};
84
85 /* Compute data window after transformation. */
86 const Bounds<float2> data_window = {float2(this->data_offset),
87 float2(this->data_offset + this->data_size)};
88 const Bounds<float2> new_data_window = bounds::transform_bounds(centered_transformation,
89 data_window);
90 const Bounds<int2> new_integer_data_window = {int2(math::floor(new_data_window.min)),
91 int2(math::ceil(new_data_window.max))};
92
93 Domain realized_domain = *this;
94 realized_domain.display_size = math::max(int2(1), new_integer_display_window.size());
95 realized_domain.data_size = math::max(int2(1), new_integer_data_window.size());
96 realized_domain.data_offset = new_integer_data_window.min - new_integer_display_window.min;
97 realized_domain.transformation = realize_translation ? float3x3::identity() : translation;
98 return realized_domain;
99}
100
101bool operator==(const Domain &a, const Domain &b)
102{
103 return a.data_size == b.data_size && a.display_size == b.display_size &&
104 a.data_offset == b.data_offset && a.transformation == b.transformation;
105}
106
107bool operator!=(const Domain &a, const Domain &b)
108{
109 return !(a == b);
110}
111
113{
114 switch (interpolation) {
116 return N_("Nearest");
118 return N_("Bilinear");
120 return N_("Bicubic");
122 return N_("Anisotropic");
123 }
124
126 return "None";
127}
128
130{
131 switch (extension) {
133 return N_("Extend");
135 return N_("Repeat");
136 case Extension::Clip:
137 return N_("Clip");
138 }
139
141 return "None";
142}
143
160
161} // namespace blender::compositor
#define BLI_assert_unreachable()
Domain realize_transformation(const bool realize_translation=false) const
Definition domain.cc:59
Domain(const int2 &size)
Definition domain.cc:20
static bool is_equal(const Domain &a, const Domain &b, const float epsilon=10e-6f)
Definition domain.cc:52
Domain transposed() const
Definition domain.cc:38
void transform(const float3x3 &input_transformation)
Definition domain.cc:33
static Domain identity()
Definition domain.cc:47
Bounds< VecBase< T, 3 > > transform_bounds(const MatBase< T, D, D > &matrix, const Bounds< VecBase< T, 3 > > &bounds)
StringRefNull to_string(const Interpolation &interpolation)
Definition domain.cc:112
bool operator==(const BokehKernelKey &a, const BokehKernelKey &b)
GPUSamplerExtendMode map_extension_mode_to_extend_mode(const Extension &mode)
Definition domain.cc:144
bool operator!=(const Domain &a, const Domain &b)
Definition domain.cc:107
T floor(const T &a)
MatBase< T, NumCol, NumRow > translate(const MatBase< T, NumCol, NumRow > &mat, const VectorT &translation)
T ceil(const T &a)
bool is_equal(const MatBase< T, NumCol, NumRow > &a, const MatBase< T, NumCol, NumRow > &b, const T epsilon=T(0))
T max(const T &a, const T &b)
MatT from_location(const typename MatT::loc_type &location)
MatBase< float, 2, 2 > float2x2
@ GPU_SAMPLER_EXTEND_MODE_CLAMP_TO_BORDER
@ GPU_SAMPLER_EXTEND_MODE_REPEAT
@ GPU_SAMPLER_EXTEND_MODE_EXTEND
#define N_(msgid)