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:
authorAras Pranckevicius <aras@nesnausk.org>2022-09-14 22:50:46 +0300
committerAras Pranckevicius <aras@nesnausk.org>2022-09-14 22:51:00 +0300
commit42fe0b6dfcc276f5db1461add1e24aea55ca1131 (patch)
tree1f099df41749b15730a4697ec20f1afe9eb763d0 /source/blender/makesrna/intern/rna_attribute.c
parent6d4d74172bac0a473bf0b389b5e402c51269042c (diff)
Attributes: add color_srgb property to FloatColorAttributeValue and ByteColorAttributeValue
This patch adds color_srgb property to FloatColorAttributeValue and ByteColorAttributeValue, so Python code can do `layer.data.foreach_get("color_srgb", ...)` to fetch the data efficiently, if it needs it in sRGB color space. Reviewed By: Bastien Montagne Differential Revision: https://developer.blender.org/D15966
Diffstat (limited to 'source/blender/makesrna/intern/rna_attribute.c')
-rw-r--r--source/blender/makesrna/intern/rna_attribute.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/source/blender/makesrna/intern/rna_attribute.c b/source/blender/makesrna/intern/rna_attribute.c
index 5e17f22ecf5..4bf55bcc701 100644
--- a/source/blender/makesrna/intern/rna_attribute.c
+++ b/source/blender/makesrna/intern/rna_attribute.c
@@ -321,6 +321,36 @@ static void rna_ByteColorAttributeValue_color_set(PointerRNA *ptr, const float *
linearrgb_to_srgb_uchar4(&mlcol->r, values);
}
+static void rna_ByteColorAttributeValue_color_srgb_get(PointerRNA *ptr, float *values)
+{
+ MLoopCol *col = (MLoopCol *)ptr->data;
+ values[0] = col->r / 255.0f;
+ values[1] = col->g / 255.0f;
+ values[2] = col->b / 255.0f;
+ values[3] = col->a / 255.0f;
+}
+
+static void rna_ByteColorAttributeValue_color_srgb_set(PointerRNA *ptr, const float *values)
+{
+ MLoopCol *col = (MLoopCol *)ptr->data;
+ col->r = round_fl_to_uchar_clamp(values[0] * 255.0f);
+ col->g = round_fl_to_uchar_clamp(values[1] * 255.0f);
+ col->b = round_fl_to_uchar_clamp(values[2] * 255.0f);
+ col->a = round_fl_to_uchar_clamp(values[3] * 255.0f);
+}
+
+static void rna_FloatColorAttributeValue_color_srgb_get(PointerRNA *ptr, float *values)
+{
+ MPropCol *col = (MPropCol *)ptr->data;
+ linearrgb_to_srgb_v4(values, col->color);
+}
+
+static void rna_FloatColorAttributeValue_color_srgb_set(PointerRNA *ptr, const float *values)
+{
+ MPropCol *col = (MPropCol *)ptr->data;
+ srgb_to_linearrgb_v4(col->color, values);
+}
+
/* Int8 Attribute. */
static int rna_ByteIntAttributeValue_get(PointerRNA *ptr)
@@ -715,6 +745,16 @@ static void rna_def_attribute_float_color(BlenderRNA *brna)
RNA_def_property_float_sdna(prop, NULL, "color");
RNA_def_property_array(prop, 4);
RNA_def_property_update(prop, 0, "rna_Attribute_update_data");
+
+ prop = RNA_def_property(srna, "color_srgb", PROP_FLOAT, PROP_COLOR);
+ RNA_def_property_ui_text(prop, "Color", "RGBA color in sRGB color space");
+ RNA_def_property_float_sdna(prop, NULL, "color");
+ RNA_def_property_array(prop, 4);
+ RNA_def_property_float_funcs(prop,
+ "rna_FloatColorAttributeValue_color_srgb_get",
+ "rna_FloatColorAttributeValue_color_srgb_set",
+ NULL);
+ RNA_def_property_update(prop, 0, "rna_Attribute_update_data");
}
static void rna_def_attribute_byte_color(BlenderRNA *brna)
@@ -756,6 +796,16 @@ static void rna_def_attribute_byte_color(BlenderRNA *brna)
NULL);
RNA_def_property_ui_text(prop, "Color", "RGBA color in scene linear color space");
RNA_def_property_update(prop, 0, "rna_Attribute_update_data");
+
+ prop = RNA_def_property(srna, "color_srgb", PROP_FLOAT, PROP_COLOR);
+ RNA_def_property_array(prop, 4);
+ RNA_def_property_range(prop, 0.0f, 1.0f);
+ RNA_def_property_float_funcs(prop,
+ "rna_ByteColorAttributeValue_color_srgb_get",
+ "rna_ByteColorAttributeValue_color_srgb_set",
+ NULL);
+ RNA_def_property_ui_text(prop, "Color", "RGBA color in sRGB color space");
+ RNA_def_property_update(prop, 0, "rna_Attribute_update_data");
}
static void rna_def_attribute_int(BlenderRNA *brna)