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, CBData *element)
334 int index = (int)(element - coba->data);
335 if (colorband_element_remove(coba, index) == 0)
336 BKE_report(reports, RPT_ERROR, "Element not found in element collection or last element");
340 static void rna_Scopes_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
342 Scopes *s = (Scopes *)ptr->data;
346 static int rna_ColorManagedDisplaySettings_display_device_get(struct PointerRNA *ptr)
348 ColorManagedDisplaySettings *display = (ColorManagedDisplaySettings *) ptr->data;
350 return IMB_colormanagement_display_get_named_index(display->display_device);
353 static void rna_ColorManagedDisplaySettings_display_device_set(struct PointerRNA *ptr, int value)
355 ColorManagedDisplaySettings *display = (ColorManagedDisplaySettings *) ptr->data;
356 const char *name = IMB_colormanagement_display_get_indexed_name(value);
359 BLI_strncpy(display->display_device, name, sizeof(display->display_device));
363 static EnumPropertyItem *rna_ColorManagedDisplaySettings_display_device_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *UNUSED(prop), int *free)
365 EnumPropertyItem *items = NULL;
368 IMB_colormanagement_display_items_add(&items, &totitem);
369 RNA_enum_item_end(&items, &totitem);
376 static void rna_ColorManagedDisplaySettings_display_device_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
378 ID *id = ptr->id.data;
383 if (GS(id->name) == ID_SCE) {
384 Scene *scene = (Scene *) id;
386 IMB_colormanagement_validate_settings(&scene->display_settings, &scene->view_settings);
388 WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, NULL);
392 static int rna_ColorManagedViewSettings_view_transform_get(PointerRNA *ptr)
394 ColorManagedViewSettings *view = (ColorManagedViewSettings *) ptr->data;
396 return IMB_colormanagement_view_get_named_index(view->view_transform);
399 static void rna_ColorManagedViewSettings_view_transform_set(PointerRNA *ptr, int value)
401 ColorManagedViewSettings *view = (ColorManagedViewSettings *) ptr->data;
403 const char *name = IMB_colormanagement_view_get_indexed_name(value);
406 BLI_strncpy(view->view_transform, name, sizeof(view->view_transform));
410 static EnumPropertyItem* rna_ColorManagedViewSettings_view_transform_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *UNUSED(prop), int *free)
412 Scene *scene = CTX_data_scene(C);
413 EnumPropertyItem *items = NULL;
414 ColorManagedDisplaySettings *display_settings = &scene->display_settings;
417 IMB_colormanagement_view_items_add(&items, &totitem, display_settings->display_device);
418 RNA_enum_item_end(&items, &totitem);
424 static void rna_ColorManagedViewSettings_use_curves_set(PointerRNA *ptr, int value)
426 ColorManagedViewSettings *view_settings = (ColorManagedViewSettings *) ptr->data;
429 view_settings->flag |= COLORMANAGE_VIEW_USE_CURVES;
431 if (view_settings->curve_mapping == NULL) {
432 view_settings->curve_mapping = curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f);
436 view_settings->flag &= ~COLORMANAGE_VIEW_USE_CURVES;
440 static int rna_ColorManagedColorspaceSettings_colorspace_get(struct PointerRNA *ptr)
442 ColorManagedColorspaceSettings *colorspace = (ColorManagedColorspaceSettings *) ptr->data;
444 return IMB_colormanagement_colorspace_get_named_index(colorspace->name);
447 static void rna_ColorManagedColorspaceSettings_colorspace_set(struct PointerRNA *ptr, int value)
449 ColorManagedColorspaceSettings *colorspace = (ColorManagedColorspaceSettings *) ptr->data;
450 const char *name = IMB_colormanagement_colorspace_get_indexed_name(value);
453 BLI_strncpy(colorspace->name, name, sizeof(colorspace->name));
457 static EnumPropertyItem *rna_ColorManagedColorspaceSettings_colorspace_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *UNUSED(prop), int *free)
459 EnumPropertyItem *items = NULL;
462 IMB_colormanagement_colorspace_items_add(&items, &totitem);
463 RNA_enum_item_end(&items, &totitem);
470 static void rna_ColorManagedColorspaceSettings_reload_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
472 ID *id = ptr->id.data;
474 if (GS(id->name) == ID_IM) {
475 Image *ima = (Image *) id;
477 BKE_image_signal(ima, NULL, IMA_SIGNAL_RELOAD);
478 WM_main_add_notifier(NC_IMAGE | ND_DISPLAY, &ima->id);
480 else if (GS(id->name) == ID_MC) {
481 MovieClip *clip = (MovieClip *) id;
483 BKE_movieclip_reload(clip);
484 WM_main_add_notifier(NC_MOVIECLIP | ND_DISPLAY, &clip->id);
488 static void rna_ColorManagement_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
490 ID *id = ptr->id.data;
495 if (GS(id->name) == ID_SCE) {
496 WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, NULL);
500 /* this function only exists because #curvemap_evaluateF uses a 'const' qualifier */
501 static float rna_CurveMap_evaluateF(struct CurveMap *cuma, float value)
503 return curvemap_evaluateF(cuma, value);
508 static void rna_def_curvemappoint(BlenderRNA *brna)
512 static EnumPropertyItem prop_handle_type_items[] = {
513 {0, "AUTO", 0, "Auto Handle", ""},
514 {CUMA_VECTOR, "VECTOR", 0, "Vector Handle", ""},
515 {0, NULL, 0, NULL, NULL}
518 srna = RNA_def_struct(brna, "CurveMapPoint", NULL);
519 RNA_def_struct_ui_text(srna, "CurveMapPoint", "Point of a curve used for a curve mapping");
521 prop = RNA_def_property(srna, "location", PROP_FLOAT, PROP_XYZ);
522 RNA_def_property_float_sdna(prop, NULL, "x");
523 RNA_def_property_array(prop, 2);
524 RNA_def_property_ui_text(prop, "Location", "X/Y coordinates of the curve point");
526 prop = RNA_def_property(srna, "handle_type", PROP_ENUM, PROP_NONE);
527 RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
528 RNA_def_property_enum_items(prop, prop_handle_type_items);
529 RNA_def_property_ui_text(prop, "Handle Type", "Curve interpolation at this point: Bezier or vector");
531 prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
532 RNA_def_property_boolean_sdna(prop, NULL, "flag", CUMA_SELECT);
533 RNA_def_property_ui_text(prop, "Select", "Selection state of the curve point");
536 static void rna_def_curvemap_points_api(BlenderRNA *brna, PropertyRNA *cprop)
542 RNA_def_property_srna(cprop, "CurveMapPoints");
543 srna = RNA_def_struct(brna, "CurveMapPoints", NULL);
544 RNA_def_struct_sdna(srna, "CurveMap");
545 RNA_def_struct_ui_text(srna, "Curve Map Point", "Collection of Curve Map Points");
547 func = RNA_def_function(srna, "new", "curvemap_insert");
548 RNA_def_function_ui_description(func, "Add point to CurveMap");
549 parm = RNA_def_float(func, "position", 0.0f, -FLT_MAX, FLT_MAX, "Position", "Position to add point", -FLT_MAX, FLT_MAX);
550 RNA_def_property_flag(parm, PROP_REQUIRED);
551 parm = RNA_def_float(func, "value", 0.0f, -FLT_MAX, FLT_MAX, "Value", "Value of point", -FLT_MAX, FLT_MAX);
552 RNA_def_property_flag(parm, PROP_REQUIRED);
553 parm = RNA_def_pointer(func, "point", "CurveMapPoint", "", "New point");
554 RNA_def_function_return(func, parm);
556 func = RNA_def_function(srna, "remove", "curvemap_remove_point");
557 RNA_def_function_ui_description(func, "Delete point from CurveMap");
558 parm = RNA_def_pointer(func, "point", "CurveMapPoint", "", "PointElement to remove");
559 RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL);
562 static void rna_def_curvemap(BlenderRNA *brna)
565 PropertyRNA *prop, *parm;
568 static EnumPropertyItem prop_extend_items[] = {
569 {0, "HORIZONTAL", 0, "Horizontal", ""},
570 {CUMA_EXTEND_EXTRAPOLATE, "EXTRAPOLATED", 0, "Extrapolated", ""},
571 {0, NULL, 0, NULL, NULL}
574 srna = RNA_def_struct(brna, "CurveMap", NULL);
575 RNA_def_struct_ui_text(srna, "CurveMap", "Curve in a curve mapping");
577 prop = RNA_def_property(srna, "extend", PROP_ENUM, PROP_NONE);
578 RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
579 RNA_def_property_enum_items(prop, prop_extend_items);
580 RNA_def_property_ui_text(prop, "Extend", "Extrapolate the curve or extend it horizontally");
582 prop = RNA_def_property(srna, "points", PROP_COLLECTION, PROP_NONE);
583 RNA_def_property_collection_sdna(prop, NULL, "curve", "totpoint");
584 RNA_def_property_struct_type(prop, "CurveMapPoint");
585 RNA_def_property_ui_text(prop, "Points", "");
586 rna_def_curvemap_points_api(brna, prop);
588 func = RNA_def_function(srna, "evaluate", "rna_CurveMap_evaluateF");
589 RNA_def_function_ui_description(func, "Evaluate curve at given location");
590 parm = RNA_def_float(func, "position", 0.0f, -FLT_MAX, FLT_MAX, "Position", "Position to evaluate curve at", -FLT_MAX, FLT_MAX);
591 RNA_def_property_flag(parm, PROP_REQUIRED);
592 parm = RNA_def_float(func, "value", 0.0f, -FLT_MAX, FLT_MAX, "Value", "Value of curve at given location", -FLT_MAX, FLT_MAX);
593 RNA_def_function_return(func, parm);
596 static void rna_def_curvemapping(BlenderRNA *brna)
602 srna = RNA_def_struct(brna, "CurveMapping", NULL);
603 RNA_def_struct_ui_text(srna, "CurveMapping",
604 "Curve mapping to map color, vector and scalar values to other values using "
605 "a user defined curve");
607 prop = RNA_def_property(srna, "use_clip", PROP_BOOLEAN, PROP_NONE);
608 RNA_def_property_boolean_sdna(prop, NULL, "flag", CUMA_DO_CLIP);
609 RNA_def_property_ui_text(prop, "Clip", "Force the curve view to fit a defined boundary");
610 RNA_def_property_boolean_funcs(prop, NULL, "rna_CurveMapping_clip_set");
612 prop = RNA_def_property(srna, "clip_min_x", PROP_FLOAT, PROP_NONE);
613 RNA_def_property_float_sdna(prop, NULL, "clipr.xmin");
614 RNA_def_property_range(prop, -100.0f, 100.0f);
615 RNA_def_property_ui_text(prop, "Clip Min X", "");
616 RNA_def_property_float_funcs(prop, NULL, NULL, "rna_CurveMapping_clipminx_range");
618 prop = RNA_def_property(srna, "clip_min_y", PROP_FLOAT, PROP_NONE);
619 RNA_def_property_float_sdna(prop, NULL, "clipr.ymin");
620 RNA_def_property_range(prop, -100.0f, 100.0f);
621 RNA_def_property_ui_text(prop, "Clip Min Y", "");
622 RNA_def_property_float_funcs(prop, NULL, NULL, "rna_CurveMapping_clipminy_range");
624 prop = RNA_def_property(srna, "clip_max_x", PROP_FLOAT, PROP_NONE);
625 RNA_def_property_float_sdna(prop, NULL, "clipr.xmax");
626 RNA_def_property_range(prop, -100.0f, 100.0f);
627 RNA_def_property_ui_text(prop, "Clip Max X", "");
628 RNA_def_property_float_funcs(prop, NULL, NULL, "rna_CurveMapping_clipmaxx_range");
630 prop = RNA_def_property(srna, "clip_max_y", PROP_FLOAT, PROP_NONE);
631 RNA_def_property_float_sdna(prop, NULL, "clipr.ymax");
632 RNA_def_property_range(prop, -100.0f, 100.0f);
633 RNA_def_property_ui_text(prop, "Clip Max Y", "");
634 RNA_def_property_float_funcs(prop, NULL, NULL, "rna_CurveMapping_clipmaxy_range");
636 prop = RNA_def_property(srna, "curves", PROP_COLLECTION, PROP_NONE);
637 RNA_def_property_collection_funcs(prop, "rna_CurveMapping_curves_begin", "rna_iterator_array_next",
638 "rna_iterator_array_end", "rna_iterator_array_get",
639 "rna_CurveMapping_curves_length", NULL, NULL, NULL);
640 RNA_def_property_struct_type(prop, "CurveMap");
641 RNA_def_property_ui_text(prop, "Curves", "");
643 prop = RNA_def_property(srna, "black_level", PROP_FLOAT, PROP_COLOR);
644 RNA_def_property_float_sdna(prop, NULL, "black");
645 RNA_def_property_range(prop, -1000.0f, 1000.0f);
646 RNA_def_property_ui_text(prop, "Black Level", "For RGB curves, the color that black is mapped to");
647 RNA_def_property_float_funcs(prop, NULL, "rna_CurveMapping_black_level_set", NULL);
649 prop = RNA_def_property(srna, "white_level", PROP_FLOAT, PROP_COLOR);
650 RNA_def_property_float_sdna(prop, NULL, "white");
651 RNA_def_property_range(prop, -1000.0f, 1000.0f);
652 RNA_def_property_ui_text(prop, "White Level", "For RGB curves, the color that white is mapped to");
653 RNA_def_property_float_funcs(prop, NULL, "rna_CurveMapping_white_level_set", NULL);
655 func = RNA_def_function(srna, "update", "curvemapping_changed_all");
656 RNA_def_function_ui_description(func, "Update curve mapping after making changes");
659 static void rna_def_color_ramp_element(BlenderRNA *brna)
664 srna = RNA_def_struct(brna, "ColorRampElement", NULL);
665 RNA_def_struct_sdna(srna, "CBData");
666 RNA_def_struct_path_func(srna, "rna_ColorRampElement_path");
667 RNA_def_struct_ui_text(srna, "Color Ramp Element", "Element defining a color at a position in the color ramp");
669 prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR);
670 RNA_def_property_float_sdna(prop, NULL, "r");
671 RNA_def_property_array(prop, 4);
672 RNA_def_property_ui_text(prop, "Color", "Set color of selected color stop");
673 RNA_def_property_update(prop, 0, "rna_ColorRamp_update");
675 prop = RNA_def_property(srna, "position", PROP_FLOAT, PROP_NONE);
676 RNA_def_property_float_sdna(prop, NULL, "pos");
677 RNA_def_property_range(prop, 0, 1);
678 RNA_def_property_ui_text(prop, "Position", "Set position of selected color stop");
679 RNA_def_property_update(prop, 0, "rna_ColorRamp_update");
682 static void rna_def_color_ramp_element_api(BlenderRNA *brna, PropertyRNA *cprop)
688 RNA_def_property_srna(cprop, "ColorRampElements");
689 srna = RNA_def_struct(brna, "ColorRampElements", NULL);
690 RNA_def_struct_sdna(srna, "ColorBand");
691 RNA_def_struct_path_func(srna, "rna_ColorRampElement_path");
692 RNA_def_struct_ui_text(srna, "Color Ramp Elements", "Collection of Color Ramp Elements");
694 /* TODO, make these functions generic in texture.c */
695 func = RNA_def_function(srna, "new", "rna_ColorRampElement_new");
696 RNA_def_function_ui_description(func, "Add element to ColorRamp");
697 RNA_def_function_flag(func, FUNC_USE_REPORTS);
698 parm = RNA_def_float(func, "position", 0.0f, 0.0f, 1.0f, "Position", "Position to add element", 0.0f, 1.0f);
699 RNA_def_property_flag(parm, PROP_REQUIRED);
701 parm = RNA_def_pointer(func, "element", "ColorRampElement", "", "New element");
702 RNA_def_function_return(func, parm);
704 func = RNA_def_function(srna, "remove", "rna_ColorRampElement_remove");
705 RNA_def_function_ui_description(func, "Delete element from ColorRamp");
706 RNA_def_function_flag(func, FUNC_USE_REPORTS);
707 parm = RNA_def_pointer(func, "element", "ColorRampElement", "", "Element to remove");
708 RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL);
711 static void rna_def_color_ramp(BlenderRNA *brna)
717 static EnumPropertyItem prop_interpolation_items[] = {
718 {1, "EASE", 0, "Ease", ""},
719 {3, "CARDINAL", 0, "Cardinal", ""},
720 {0, "LINEAR", 0, "Linear", ""},
721 {2, "B_SPLINE", 0, "B-Spline", ""},
722 {4, "CONSTANT", 0, "Constant", ""},
723 {0, NULL, 0, NULL, NULL}
726 srna = RNA_def_struct(brna, "ColorRamp", NULL);
727 RNA_def_struct_sdna(srna, "ColorBand");
728 RNA_def_struct_path_func(srna, "rna_ColorRamp_path");
729 RNA_def_struct_ui_text(srna, "Color Ramp", "Color ramp mapping a scalar value to a color");
731 prop = RNA_def_property(srna, "elements", PROP_COLLECTION, PROP_COLOR);
732 RNA_def_property_collection_sdna(prop, NULL, "data", "tot");
733 RNA_def_property_struct_type(prop, "ColorRampElement");
734 RNA_def_property_ui_text(prop, "Elements", "");
735 RNA_def_property_update(prop, 0, "rna_ColorRamp_update");
736 rna_def_color_ramp_element_api(brna, prop);
738 prop = RNA_def_property(srna, "interpolation", PROP_ENUM, PROP_NONE);
739 RNA_def_property_enum_sdna(prop, NULL, "ipotype");
740 RNA_def_property_enum_items(prop, prop_interpolation_items);
741 RNA_def_property_ui_text(prop, "Interpolation", "");
742 RNA_def_property_update(prop, 0, "rna_ColorRamp_update");
744 #if 0 /* use len(elements) */
745 prop = RNA_def_property(srna, "total", PROP_INT, PROP_NONE);
746 RNA_def_property_int_sdna(prop, NULL, "tot");
747 /* needs a function to do the right thing when adding elements like colorband_add_cb() */
748 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
749 RNA_def_property_range(prop, 0, 31); /* MAXCOLORBAND = 32 */
750 RNA_def_property_ui_text(prop, "Total", "Total number of elements");
751 RNA_def_property_update(prop, 0, "rna_ColorRamp_update");
754 func = RNA_def_function(srna, "evaluate", "rna_ColorRamp_eval");
755 RNA_def_function_ui_description(func, "Evaluate ColorRamp");
756 prop = RNA_def_float(func, "position", 1.0f, 0.0f, 1.0f, "Position", "Evaluate ColorRamp at position", 0.0f, 1.0f);
757 RNA_def_property_flag(prop, PROP_REQUIRED);
759 prop = RNA_def_float_color(func, "color", 4, NULL, -FLT_MAX, FLT_MAX, "Color", "Color at given position",
761 RNA_def_property_flag(prop, PROP_THICK_WRAP);
762 RNA_def_function_output(func, prop);
765 static void rna_def_histogram(BlenderRNA *brna)
770 static EnumPropertyItem prop_mode_items[] = {
771 {HISTO_MODE_LUMA, "LUMA", 0, "Luma", "Luma"},
772 {HISTO_MODE_RGB, "RGB", 0, "RGB", "Red Green Blue"},
773 {HISTO_MODE_R, "R", 0, "R", "Red"},
774 {HISTO_MODE_G, "G", 0, "G", "Green"},
775 {HISTO_MODE_B, "B", 0, "B", "Blue"},
776 {HISTO_MODE_ALPHA, "A", 0, "A", "Alpha"},
777 {0, NULL, 0, NULL, NULL}
780 srna = RNA_def_struct(brna, "Histogram", NULL);
781 RNA_def_struct_ui_text(srna, "Histogram", "Statistical view of the levels of color in an image");
783 prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
784 RNA_def_property_enum_sdna(prop, NULL, "mode");
785 RNA_def_property_enum_items(prop, prop_mode_items);
786 RNA_def_property_ui_text(prop, "Mode", "Channels to display when drawing the histogram");
788 prop = RNA_def_property(srna, "show_line", PROP_BOOLEAN, PROP_NONE);
789 RNA_def_property_boolean_sdna(prop, NULL, "flag", HISTO_FLAG_LINE);
790 RNA_def_property_ui_text(prop, "Show Line", "Display lines rather then filled shapes");
791 RNA_def_property_ui_icon(prop, ICON_IPO, 0);
794 static void rna_def_scopes(BlenderRNA *brna)
799 static EnumPropertyItem prop_wavefrm_mode_items[] = {
800 {SCOPES_WAVEFRM_LUMA, "LUMA", ICON_COLOR, "Luma", ""},
801 {SCOPES_WAVEFRM_RGB, "RGB", ICON_COLOR, "Red Green Blue", ""},
802 {SCOPES_WAVEFRM_YCC_601, "YCBCR601", ICON_COLOR, "YCbCr (ITU 601)", ""},
803 {SCOPES_WAVEFRM_YCC_709, "YCBCR709", ICON_COLOR, "YCbCr (ITU 709)", ""},
804 {SCOPES_WAVEFRM_YCC_JPEG, "YCBCRJPG", ICON_COLOR, "YCbCr (Jpeg)", ""},
805 {0, NULL, 0, NULL, NULL}
808 srna = RNA_def_struct(brna, "Scopes", NULL);
809 RNA_def_struct_ui_text(srna, "Scopes", "Scopes for statistical view of an image");
811 prop = RNA_def_property(srna, "use_full_resolution", PROP_BOOLEAN, PROP_NONE);
812 RNA_def_property_boolean_sdna(prop, "Scopes", "sample_full", 1);
813 RNA_def_property_ui_text(prop, "Full Sample", "Sample every pixel of the image");
814 RNA_def_property_update(prop, 0, "rna_Scopes_update");
816 prop = RNA_def_property(srna, "accuracy", PROP_FLOAT, PROP_PERCENTAGE);
817 RNA_def_property_float_sdna(prop, "Scopes", "accuracy");
818 RNA_def_property_range(prop, 0.0, 100.0);
819 RNA_def_property_ui_range(prop, 0.0, 100.0, 10, 1);
820 RNA_def_property_ui_text(prop, "Accuracy", "Proportion of original image source pixel lines to sample");
821 RNA_def_property_update(prop, 0, "rna_Scopes_update");
823 prop = RNA_def_property(srna, "histogram", PROP_POINTER, PROP_NONE);
824 RNA_def_property_pointer_sdna(prop, "Scopes", "hist");
825 RNA_def_property_struct_type(prop, "Histogram");
826 RNA_def_property_ui_text(prop, "Histogram", "Histogram for viewing image statistics");
828 prop = RNA_def_property(srna, "waveform_mode", PROP_ENUM, PROP_NONE);
829 RNA_def_property_enum_sdna(prop, "Scopes", "wavefrm_mode");
830 RNA_def_property_enum_items(prop, prop_wavefrm_mode_items);
831 RNA_def_property_ui_text(prop, "Waveform Mode", "");
832 RNA_def_property_update(prop, 0, "rna_Scopes_update");
834 prop = RNA_def_property(srna, "waveform_alpha", PROP_FLOAT, PROP_FACTOR);
835 RNA_def_property_float_sdna(prop, "Scopes", "wavefrm_alpha");
836 RNA_def_property_range(prop, 0, 1);
837 RNA_def_property_ui_text(prop, "Waveform Opacity", "Opacity of the points");
839 prop = RNA_def_property(srna, "vectorscope_alpha", PROP_FLOAT, PROP_FACTOR);
840 RNA_def_property_float_sdna(prop, "Scopes", "vecscope_alpha");
841 RNA_def_property_range(prop, 0, 1);
842 RNA_def_property_ui_text(prop, "Vectorscope Opacity", "Opacity of the points");
845 static void rna_def_colormanage(BlenderRNA *brna)
850 static EnumPropertyItem display_device_items[] = {
851 {0, "DEFAULT", 0, "Default", ""},
852 {0, NULL, 0, NULL, NULL}
855 static EnumPropertyItem view_transform_items[] = {
856 {0, "NONE", 0, "None", "Do not perform any color transform on display, use old non-color managed technique for display"},
857 {0, NULL, 0, NULL, NULL}
860 static EnumPropertyItem color_space_items[] = {
861 {0, "NONE", 0, "None", "Do not perform any color transform on load, treat colors as in scene linear space already"},
862 {0, NULL, 0, NULL, NULL}
865 /* ** Display Settings ** */
866 srna = RNA_def_struct(brna, "ColorManagedDisplaySettings", NULL);
867 RNA_def_struct_ui_text(srna, "ColorManagedDisplaySettings", "Color management specific to display device");
869 prop= RNA_def_property(srna, "display_device", PROP_ENUM, PROP_NONE);
870 RNA_def_property_enum_items(prop, display_device_items);
871 RNA_def_property_enum_funcs(prop, "rna_ColorManagedDisplaySettings_display_device_get",
872 "rna_ColorManagedDisplaySettings_display_device_set",
873 "rna_ColorManagedDisplaySettings_display_device_itemf");
874 RNA_def_property_ui_text(prop, "Display Device", "Display device name");
875 RNA_def_property_update(prop, NC_WINDOW, "rna_ColorManagedDisplaySettings_display_device_update");
877 /* ** View Settings ** */
878 srna = RNA_def_struct(brna, "ColorManagedViewSettings", NULL);
879 RNA_def_struct_ui_text(srna, "ColorManagedViewSettings", "Color management settings used for displaying images on the display");
881 prop= RNA_def_property(srna, "view_transform", PROP_ENUM, PROP_NONE);
882 RNA_def_property_enum_items(prop, view_transform_items);
883 RNA_def_property_enum_funcs(prop, "rna_ColorManagedViewSettings_view_transform_get",
884 "rna_ColorManagedViewSettings_view_transform_set",
885 "rna_ColorManagedViewSettings_view_transform_itemf");
886 RNA_def_property_ui_text(prop, "View Transform", "View used ");
887 RNA_def_property_update(prop, NC_WINDOW, "rna_ColorManagement_update");
889 prop = RNA_def_property(srna, "exposure", PROP_FLOAT, PROP_FACTOR);
890 RNA_def_property_float_sdna(prop, NULL, "exposure");
891 RNA_def_property_range(prop, -10.0f, 10.0f);
892 RNA_def_property_float_default(prop, 0.0f);
893 RNA_def_property_ui_text(prop, "Exposure", "Exposure (stops) applied before display transform");
894 RNA_def_property_update(prop, NC_WINDOW, "rna_ColorManagement_update");
896 prop = RNA_def_property(srna, "gamma", PROP_FLOAT, PROP_FACTOR);
897 RNA_def_property_float_sdna(prop, NULL, "gamma");
898 RNA_def_property_float_default(prop, 1.0f);
899 RNA_def_property_range(prop, 0.0f, 5.0f);
900 RNA_def_property_ui_text(prop, "Gamma", "Amount of gamma modification applied after display transform");
901 RNA_def_property_update(prop, NC_WINDOW, "rna_ColorManagement_update");
903 prop = RNA_def_property(srna, "curve_mapping", PROP_POINTER, PROP_NONE);
904 RNA_def_property_pointer_sdna(prop, NULL, "curve_mapping");
905 RNA_def_property_ui_text(prop, "Curve", "Color curve mapping applied before display transform");
906 RNA_def_property_update(prop, NC_WINDOW, "rna_ColorManagement_update");
908 prop = RNA_def_property(srna, "use_curve_mapping", PROP_BOOLEAN, PROP_NONE);
909 RNA_def_property_boolean_sdna(prop, NULL, "flag", COLORMANAGE_VIEW_USE_CURVES);
910 RNA_def_property_boolean_funcs(prop, NULL, "rna_ColorManagedViewSettings_use_curves_set");
911 RNA_def_property_ui_text(prop, "Use Curves", "Use RGB curved for pre-display transformation");
912 RNA_def_property_update(prop, NC_WINDOW, "rna_ColorManagement_update");
914 /* ** Colorspace ** */
915 srna = RNA_def_struct(brna, "ColorManagedColorspaceSettings", NULL);
916 RNA_def_struct_ui_text(srna, "ColorManagedColorspaceSettings", "Input color space settings");
918 prop= RNA_def_property(srna, "name", PROP_ENUM, PROP_NONE);
919 RNA_def_property_enum_items(prop, color_space_items);
920 RNA_def_property_enum_funcs(prop, "rna_ColorManagedColorspaceSettings_colorspace_get",
921 "rna_ColorManagedColorspaceSettings_colorspace_set",
922 "rna_ColorManagedColorspaceSettings_colorspace_itemf");
923 RNA_def_property_ui_text(prop, "Color Space", "Input color space name");
924 RNA_def_property_update(prop, NC_WINDOW, "rna_ColorManagedColorspaceSettings_reload_update");
927 void RNA_def_color(BlenderRNA *brna)
929 rna_def_curvemappoint(brna);
930 rna_def_curvemap(brna);
931 rna_def_curvemapping(brna);
932 rna_def_color_ramp_element(brna);
933 rna_def_color_ramp(brna);
934 rna_def_histogram(brna);
935 rna_def_scopes(brna);
936 rna_def_colormanage(brna);