19template<
typename From,
typename To, To (*ConversionF)(const From &)>
24 static const std::string conversion_name = from_type.
name() +
" to " + to_type.
name();
26 static auto multi_function = mf::build::SI1_SO<From, To>(
27 conversion_name.c_str(),
30 [](
const From &a) { return ConversionF(a); },
31 mf::build::exec_presets::AllSpanOrSingle());
32 static auto convert_single_to_initialized = [](
const void *src,
void *dst) {
33 *(To *)dst = ConversionF(*(
const From *)src);
35 static auto convert_single_to_uninitialized = [](
const void *src,
void *dst) {
36 new (dst) To(ConversionF(*(
const From *)src));
38 conversions.
add(mf::DataType::ForSingle<From>(),
39 mf::DataType::ForSingle<To>(),
41 convert_single_to_initialized,
42 convert_single_to_uninitialized);
76 a,
float(std::numeric_limits<int8_t>::min()),
float(std::numeric_limits<int8_t>::max()));
93 return float3(a.x, a.y, 0.0f);
97 return float4(a.x, a.y, 0.0f, 0.0f);
101 return (a.x + a.y) / 2.0f;
105 return int32_t((a.x + a.y) / 2.0f);
113 return int2(a.x, a.y);
142 return (a.x + a.y + a.z) / 3.0f;
146 return int((a.x + a.y + a.z) / 3.0f);
154 return int2(a.x, a.y);
187 return (a.x + a.y + a.z + a.w) / 4.0f;
191 return int((a.x + a.y + a.z + a.w) / 4.0f);
199 return int2(a.x, a.y);
229 a,
int(std::numeric_limits<int8_t>::min()),
int(std::numeric_limits<int8_t>::max()));
278 return int2(a.x, a.y);
290 return float3(
float(a.x),
float(a.y), 0.0f);
294 return float4(
float(a.x),
float(a.y), 0.0f, 0.0f);
331 return float3(
float(a.x),
float(a.y), 0.0f);
335 return float4(
float(a.x),
float(a.y), 0.0f, 0.0f);
471 return a.
r > 0 || a.
g > 0 || a.
b > 0;
673 const void *from_value,
674 void *to_value)
const
676 if (from_type == to_type) {
682 DataType::ForSingle(from_type), DataType::ForSingle(to_type));
689 const mf::MultiFunction &
fn,
694 params.add_readonly_single_input(from);
695 params.add_uninitialized_single_output(to);
696 mf::ContextBuilder context;
701 const mf::MultiFunction &
fn,
716 DataType::ForSingle(to_type));
732 :
GVArrayImpl(to_type, varray.
size()), varray_(std::move(varray)), from_type_(varray_.
type())
738 void get(
const int64_t index,
void *r_value)
const override
741 varray_.
get(index, buffer);
746 void get_to_uninitialized(
const int64_t index,
void *r_value)
const override
749 varray_.
get(index, buffer);
756 const bool dst_is_uninitialized)
const override
758 if (!dst_is_uninitialized) {
762 *old_to_new_conversions_.multi_function,
764 {this->type(), dst, mask.min_array_size()});
780 varray_(std::move(varray)),
781 from_type_(varray_.
type())
788 void get(
const int64_t index,
void *r_value)
const override
791 varray_.
get(index, buffer);
796 void get_to_uninitialized(
const int64_t index,
void *r_value)
const override
799 varray_.
get(index, buffer);
804 void set_by_move(
const int64_t index,
void *value)
override
811 void materialize(
const IndexMask &
mask,
813 const bool dst_is_uninitialized)
const override
815 if (!dst_is_uninitialized) {
816 type_->destruct_n(dst,
mask.min_array_size());
819 *old_to_new_conversions_.multi_function,
821 {this->type(), dst, mask.min_array_size()});
828 if (from_type == to_type) {
841 if (from_type == to_type) {
848 std::move(varray), to_type, *
this);
854 if (from_type == to_type) {
861 mf::DataType::ForSingle(from_type), mf::DataType::ForSingle(to_type));
#define BUFFER_FOR_CPP_TYPE_VALUE(type, variable_name)
BLI_INLINE float IMB_colormanagement_get_luminance(const float rgb[3])
static const CPPType & get()
void destruct_n(void *ptr, int64_t n) const
StringRefNull name() const
void copy_construct(const void *src, void *dst) const
void destruct(void *ptr) const
const CPPType & type() const
const CPPType & type() const
const CPPType & type() const
void get(int64_t index, void *r_value) const
GVArrayImpl(const CPPType &type, int64_t size)
const CPPType & type() const
static GVArray from(Args &&...args)
static GVArray from_span(GSpan span)
GVMutableArrayImpl(const CPPType &type, int64_t size)
static GVMutableArray from(Args &&...args)
void set_by_relocate(int64_t index, void *value)
void convert_to_uninitialized(const CPPType &from_type, const CPPType &to_type, const void *from_value, void *to_value) const
void add(mf::DataType from_type, mf::DataType to_type, const mf::MultiFunction &fn, void(*convert_single_to_initialized)(const void *src, void *dst), void(*convert_single_to_uninitialized)(const void *src, void *dst))
void convert_to_initialized_n(GSpan from_span, GMutableSpan to_span) const
const ConversionFunctions * get_conversion_functions(mf::DataType from, mf::DataType to) const
bool is_convertible(const CPPType &from_type, const CPPType &to_type) const
GVArray try_convert(GVArray varray, const CPPType &to_type) const
const mf::MultiFunction * get_conversion_multi_function(mf::DataType from, mf::DataType to) const
GVArray_For_ConvertedGVArray(GVArray varray, const CPPType &to_type, const DataTypeConversions &conversions)
GVMutableArray_For_ConvertedGVMutableArray(GVMutableArray varray, const CPPType &to_type, const DataTypeConversions &conversions)
static std::shared_ptr< FieldOperation > from(std::shared_ptr< const mf::MultiFunction > function, Vector< GField > inputs={})
const CPPType & cpp_type() const
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
static float4 float_to_float4(const float &a)
static int2 bool_to_int2(const bool &a)
static float3 quaternion_to_float3(const math::Quaternion &a)
static float2 short2_to_float2(const short2 &a)
static float3 color_to_float3(const ColorGeometry4f &a)
static float bool_to_float(const bool &a)
static int2 int_to_int2(const int32_t &a)
static short2 float_to_short2(const float &a)
static short2 bool_to_short2(const bool &a)
static short2 float4_to_short2(const float4 &a)
static ColorGeometry4b float_to_byte_color(const float &a)
static ColorGeometry4f float_to_color(const float &a)
static int short2_to_int(const short2 &a)
static ColorGeometry4f byte_color_to_color(const ColorGeometry4b &a)
static int8_t float_to_int8(const float &a)
static float2 float4_to_float2(const float4 &a)
static float color_to_float(const ColorGeometry4f &a)
static ColorGeometry4b float4_to_byte_color(const float4 &a)
static int2 int8_to_int2(const int8_t &a)
static int float4_to_int(const float4 &a)
static float2 float_to_float2(const float &a)
static float int2_to_float(const int2 &a)
static ColorGeometry4b int_to_byte_color(const int32_t &a)
static int2 float_to_int2(const float &a)
static float2 int2_to_float2(const int2 &a)
static bool float_to_bool(const float &a)
static void add_implicit_conversion(DataTypeConversions &conversions)
static int8_t int2_to_int8(const int2 &a)
static bool int2_to_bool(const int2 &a)
static ColorGeometry4f float4_to_color(const float4 &a)
static float4 float2_to_float4(const float2 &a)
static int8_t float4_to_int8(const float4 &a)
static float4 float3_to_float4(const float3 &a)
static int8_t float2_to_int8(const float2 &a)
static ColorGeometry4b int2_to_byte_color(const int2 &a)
const DataTypeConversions & get_implicit_type_conversions()
static short2 int2_to_short2(const int2 &a)
static float float3_to_float(const float3 &a)
static float3 float2_to_float3(const float2 &a)
static float float2_to_float(const float2 &a)
static float3 float4_to_float3(const float4 &a)
static math::Quaternion float_to_quaternion(const float &a)
static float2 bool_to_float2(const bool &a)
static int8_t bool_to_int8(const bool &a)
static short2 color_to_short2(const ColorGeometry4f &a)
static ColorGeometry4b float3_to_byte_color(const float3 &a)
static float4 color_to_float4(const ColorGeometry4f &a)
static float short2_to_float(const short2 &a)
static float3 int8_to_float3(const int8_t &a)
static ColorGeometry4f short2_to_color(const short2 &a)
static int32_t color_to_int(const ColorGeometry4f &a)
static float3 float_to_float3(const float &a)
static float4 byte_color_to_float4(const ColorGeometry4b &a)
static ColorGeometry4f float3_to_color(const float3 &a)
static int2 byte_color_to_int2(const ColorGeometry4b &a)
static math::Quaternion float4_to_quaternion(const float4 &a)
static int2 float3_to_int2(const float3 &a)
static int float2_to_int(const float2 &a)
static bool byte_color_to_bool(const ColorGeometry4b &a)
static bool float2_to_bool(const float2 &a)
static bool color_to_bool(const ColorGeometry4f &a)
static float3 short2_to_float3(const short2 &a)
static short2 int_to_short2(const int32_t &a)
static ColorGeometry4f float2_to_color(const float2 &a)
static float2 int_to_float2(const int32_t &a)
static float int8_to_float(const int8_t &a)
static int2 color_to_int2(const ColorGeometry4f &a)
static bool short2_to_bool(const short2 &a)
static short2 int8_to_short2(const int8_t &a)
static float4 bool_to_float4(const bool &a)
static DataTypeConversions create_implicit_conversions()
static bool float3_to_bool(const float3 &a)
static ColorGeometry4b short2_to_byte_color(const short2 &a)
static float4 int8_to_float4(const int8_t &a)
static float4 int_to_float4(const int32_t &a)
static float2 int8_to_float2(const int8_t &a)
static bool int8_to_bool(const int8_t &a)
static float4x4 quaternion_to_float4x4(const math::Quaternion &a)
static int int2_to_int(const int2 &a)
static float3 int_to_float3(const int32_t &a)
static float float4_to_float(const float4 &a)
static float4 short2_to_float4(const short2 &a)
static float byte_color_to_float(const ColorGeometry4b &a)
static float3 int2_to_float3(const int2 &a)
static ColorGeometry4b float2_to_byte_color(const float2 &a)
static int32_t byte_color_to_int(const ColorGeometry4b &a)
static int32_t bool_to_int(const bool &a)
static int float3_to_int(const float3 &a)
static int2 short2_to_int2(const short2 &a)
static float int_to_float(const int32_t &a)
static short2 float3_to_short2(const float3 &a)
static math::Quaternion float3_to_quaternion(const float3 &a)
static ColorGeometry4f int_to_color(const int32_t &a)
static ColorGeometry4b bool_to_byte_color(const bool &a)
static ColorGeometry4f int2_to_color(const int2 &a)
static int32_t float_to_int(const float &a)
static bool int_to_bool(const int32_t &a)
static math::Quaternion float4x4_to_quaternion(const float4x4 &a)
static short2 byte_color_to_short2(const ColorGeometry4b &a)
static ColorGeometry4f int8_to_color(const int8_t &a)
static int8_t byte_color_to_int8(const ColorGeometry4b &a)
static bool float4_to_bool(const float4 &a)
static float2 float3_to_float2(const float3 &a)
static int2 float4_to_int2(const float4 &a)
static short2 float2_to_short2(const float2 &a)
static int8_t int_to_int8(const int32_t &a)
static float2 byte_color_to_float2(const ColorGeometry4b &a)
static int2 float2_to_int2(const float2 &a)
static int8_t float3_to_int8(const float3 &a)
static ColorGeometry4b int8_to_byte_color(const int8_t &a)
static ColorGeometry4b color_to_byte_color(const ColorGeometry4f &a)
static float2 color_to_float2(const ColorGeometry4f &a)
static float4 quaternion_to_float4(const math::Quaternion &a)
static int int8_to_int(const int8_t &a)
static int8_t color_to_int8(const ColorGeometry4f &a)
static void call_convert_to_uninitialized_fn(const GVArray &from, const mf::MultiFunction &fn, const IndexMask &mask, GMutableSpan to)
static ColorGeometry4f bool_to_color(const bool &a)
static int8_t short2_to_int8(const short2 &a)
static float3 byte_color_to_float3(const ColorGeometry4b &a)
static float4 int2_to_float4(const int2 &a)
static float3 bool_to_float3(const bool &a)
BLI_INLINE ColorSceneLinear4f< Alpha > decode(const ColorSceneLinearByteEncoded4b< Alpha > &color)
BLI_INLINE ColorSceneLinearByteEncoded4b< Alpha > encode(const ColorSceneLinear4f< Alpha > &color)
QuaternionBase< float > Quaternion
QuaternionBase< T > to_quaternion(const AxisAngleBase< T, AngleT > &axis_angle)
EulerXYZBase< float > EulerXYZ
T midpoint(const T &a, const T &b)
QuaternionBase< T > normalized_to_quaternion_safe(const MatBase< T, 3, 3 > &mat)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
MatT from_rotation(const RotationT &rotation)
Euler3Base< T > to_euler(const AxisAngleBase< T, AngleT > &axis_angle, EulerOrder order)
MatBase< float, 4, 4 > float4x4
VecBase< float, 4 > float4
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
MatBase< float, 3, 3 > float3x3
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
VecBase< float, 3 > float3
blender::VecBase< int16_t, 2 > short2
ColorSceneLinearByteEncoded4b< eAlpha::Premultiplied > ColorGeometry4b
VecBase< T, 2 > xy() const
VecBase< T, 3 > xyz() const
void(* convert_single_to_uninitialized)(const void *src, void *dst)
void(* convert_single_to_initialized)(const void *src, void *dst)