2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * Contributor(s): Blender Foundation (2008).
20 * ***** END GPL LICENSE BLOCK *****
23 /** \file blender/makesrna/intern/rna_color.c
31 #include "RNA_define.h"
32 #include "rna_internal.h"
34 #include "DNA_color_types.h"
35 #include "DNA_texture_types.h"
42 #include "RNA_access.h"
44 #include "DNA_image_types.h"
45 #include "DNA_material_types.h"
46 #include "DNA_movieclip_types.h"
47 #include "DNA_node_types.h"
49 #include "MEM_guardedalloc.h"
51 #include "BKE_colortools.h"
52 #include "BKE_depsgraph.h"
53 #include "BKE_image.h"
54 #include "BKE_movieclip.h"
56 #include "BKE_texture.h"
60 #include "IMB_colormanagement.h"
62 static int rna_CurveMapping_curves_length(PointerRNA *ptr)
64 CurveMapping *cumap = (CurveMapping *)ptr->data;
67 for (len = 0; len < CM_TOT; len++)
68 if (!cumap->cm[len].curve)
74 static void rna_CurveMapping_curves_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
76 CurveMapping *cumap = (CurveMapping *)ptr->data;
78 rna_iterator_array_begin(iter, cumap->cm, sizeof(CurveMap), rna_CurveMapping_curves_length(ptr), 0, NULL);
81 static void rna_CurveMapping_clip_set(PointerRNA *ptr, int value)
83 CurveMapping *cumap = (CurveMapping *)ptr->data;
85 if (value) cumap->flag |= CUMA_DO_CLIP;
86 else cumap->flag &= ~CUMA_DO_CLIP;
88 curvemapping_changed(cumap, FALSE);
91 static void rna_CurveMapping_black_level_set(PointerRNA *ptr, const float *values)
93 CurveMapping *cumap = (CurveMapping *)ptr->data;
94 cumap->black[0] = values[0];
95 cumap->black[1] = values[1];
96 cumap->black[2] = values[2];
97 curvemapping_set_black_white(cumap, NULL, NULL);
100 static void rna_CurveMapping_white_level_set(PointerRNA *ptr, const float *values)
102 CurveMapping *cumap = (CurveMapping *)ptr->data;
103 cumap->white[0] = values[0];
104 cumap->white[1] = values[1];
105 cumap->white[2] = values[2];
106 curvemapping_set_black_white(cumap, NULL, NULL);
109 static void rna_CurveMapping_clipminx_range(PointerRNA *ptr, float *min, float *max, float *softmin, float *softmax)
111 CurveMapping *cumap = (CurveMapping *)ptr->data;
114 *max = cumap->clipr.xmax;
117 static void rna_CurveMapping_clipminy_range(PointerRNA *ptr, float *min, float *max, float *softmin, float *softmax)
119 CurveMapping *cumap = (CurveMapping *)ptr->data;
122 *max = cumap->clipr.ymax;
125 static void rna_CurveMapping_clipmaxx_range(PointerRNA *ptr, float *min, float *max, float *softmin, float *softmax)
127 CurveMapping *cumap = (CurveMapping *)ptr->data;
129 *min = cumap->clipr.xmin;
133 static void rna_CurveMapping_clipmaxy_range(PointerRNA *ptr, float *min, float *max, float *softmin, float *softmax)
135 CurveMapping *cumap = (CurveMapping *)ptr->data;
137 *min = cumap->clipr.ymin;
142 static char *rna_ColorRamp_path(PointerRNA *ptr)
146 /* handle the cases where a single datablock may have 2 ramp types */
148 ID *id = ptr->id.data;
150 switch (GS(id->name)) {
151 case ID_MA: /* material has 2 cases - diffuse and specular */
153 Material *ma = (Material *)id;
155 if (ptr->data == ma->ramp_col)
156 path = BLI_strdup("diffuse_ramp");
157 else if (ptr->data == ma->ramp_spec)
158 path = BLI_strdup("specular_ramp");
164 bNodeTree *ntree = (bNodeTree *)id;
169 for (node = ntree->nodes.first; node; node = node->next) {
170 if (ELEM3(node->type, SH_NODE_VALTORGB, CMP_NODE_VALTORGB, TEX_NODE_VALTORGB)) {
171 if (node->storage == ptr->data) {
172 /* all node color ramp properties called 'color_ramp'
173 * prepend path from ID to the node
175 RNA_pointer_create(id, &RNA_Node, node, &node_ptr);
176 node_path = RNA_path_from_ID_to_struct(&node_ptr);
177 path = BLI_sprintfN("%s.color_ramp", node_path);
178 MEM_freeN(node_path);
186 /* everything else just uses 'color_ramp' */
187 path = BLI_strdup("color_ramp");
192 /* everything else just uses 'color_ramp' */
193 path = BLI_strdup("color_ramp");
199 static char *rna_ColorRampElement_path(PointerRNA *ptr)
206 /* helper macro for use here to try and get the path
207 * - this calls the standard code for getting a path to a texture...
210 #define COLRAMP_GETPATH \
212 prop = RNA_struct_find_property(&ramp_ptr, "elements"); \
214 index = RNA_property_collection_lookup_index(&ramp_ptr, prop, ptr); \
216 char *texture_path = rna_ColorRamp_path(&ramp_ptr); \
217 path = BLI_sprintfN("%s.elements[%d]", texture_path, index); \
218 MEM_freeN(texture_path); \
223 /* determine the path from the ID-block to the ramp */
224 /* FIXME: this is a very slow way to do it, but it will have to suffice... */
226 ID *id = ptr->id.data;
228 switch (GS(id->name)) {
229 case ID_MA: /* 2 cases for material - diffuse and spec */
231 Material *ma = (Material *)id;
233 /* try diffuse first */
235 RNA_pointer_create(id, &RNA_ColorRamp, ma->ramp_col, &ramp_ptr);
238 /* try specular if not diffuse */
239 if (!path && ma->ramp_spec) {
240 RNA_pointer_create(id, &RNA_ColorRamp, ma->ramp_spec, &ramp_ptr);
248 bNodeTree *ntree = (bNodeTree *)id;
251 for (node = ntree->nodes.first; node; node = node->next) {
252 if (ELEM3(node->type, SH_NODE_VALTORGB, CMP_NODE_VALTORGB, TEX_NODE_VALTORGB)) {
253 RNA_pointer_create(id, &RNA_ColorRamp, node->storage, &ramp_ptr);
260 default: /* everything else should have a "color_ramp" property */
262 /* create pointer to the ID block, and try to resolve "color_ramp" pointer */
263 RNA_id_pointer_create(id, &ramp_ptr);
264 if (RNA_path_resolve(&ramp_ptr, "color_ramp", &ramp_ptr, &prop)) {
271 /* cleanup the macro we defined */
272 #undef COLRAMP_GETPATH
277 static void rna_ColorRamp_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
280 ID *id = ptr->id.data;
282 switch (GS(id->name)) {
285 Material *ma = ptr->id.data;
287 DAG_id_tag_update(&ma->id, 0);
288 WM_main_add_notifier(NC_MATERIAL | ND_SHADING_DRAW, ma);
293 bNodeTree *ntree = (bNodeTree *)id;
296 for (node = ntree->nodes.first; node; node = node->next) {
297 if (ELEM3(node->type, SH_NODE_VALTORGB, CMP_NODE_VALTORGB, TEX_NODE_VALTORGB)) {
298 ED_node_generic_update(bmain, ntree, node);
305 Tex *tex = ptr->id.data;
307 DAG_id_tag_update(&tex->id, 0);
308 WM_main_add_notifier(NC_TEXTURE, tex);
317 static void rna_ColorRamp_eval(struct ColorBand *coba, float position, float color[4])
319 do_colorband(coba, position, color);
322 static CBData *rna_ColorRampElement_new(struct ColorBand *coba, ReportList *reports, float position)
324 CBData *element = colorband_element_add(coba, position);
327 BKE_reportf(reports, RPT_ERROR, "Unable to add element to colorband (limit %d)", MAXCOLORBAND);
332 static void rna_ColorRampElement_remove(struct ColorBand *coba, ReportList *reports, PointerRNA *element_ptr)
334 CBData *element = element_ptr->data;
335 int index = (int)(element - coba->data);
336 if (colorband_element_remove(coba, index) == FALSE) {
337 BKE_report(reports, RPT_ERROR, "Element not found in element collection or last element");
341 RNA_POINTER_INVALIDATE(element_ptr);
344 void rna_CurveMap_remove_point(CurveMap *cuma, ReportList *reports, PointerRNA *point_ptr)
346 CurveMapPoint *point = point_ptr->data;
347 if (curvemap_remove_point(cuma, point) == FALSE) {
348 BKE_report(reports, RPT_ERROR, "Unable to remove curve point");
352 RNA_POINTER_INVALIDATE(point_ptr);
355 static void rna_Scopes_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
357 Scopes *s = (Scopes *)ptr->data;
361 static int rna_ColorManagedDisplaySettings_display_device_get(struct PointerRNA *ptr)
363 ColorManagedDisplaySettings *display = (ColorManagedDisplaySettings *) ptr->data;
365 return IMB_colormanagement_display_get_named_index(display->display_device);
368 static void rna_ColorManagedDisplaySettings_display_device_set(struct PointerRNA *ptr, int value)
370 ColorManagedDisplaySettings *display = (ColorManagedDisplaySettings *) ptr->data;
371 const char *name = IMB_colormanagement_display_get_indexed_name(value);
374 BLI_strncpy(display->display_device, name, sizeof(display->display_device));
378 static EnumPropertyItem *rna_ColorManagedDisplaySettings_display_device_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *UNUSED(prop), int *free)
380 EnumPropertyItem *items = NULL;
383 IMB_colormanagement_display_items_add(&items, &totitem);
384 RNA_enum_item_end(&items, &totitem);
391 static void rna_ColorManagedDisplaySettings_display_device_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
393 ID *id = ptr->id.data;
398 if (GS(id->name) == ID_SCE) {
399 Scene *scene = (Scene *) id;
401 IMB_colormanagement_validate_settings(&scene->display_settings, &scene->view_settings);
403 WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, NULL);
407 static int rna_ColorManagedViewSettings_view_transform_get(PointerRNA *ptr)
409 ColorManagedViewSettings *view = (ColorManagedViewSettings *) ptr->data;
411 return IMB_colormanagement_view_get_named_index(view->view_transform);
414 static void rna_ColorManagedViewSettings_view_transform_set(PointerRNA *ptr, int value)
416 ColorManagedViewSettings *view = (ColorManagedViewSettings *) ptr->data;
418 const char *name = IMB_colormanagement_view_get_indexed_name(value);
421 BLI_strncpy(view->view_transform, name, sizeof(view->view_transform));
425 static EnumPropertyItem* rna_ColorManagedViewSettings_view_transform_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *UNUSED(prop), int *free)
427 Scene *scene = CTX_data_scene(C);
428 EnumPropertyItem *items = NULL;
429 ColorManagedDisplaySettings *display_settings = &scene->display_settings;
432 IMB_colormanagement_view_items_add(&items, &totitem, display_settings->display_device);
433 RNA_enum_item_end(&items, &totitem);
439 static void rna_ColorManagedViewSettings_use_curves_set(PointerRNA *ptr, int value)
441 ColorManagedViewSettings *view_settings = (ColorManagedViewSettings *) ptr->data;
444 view_settings->flag |= COLORMANAGE_VIEW_USE_CURVES;
446 if (view_settings->curve_mapping == NULL) {
447 view_settings->curve_mapping = curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f);
451 view_settings->flag &= ~COLORMANAGE_VIEW_USE_CURVES;
455 static int rna_ColorManagedColorspaceSettings_colorspace_get(struct PointerRNA *ptr)
457 ColorManagedColorspaceSettings *colorspace = (ColorManagedColorspaceSettings *) ptr->data;
459 return IMB_colormanagement_colorspace_get_named_index(colorspace->name);
462 static void rna_ColorManagedColorspaceSettings_colorspace_set(struct PointerRNA *ptr, int value)
464 ColorManagedColorspaceSettings *colorspace = (ColorManagedColorspaceSettings *) ptr->data;
465 const char *name = IMB_colormanagement_colorspace_get_indexed_name(value);
468 BLI_strncpy(colorspace->name, name, sizeof(colorspace->name));
472 static EnumPropertyItem *rna_ColorManagedColorspaceSettings_colorspace_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *UNUSED(prop), int *free)
474 EnumPropertyItem *items = NULL;
477 IMB_colormanagement_colorspace_items_add(&items, &totitem);
478 RNA_enum_item_end(&items, &totitem);
485 static void rna_ColorManagedColorspaceSettings_reload_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
487 ID *id = ptr->id.data;
489 if (GS(id->name) == ID_IM) {
490 Image *ima = (Image *) id;
492 DAG_id_tag_update(&ima->id, 0);
494 BKE_image_signal(ima, NULL, IMA_SIGNAL_COLORMANAGE);
496 WM_main_add_notifier(NC_IMAGE | ND_DISPLAY, &ima->id);
497 WM_main_add_notifier(NC_IMAGE | NA_EDITED, &ima->id);
499 else if (GS(id->name) == ID_MC) {
500 MovieClip *clip = (MovieClip *) id;
502 BKE_movieclip_reload(clip);
504 WM_main_add_notifier(NC_MOVIECLIP | ND_DISPLAY, &clip->id);
505 WM_main_add_notifier(NC_MOVIECLIP | NA_EDITED, &clip->id);
509 static void rna_ColorManagement_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
511 ID *id = ptr->id.data;
516 if (GS(id->name) == ID_SCE) {
517 WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, NULL);
521 /* this function only exists because #curvemap_evaluateF uses a 'const' qualifier */
522 static float rna_CurveMap_evaluateF(struct CurveMap *cuma, float value)
524 return curvemap_evaluateF(cuma, value);
529 static void rna_def_curvemappoint(BlenderRNA *brna)
533 static EnumPropertyItem prop_handle_type_items[] = {
534 {0, "AUTO", 0, "Auto Handle", ""},
535 {CUMA_VECTOR, "VECTOR", 0, "Vector Handle", ""},
536 {0, NULL, 0, NULL, NULL}
539 srna = RNA_def_struct(brna, "CurveMapPoint", NULL);
540 RNA_def_struct_ui_text(srna, "CurveMapPoint", "Point of a curve used for a curve mapping");
542 prop = RNA_def_property(srna, "location", PROP_FLOAT, PROP_XYZ);
543 RNA_def_property_float_sdna(prop, NULL, "x");
544 RNA_def_property_array(prop, 2);
545 RNA_def_property_ui_text(prop, "Location", "X/Y coordinates of the curve point");
547 prop = RNA_def_property(srna, "handle_type", PROP_ENUM, PROP_NONE);
548 RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
549 RNA_def_property_enum_items(prop, prop_handle_type_items);
550 RNA_def_property_ui_text(prop, "Handle Type", "Curve interpolation at this point: Bezier or vector");
552 prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
553 RNA_def_property_boolean_sdna(prop, NULL, "flag", CUMA_SELECT);
554 RNA_def_property_ui_text(prop, "Select", "Selection state of the curve point");
557 static void rna_def_curvemap_points_api(BlenderRNA *brna, PropertyRNA *cprop)
563 RNA_def_property_srna(cprop, "CurveMapPoints");
564 srna = RNA_def_struct(brna, "CurveMapPoints", NULL);
565 RNA_def_struct_sdna(srna, "CurveMap");
566 RNA_def_struct_ui_text(srna, "Curve Map Point", "Collection of Curve Map Points");
568 func = RNA_def_function(srna, "new", "curvemap_insert");
569 RNA_def_function_ui_description(func, "Add point to CurveMap");
570 parm = RNA_def_float(func, "position", 0.0f, -FLT_MAX, FLT_MAX, "Position", "Position to add point", -FLT_MAX, FLT_MAX);
571 RNA_def_property_flag(parm, PROP_REQUIRED);
572 parm = RNA_def_float(func, "value", 0.0f, -FLT_MAX, FLT_MAX, "Value", "Value of point", -FLT_MAX, FLT_MAX);
573 RNA_def_property_flag(parm, PROP_REQUIRED);
574 parm = RNA_def_pointer(func, "point", "CurveMapPoint", "", "New point");
575 RNA_def_function_return(func, parm);
577 func = RNA_def_function(srna, "remove", "rna_CurveMap_remove_point");
578 RNA_def_function_flag(func, FUNC_USE_REPORTS);
579 RNA_def_function_ui_description(func, "Delete point from CurveMap");
580 parm = RNA_def_pointer(func, "point", "CurveMapPoint", "", "PointElement to remove");
581 RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR);
582 RNA_def_property_clear_flag(parm, PROP_THICK_WRAP);
585 static void rna_def_curvemap(BlenderRNA *brna)
588 PropertyRNA *prop, *parm;
591 static EnumPropertyItem prop_extend_items[] = {
592 {0, "HORIZONTAL", 0, "Horizontal", ""},
593 {CUMA_EXTEND_EXTRAPOLATE, "EXTRAPOLATED", 0, "Extrapolated", ""},
594 {0, NULL, 0, NULL, NULL}
597 srna = RNA_def_struct(brna, "CurveMap", NULL);
598 RNA_def_struct_ui_text(srna, "CurveMap", "Curve in a curve mapping");
600 prop = RNA_def_property(srna, "extend", PROP_ENUM, PROP_NONE);
601 RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
602 RNA_def_property_enum_items(prop, prop_extend_items);
603 RNA_def_property_ui_text(prop, "Extend", "Extrapolate the curve or extend it horizontally");
605 prop = RNA_def_property(srna, "points", PROP_COLLECTION, PROP_NONE);
606 RNA_def_property_collection_sdna(prop, NULL, "curve", "totpoint");
607 RNA_def_property_struct_type(prop, "CurveMapPoint");
608 RNA_def_property_ui_text(prop, "Points", "");
609 rna_def_curvemap_points_api(brna, prop);
611 func = RNA_def_function(srna, "evaluate", "rna_CurveMap_evaluateF");
612 RNA_def_function_ui_description(func, "Evaluate curve at given location");
613 parm = RNA_def_float(func, "position", 0.0f, -FLT_MAX, FLT_MAX, "Position", "Position to evaluate curve at", -FLT_MAX, FLT_MAX);
614 RNA_def_property_flag(parm, PROP_REQUIRED);
615 parm = RNA_def_float(func, "value", 0.0f, -FLT_MAX, FLT_MAX, "Value", "Value of curve at given location", -FLT_MAX, FLT_MAX);
616 RNA_def_function_return(func, parm);
619 static void rna_def_curvemapping(BlenderRNA *brna)
625 srna = RNA_def_struct(brna, "CurveMapping", NULL);
626 RNA_def_struct_ui_text(srna, "CurveMapping",
627 "Curve mapping to map color, vector and scalar values to other values using "
628 "a user defined curve");
630 prop = RNA_def_property(srna, "use_clip", PROP_BOOLEAN, PROP_NONE);
631 RNA_def_property_boolean_sdna(prop, NULL, "flag", CUMA_DO_CLIP);
632 RNA_def_property_ui_text(prop, "Clip", "Force the curve view to fit a defined boundary");
633 RNA_def_property_boolean_funcs(prop, NULL, "rna_CurveMapping_clip_set");
635 prop = RNA_def_property(srna, "clip_min_x", PROP_FLOAT, PROP_NONE);
636 RNA_def_property_float_sdna(prop, NULL, "clipr.xmin");
637 RNA_def_property_range(prop, -100.0f, 100.0f);
638 RNA_def_property_ui_text(prop, "Clip Min X", "");
639 RNA_def_property_float_funcs(prop, NULL, NULL, "rna_CurveMapping_clipminx_range");
641 prop = RNA_def_property(srna, "clip_min_y", PROP_FLOAT, PROP_NONE);
642 RNA_def_property_float_sdna(prop, NULL, "clipr.ymin");
643 RNA_def_property_range(prop, -100.0f, 100.0f);
644 RNA_def_property_ui_text(prop, "Clip Min Y", "");
645 RNA_def_property_float_funcs(prop, NULL, NULL, "rna_CurveMapping_clipminy_range");
647 prop = RNA_def_property(srna, "clip_max_x", PROP_FLOAT, PROP_NONE);
648 RNA_def_property_float_sdna(prop, NULL, "clipr.xmax");
649 RNA_def_property_range(prop, -100.0f, 100.0f);
650 RNA_def_property_ui_text(prop, "Clip Max X", "");
651 RNA_def_property_float_funcs(prop, NULL, NULL, "rna_CurveMapping_clipmaxx_range");
653 prop = RNA_def_property(srna, "clip_max_y", PROP_FLOAT, PROP_NONE);
654 RNA_def_property_float_sdna(prop, NULL, "clipr.ymax");
655 RNA_def_property_range(prop, -100.0f, 100.0f);
656 RNA_def_property_ui_text(prop, "Clip Max Y", "");
657 RNA_def_property_float_funcs(prop, NULL, NULL, "rna_CurveMapping_clipmaxy_range");
659 prop = RNA_def_property(srna, "curves", PROP_COLLECTION, PROP_NONE);
660 RNA_def_property_collection_funcs(prop, "rna_CurveMapping_curves_begin", "rna_iterator_array_next",
661 "rna_iterator_array_end", "rna_iterator_array_get",
662 "rna_CurveMapping_curves_length", NULL, NULL, NULL);
663 RNA_def_property_struct_type(prop, "CurveMap");
664 RNA_def_property_ui_text(prop, "Curves", "");
666 prop = RNA_def_property(srna, "black_level", PROP_FLOAT, PROP_COLOR);
667 RNA_def_property_float_sdna(prop, NULL, "black");
668 RNA_def_property_range(prop, -1000.0f, 1000.0f);
669 RNA_def_property_ui_text(prop, "Black Level", "For RGB curves, the color that black is mapped to");
670 RNA_def_property_float_funcs(prop, NULL, "rna_CurveMapping_black_level_set", NULL);
672 prop = RNA_def_property(srna, "white_level", PROP_FLOAT, PROP_COLOR);
673 RNA_def_property_float_sdna(prop, NULL, "white");
674 RNA_def_property_range(prop, -1000.0f, 1000.0f);
675 RNA_def_property_ui_text(prop, "White Level", "For RGB curves, the color that white is mapped to");
676 RNA_def_property_float_funcs(prop, NULL, "rna_CurveMapping_white_level_set", NULL);
678 func = RNA_def_function(srna, "update", "curvemapping_changed_all");
679 RNA_def_function_ui_description(func, "Update curve mapping after making changes");
682 static void rna_def_color_ramp_element(BlenderRNA *brna)
687 srna = RNA_def_struct(brna, "ColorRampElement", NULL);
688 RNA_def_struct_sdna(srna, "CBData");
689 RNA_def_struct_path_func(srna, "rna_ColorRampElement_path");
690 RNA_def_struct_ui_text(srna, "Color Ramp Element", "Element defining a color at a position in the color ramp");
692 prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR);
693 RNA_def_property_float_sdna(prop, NULL, "r");
694 RNA_def_property_array(prop, 4);
695 RNA_def_property_ui_text(prop, "Color", "Set color of selected color stop");
696 RNA_def_property_update(prop, 0, "rna_ColorRamp_update");
698 prop = RNA_def_property(srna, "position", PROP_FLOAT, PROP_NONE);
699 RNA_def_property_float_sdna(prop, NULL, "pos");
700 RNA_def_property_range(prop, 0, 1);
701 RNA_def_property_ui_text(prop, "Position", "Set position of selected color stop");
702 RNA_def_property_update(prop, 0, "rna_ColorRamp_update");
705 static void rna_def_color_ramp_element_api(BlenderRNA *brna, PropertyRNA *cprop)
711 RNA_def_property_srna(cprop, "ColorRampElements");
712 srna = RNA_def_struct(brna, "ColorRampElements", NULL);
713 RNA_def_struct_sdna(srna, "ColorBand");
714 RNA_def_struct_path_func(srna, "rna_ColorRampElement_path");
715 RNA_def_struct_ui_text(srna, "Color Ramp Elements", "Collection of Color Ramp Elements");
717 /* TODO, make these functions generic in texture.c */
718 func = RNA_def_function(srna, "new", "rna_ColorRampElement_new");
719 RNA_def_function_ui_description(func, "Add element to ColorRamp");
720 RNA_def_function_flag(func, FUNC_USE_REPORTS);
721 parm = RNA_def_float(func, "position", 0.0f, 0.0f, 1.0f, "Position", "Position to add element", 0.0f, 1.0f);
722 RNA_def_property_flag(parm, PROP_REQUIRED);
724 parm = RNA_def_pointer(func, "element", "ColorRampElement", "", "New element");
725 RNA_def_function_return(func, parm);
727 func = RNA_def_function(srna, "remove", "rna_ColorRampElement_remove");
728 RNA_def_function_ui_description(func, "Delete element from ColorRamp");
729 RNA_def_function_flag(func, FUNC_USE_REPORTS);
730 parm = RNA_def_pointer(func, "element", "ColorRampElement", "", "Element to remove");
731 RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR);
732 RNA_def_property_clear_flag(parm, PROP_THICK_WRAP);
735 static void rna_def_color_ramp(BlenderRNA *brna)
741 static EnumPropertyItem prop_interpolation_items[] = {
742 {1, "EASE", 0, "Ease", ""},
743 {3, "CARDINAL", 0, "Cardinal", ""},
744 {0, "LINEAR", 0, "Linear", ""},
745 {2, "B_SPLINE", 0, "B-Spline", ""},
746 {4, "CONSTANT", 0, "Constant", ""},
747 {0, NULL, 0, NULL, NULL}
750 srna = RNA_def_struct(brna, "ColorRamp", NULL);
751 RNA_def_struct_sdna(srna, "ColorBand");
752 RNA_def_struct_path_func(srna, "rna_ColorRamp_path");
753 RNA_def_struct_ui_text(srna, "Color Ramp", "Color ramp mapping a scalar value to a color");
755 prop = RNA_def_property(srna, "elements", PROP_COLLECTION, PROP_COLOR);
756 RNA_def_property_collection_sdna(prop, NULL, "data", "tot");
757 RNA_def_property_struct_type(prop, "ColorRampElement");
758 RNA_def_property_ui_text(prop, "Elements", "");
759 RNA_def_property_update(prop, 0, "rna_ColorRamp_update");
760 rna_def_color_ramp_element_api(brna, prop);
762 prop = RNA_def_property(srna, "interpolation", PROP_ENUM, PROP_NONE);
763 RNA_def_property_enum_sdna(prop, NULL, "ipotype");
764 RNA_def_property_enum_items(prop, prop_interpolation_items);
765 RNA_def_property_ui_text(prop, "Interpolation", "");
766 RNA_def_property_update(prop, 0, "rna_ColorRamp_update");
768 #if 0 /* use len(elements) */
769 prop = RNA_def_property(srna, "total", PROP_INT, PROP_NONE);
770 RNA_def_property_int_sdna(prop, NULL, "tot");
771 /* needs a function to do the right thing when adding elements like colorband_add_cb() */
772 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
773 RNA_def_property_range(prop, 0, 31); /* MAXCOLORBAND = 32 */
774 RNA_def_property_ui_text(prop, "Total", "Total number of elements");
775 RNA_def_property_update(prop, 0, "rna_ColorRamp_update");
778 func = RNA_def_function(srna, "evaluate", "rna_ColorRamp_eval");
779 RNA_def_function_ui_description(func, "Evaluate ColorRamp");
780 prop = RNA_def_float(func, "position", 1.0f, 0.0f, 1.0f, "Position", "Evaluate ColorRamp at position", 0.0f, 1.0f);
781 RNA_def_property_flag(prop, PROP_REQUIRED);
783 prop = RNA_def_float_color(func, "color", 4, NULL, -FLT_MAX, FLT_MAX, "Color", "Color at given position",
785 RNA_def_property_flag(prop, PROP_THICK_WRAP);
786 RNA_def_function_output(func, prop);
789 static void rna_def_histogram(BlenderRNA *brna)
794 static EnumPropertyItem prop_mode_items[] = {
795 {HISTO_MODE_LUMA, "LUMA", 0, "Luma", "Luma"},
796 {HISTO_MODE_RGB, "RGB", 0, "RGB", "Red Green Blue"},
797 {HISTO_MODE_R, "R", 0, "R", "Red"},
798 {HISTO_MODE_G, "G", 0, "G", "Green"},
799 {HISTO_MODE_B, "B", 0, "B", "Blue"},
800 {HISTO_MODE_ALPHA, "A", 0, "A", "Alpha"},
801 {0, NULL, 0, NULL, NULL}
804 srna = RNA_def_struct(brna, "Histogram", NULL);
805 RNA_def_struct_ui_text(srna, "Histogram", "Statistical view of the levels of color in an image");
807 prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
808 RNA_def_property_enum_sdna(prop, NULL, "mode");
809 RNA_def_property_enum_items(prop, prop_mode_items);
810 RNA_def_property_ui_text(prop, "Mode", "Channels to display when drawing the histogram");
812 prop = RNA_def_property(srna, "show_line", PROP_BOOLEAN, PROP_NONE);
813 RNA_def_property_boolean_sdna(prop, NULL, "flag", HISTO_FLAG_LINE);
814 RNA_def_property_ui_text(prop, "Show Line", "Display lines rather then filled shapes");
815 RNA_def_property_ui_icon(prop, ICON_IPO, 0);
818 static void rna_def_scopes(BlenderRNA *brna)
823 static EnumPropertyItem prop_wavefrm_mode_items[] = {
824 {SCOPES_WAVEFRM_LUMA, "LUMA", ICON_COLOR, "Luma", ""},
825 {SCOPES_WAVEFRM_RGB, "RGB", ICON_COLOR, "Red Green Blue", ""},
826 {SCOPES_WAVEFRM_YCC_601, "YCBCR601", ICON_COLOR, "YCbCr (ITU 601)", ""},
827 {SCOPES_WAVEFRM_YCC_709, "YCBCR709", ICON_COLOR, "YCbCr (ITU 709)", ""},
828 {SCOPES_WAVEFRM_YCC_JPEG, "YCBCRJPG", ICON_COLOR, "YCbCr (Jpeg)", ""},
829 {0, NULL, 0, NULL, NULL}
832 srna = RNA_def_struct(brna, "Scopes", NULL);
833 RNA_def_struct_ui_text(srna, "Scopes", "Scopes for statistical view of an image");
835 prop = RNA_def_property(srna, "use_full_resolution", PROP_BOOLEAN, PROP_NONE);
836 RNA_def_property_boolean_sdna(prop, "Scopes", "sample_full", 1);
837 RNA_def_property_ui_text(prop, "Full Sample", "Sample every pixel of the image");
838 RNA_def_property_update(prop, 0, "rna_Scopes_update");
840 prop = RNA_def_property(srna, "accuracy", PROP_FLOAT, PROP_PERCENTAGE);
841 RNA_def_property_float_sdna(prop, "Scopes", "accuracy");
842 RNA_def_property_range(prop, 0.0, 100.0);
843 RNA_def_property_ui_range(prop, 0.0, 100.0, 10, 1);
844 RNA_def_property_ui_text(prop, "Accuracy", "Proportion of original image source pixel lines to sample");
845 RNA_def_property_update(prop, 0, "rna_Scopes_update");
847 prop = RNA_def_property(srna, "histogram", PROP_POINTER, PROP_NONE);
848 RNA_def_property_pointer_sdna(prop, "Scopes", "hist");
849 RNA_def_property_struct_type(prop, "Histogram");
850 RNA_def_property_ui_text(prop, "Histogram", "Histogram for viewing image statistics");
852 prop = RNA_def_property(srna, "waveform_mode", PROP_ENUM, PROP_NONE);
853 RNA_def_property_enum_sdna(prop, "Scopes", "wavefrm_mode");
854 RNA_def_property_enum_items(prop, prop_wavefrm_mode_items);
855 RNA_def_property_ui_text(prop, "Waveform Mode", "");
856 RNA_def_property_update(prop, 0, "rna_Scopes_update");
858 prop = RNA_def_property(srna, "waveform_alpha", PROP_FLOAT, PROP_FACTOR);
859 RNA_def_property_float_sdna(prop, "Scopes", "wavefrm_alpha");
860 RNA_def_property_range(prop, 0, 1);
861 RNA_def_property_ui_text(prop, "Waveform Opacity", "Opacity of the points");
863 prop = RNA_def_property(srna, "vectorscope_alpha", PROP_FLOAT, PROP_FACTOR);
864 RNA_def_property_float_sdna(prop, "Scopes", "vecscope_alpha");
865 RNA_def_property_range(prop, 0, 1);
866 RNA_def_property_ui_text(prop, "Vectorscope Opacity", "Opacity of the points");
869 static void rna_def_colormanage(BlenderRNA *brna)
874 static EnumPropertyItem display_device_items[] = {
875 {0, "DEFAULT", 0, "Default", ""},
876 {0, NULL, 0, NULL, NULL}
879 static EnumPropertyItem view_transform_items[] = {
880 {0, "NONE", 0, "None", "Do not perform any color transform on display, use old non-color managed technique for display"},
881 {0, NULL, 0, NULL, NULL}
884 static EnumPropertyItem color_space_items[] = {
885 {0, "NONE", 0, "None", "Do not perform any color transform on load, treat colors as in scene linear space already"},
886 {0, NULL, 0, NULL, NULL}
889 /* ** Display Settings ** */
890 srna = RNA_def_struct(brna, "ColorManagedDisplaySettings", NULL);
891 RNA_def_struct_ui_text(srna, "ColorManagedDisplaySettings", "Color management specific to display device");
893 prop = RNA_def_property(srna, "display_device", PROP_ENUM, PROP_NONE);
894 RNA_def_property_enum_items(prop, display_device_items);
895 RNA_def_property_enum_funcs(prop, "rna_ColorManagedDisplaySettings_display_device_get",
896 "rna_ColorManagedDisplaySettings_display_device_set",
897 "rna_ColorManagedDisplaySettings_display_device_itemf");
898 RNA_def_property_ui_text(prop, "Display Device", "Display device name");
899 RNA_def_property_update(prop, NC_WINDOW, "rna_ColorManagedDisplaySettings_display_device_update");
901 /* ** View Settings ** */
902 srna = RNA_def_struct(brna, "ColorManagedViewSettings", NULL);
903 RNA_def_struct_ui_text(srna, "ColorManagedViewSettings", "Color management settings used for displaying images on the display");
905 prop = RNA_def_property(srna, "view_transform", PROP_ENUM, PROP_NONE);
906 RNA_def_property_enum_items(prop, view_transform_items);
907 RNA_def_property_enum_funcs(prop, "rna_ColorManagedViewSettings_view_transform_get",
908 "rna_ColorManagedViewSettings_view_transform_set",
909 "rna_ColorManagedViewSettings_view_transform_itemf");
910 RNA_def_property_ui_text(prop, "View Transform", "View used ");
911 RNA_def_property_update(prop, NC_WINDOW, "rna_ColorManagement_update");
913 prop = RNA_def_property(srna, "exposure", PROP_FLOAT, PROP_FACTOR);
914 RNA_def_property_float_sdna(prop, NULL, "exposure");
915 RNA_def_property_range(prop, -10.0f, 10.0f);
916 RNA_def_property_float_default(prop, 0.0f);
917 RNA_def_property_ui_text(prop, "Exposure", "Exposure (stops) applied before display transform");
918 RNA_def_property_update(prop, NC_WINDOW, "rna_ColorManagement_update");
920 prop = RNA_def_property(srna, "gamma", PROP_FLOAT, PROP_FACTOR);
921 RNA_def_property_float_sdna(prop, NULL, "gamma");
922 RNA_def_property_float_default(prop, 1.0f);
923 RNA_def_property_range(prop, 0.0f, 5.0f);
924 RNA_def_property_ui_text(prop, "Gamma", "Amount of gamma modification applied after display transform");
925 RNA_def_property_update(prop, NC_WINDOW, "rna_ColorManagement_update");
927 prop = RNA_def_property(srna, "curve_mapping", PROP_POINTER, PROP_NONE);
928 RNA_def_property_pointer_sdna(prop, NULL, "curve_mapping");
929 RNA_def_property_ui_text(prop, "Curve", "Color curve mapping applied before display transform");
930 RNA_def_property_update(prop, NC_WINDOW, "rna_ColorManagement_update");
932 prop = RNA_def_property(srna, "use_curve_mapping", PROP_BOOLEAN, PROP_NONE);
933 RNA_def_property_boolean_sdna(prop, NULL, "flag", COLORMANAGE_VIEW_USE_CURVES);
934 RNA_def_property_boolean_funcs(prop, NULL, "rna_ColorManagedViewSettings_use_curves_set");
935 RNA_def_property_ui_text(prop, "Use Curves", "Use RGB curved for pre-display transformation");
936 RNA_def_property_update(prop, NC_WINDOW, "rna_ColorManagement_update");
938 /* ** Colorspace ** */
939 srna = RNA_def_struct(brna, "ColorManagedColorspaceSettings", NULL);
940 RNA_def_struct_ui_text(srna, "ColorManagedColorspaceSettings", "Input color space settings");
942 prop = RNA_def_property(srna, "name", PROP_ENUM, PROP_NONE);
943 RNA_def_property_enum_items(prop, color_space_items);
944 RNA_def_property_enum_funcs(prop, "rna_ColorManagedColorspaceSettings_colorspace_get",
945 "rna_ColorManagedColorspaceSettings_colorspace_set",
946 "rna_ColorManagedColorspaceSettings_colorspace_itemf");
947 RNA_def_property_ui_text(prop, "Color Space", "Input color space name");
948 RNA_def_property_update(prop, NC_WINDOW, "rna_ColorManagedColorspaceSettings_reload_update");
951 void RNA_def_color(BlenderRNA *brna)
953 rna_def_curvemappoint(brna);
954 rna_def_curvemap(brna);
955 rna_def_curvemapping(brna);
956 rna_def_color_ramp_element(brna);
957 rna_def_color_ramp(brna);
958 rna_def_histogram(brna);
959 rna_def_scopes(brna);
960 rna_def_colormanage(brna);