Blender V4.3
realize_on_domain_operation.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_math_matrix.hh"
6
8#include "COM_context.hh"
9#include "COM_domain.hh"
11#include "COM_result.hh"
12
14
16
17/* ------------------------------------------------------------------------------------------------
18 * Realize On Domain Operation
19 */
20
22 Domain domain,
23 ResultType type)
24 : SimpleOperation(context), domain_(domain)
25{
26 InputDescriptor input_descriptor;
27 input_descriptor.type = type;
28 declare_input_descriptor(input_descriptor);
29 populate_result(context.create_result(type));
30}
31
33{
34 const Domain &in_domain = get_input().domain();
35
36 /* Even and odd-sized domains have different pixel locations, which produces unexpected
37 * filtering. If one is odd and the other is even (detected by testing the low bit of the xor of
38 * the sizes), shift the input by 1/2 pixel so the pixels align. */
39 const float2 translation(((in_domain.size[0] ^ domain_.size[0]) & 1) ? -0.5f : 0.0f,
40 ((in_domain.size[1] ^ domain_.size[1]) & 1) ? -0.5f : 0.0f);
41
43 get_input(),
44 get_result(),
45 domain_,
46 math::translate(in_domain.transformation, translation),
47 get_input().get_realization_options());
48}
49
54
56 Context &context,
57 const Result &input_result,
58 const InputDescriptor &input_descriptor,
59 const Domain &operation_domain)
60{
61 /* This input doesn't need realization, the operation is not needed. */
63 return nullptr;
64 }
65
66 /* The input expects a single value and if no single value is provided, it will be ignored and a
67 * default value will be used, so no need to realize it and the operation is not needed. */
68 if (input_descriptor.expects_single_value) {
69 return nullptr;
70 }
71
72 /* Input result is a single value and does not need realization, the operation is not needed. */
73 if (input_result.is_single_value()) {
74 return nullptr;
75 }
76
77 /* The input have an identical domain to the operation domain, so no need to realize it and the
78 * operation is not needed. */
79 if (input_result.domain() == operation_domain) {
80 return nullptr;
81 }
82
83 /* Otherwise, realization is needed. */
84 return new RealizeOnDomainOperation(context, operation_domain, input_descriptor.type);
85}
86
87} // namespace blender::realtime_compositor
RealizeOnDomainOperation(Context &context, Domain domain, ResultType type)
static SimpleOperation * construct_if_needed(Context &context, const Result &input_result, const InputDescriptor &input_descriptor, const Domain &operation_domain)
const Domain & domain() const
Definition result.cc:712
void declare_input_descriptor(InputDescriptor descriptor)
MatBase< T, NumCol, NumRow > translate(const MatBase< T, NumCol, NumRow > &mat, const VectorT &translation)
void realize_on_domain(Context &context, Result &input, Result &output, const Domain &domain, const float3x3 &input_transformation, const RealizationOptions &realization_options)