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"
40 static EnumPropertyItem view_transform_items[] = {
41 {0, "NONE", 0, "None", ""},
42 {0, NULL, 0, NULL, NULL}
47 #include "RNA_access.h"
49 #include "DNA_material_types.h"
50 #include "DNA_node_types.h"
52 #include "MEM_guardedalloc.h"
54 #include "BKE_colortools.h"
55 #include "BKE_depsgraph.h"
57 #include "BKE_texture.h"
61 #include "IMB_colormanagement.h"
63 static int rna_CurveMapping_curves_length(PointerRNA *ptr)
65 CurveMapping *cumap = (CurveMapping *)ptr->data;
68 for (len = 0; len < CM_TOT; len++)
69 if (!cumap->cm[len].curve)
75 static void rna_CurveMapping_curves_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
77 CurveMapping *cumap = (CurveMapping *)ptr->data;
79 rna_iterator_array_begin(iter, cumap->cm, sizeof(CurveMap), rna_CurveMapping_curves_length(ptr), 0, NULL);
82 static void rna_CurveMapping_clip_set(PointerRNA *ptr, int value)
84 CurveMapping *cumap = (CurveMapping *)ptr->data;
86 if (value) cumap->flag |= CUMA_DO_CLIP;
87 else cumap->flag &= ~CUMA_DO_CLIP;
89 curvemapping_changed(cumap, 0);
92 static void rna_CurveMapping_black_level_set(PointerRNA *ptr, const float *values)
94 CurveMapping *cumap = (CurveMapping *)ptr->data;
95 cumap->black[0] = values[0];
96 cumap->black[1] = values[1];
97 cumap->black[2] = values[2];
98 curvemapping_set_black_white(cumap, NULL, NULL);
101 static void rna_CurveMapping_white_level_set(PointerRNA *ptr, const float *values)
103 CurveMapping *cumap = (CurveMapping *)ptr->data;
104 cumap->white[0] = values[0];
105 cumap->white[1] = values[1];
106 cumap->white[2] = values[2];
107 curvemapping_set_black_white(cumap, NULL, NULL);
110 static void rna_CurveMapping_clipminx_range(PointerRNA *ptr, float *min, float *max, float *softmin, float *softmax)
112 CurveMapping *cumap = (CurveMapping *)ptr->data;
115 *max = cumap->clipr.xmax;
118 static void rna_CurveMapping_clipminy_range(PointerRNA *ptr, float *min, float *max, float *softmin, float *softmax)
120 CurveMapping *cumap = (CurveMapping *)ptr->data;
123 *max = cumap->clipr.ymax;
126 static void rna_CurveMapping_clipmaxx_range(PointerRNA *ptr, float *min, float *max, float *softmin, float *softmax)
128 CurveMapping *cumap = (CurveMapping *)ptr->data;
130 *min = cumap->clipr.xmin;
134 static void rna_CurveMapping_clipmaxy_range(PointerRNA *ptr, float *min, float *max, float *softmin, float *softmax)
136 CurveMapping *cumap = (CurveMapping *)ptr->data;
138 *min = cumap->clipr.ymin;
143 static char *rna_ColorRamp_path(PointerRNA *ptr)
147 /* handle the cases where a single datablock may have 2 ramp types */
149 ID *id = ptr->id.data;
151 switch (GS(id->name)) {
152 case ID_MA: /* material has 2 cases - diffuse and specular */
154 Material *ma = (Material *)id;
156 if (ptr->data == ma->ramp_col)
157 path = BLI_strdup("diffuse_ramp");
158 else if (ptr->data == ma->ramp_spec)
159 path = BLI_strdup("specular_ramp");
165 bNodeTree *ntree = (bNodeTree *)id;
170 for (node = ntree->nodes.first; node; node = node->next) {
171 if (ELEM3(node->type, SH_NODE_VALTORGB, CMP_NODE_VALTORGB, TEX_NODE_VALTORGB)) {
172 if (node->storage == ptr->data) {
173 /* all node color ramp properties called 'color_ramp'
174 * prepend path from ID to the node
176 RNA_pointer_create(id, &RNA_Node, node, &node_ptr);
177 node_path = RNA_path_from_ID_to_struct(&node_ptr);
178 path = BLI_sprintfN("%s.color_ramp", node_path);
179 MEM_freeN(node_path);
187 /* everything else just uses 'color_ramp' */
188 path = BLI_strdup("color_ramp");
193 /* everything else just uses 'color_ramp' */
194 path = BLI_strdup("color_ramp");
200 static char *rna_ColorRampElement_path(PointerRNA *ptr)
207 /* helper macro for use here to try and get the path
208 * - this calls the standard code for getting a path to a texture...
211 #define COLRAMP_GETPATH \
213 prop = RNA_struct_find_property(&ramp_ptr, "elements"); \
215 index = RNA_property_collection_lookup_index(&ramp_ptr, prop, ptr); \
217 char *texture_path = rna_ColorRamp_path(&ramp_ptr); \
218 path = BLI_sprintfN("%s.elements[%d]", texture_path, index); \
219 MEM_freeN(texture_path); \
224 /* determine the path from the ID-block to the ramp */
225 /* FIXME: this is a very slow way to do it, but it will have to suffice... */
227 ID *id = ptr->id.data;
229 switch (GS(id->name)) {
230 case ID_MA: /* 2 cases for material - diffuse and spec */
232 Material *ma = (Material *)id;
234 /* try diffuse first */
236 RNA_pointer_create(id, &RNA_ColorRamp, ma->ramp_col, &ramp_ptr);
239 /* try specular if not diffuse */
240 if (!path && ma->ramp_spec) {
241 RNA_pointer_create(id, &RNA_ColorRamp, ma->ramp_spec, &ramp_ptr);
249 bNodeTree *ntree = (bNodeTree *)id;
252 for (node = ntree->nodes.first; node; node = node->next) {
253 if (ELEM3(node->type, SH_NODE_VALTORGB, CMP_NODE_VALTORGB, TEX_NODE_VALTORGB)) {
254 RNA_pointer_create(id, &RNA_ColorRamp, node->storage, &ramp_ptr);
261 default: /* everything else should have a "color_ramp" property */
263 /* create pointer to the ID block, and try to resolve "color_ramp" pointer */
264 RNA_id_pointer_create(id, &ramp_ptr);
265 if (RNA_path_resolve(&ramp_ptr, "color_ramp", &ramp_ptr, &prop)) {
272 /* cleanup the macro we defined */
273 #undef COLRAMP_GETPATH
278 static void rna_ColorRamp_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
281 ID *id = ptr->id.data;
283 switch (GS(id->name)) {
286 Material *ma = ptr->id.data;
288 DAG_id_tag_update(&ma->id, 0);
289 WM_main_add_notifier(NC_MATERIAL | ND_SHADING_DRAW, ma);
294 bNodeTree *ntree = (bNodeTree *)id;
297 for (node = ntree->nodes.first; node; node = node->next) {
298 if (ELEM3(node->type, SH_NODE_VALTORGB, CMP_NODE_VALTORGB, TEX_NODE_VALTORGB)) {
299 ED_node_generic_update(bmain, ntree, node);
306 Tex *tex = ptr->id.data;
308 DAG_id_tag_update(&tex->id, 0);
309 WM_main_add_notifier(NC_TEXTURE, tex);
318 void rna_ColorRamp_eval(struct ColorBand *coba, float position, float color[4])
320 do_colorband(coba, position, color);
323 static CBData *rna_ColorRampElement_new(struct ColorBand *coba, ReportList *reports, float position)
325 CBData *element = colorband_element_add(coba, position);
328 BKE_reportf(reports, RPT_ERROR, "Unable to add element to colorband (limit %d)", MAXCOLORBAND);
333 static void rna_ColorRampElement_remove(struct ColorBand *coba, ReportList *reports, CBData *element)
335 int index = (int)(element - coba->data);
336 if (colorband_element_remove(coba, index) == 0)
337 BKE_report(reports, RPT_ERROR, "Element not found in element collection or last element");
341 static void rna_Scopes_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
343 Scopes *s = (Scopes *)ptr->data;
347 static int rna_ColorManagedDisplaySettings_display_device_get(struct PointerRNA *ptr)
349 ColorManagedDisplaySettings *display = (ColorManagedDisplaySettings *) ptr->data;
351 return IMB_colormanagement_display_get_named_index(display->display_device);
354 static void rna_ColorManagedDisplaySettings_display_device_set(struct PointerRNA *ptr, int value)
356 ColorManagedDisplaySettings *display = (ColorManagedDisplaySettings *) ptr->data;
357 const char *name = IMB_colormanagement_display_get_indexed_name(value);
360 BLI_strncpy(display->display_device, name, sizeof(display->display_device));
364 static EnumPropertyItem *rna_ColorManagedDisplaySettings_display_device_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *UNUSED(prop), int *free)
366 EnumPropertyItem *items = NULL;
369 IMB_colormanagement_display_items_add(&items, &totitem);
370 RNA_enum_item_end(&items, &totitem);
377 static int rna_ColorManagedViewSettings_view_transform_get(PointerRNA *ptr)
379 ColorManagedViewSettings *view = (ColorManagedViewSettings *) ptr->data;
381 return IMB_colormanagement_view_get_named_index(view->view_transform);
384 static void rna_ColorManagedViewSettings_view_transform_set(PointerRNA *ptr, int value)
386 ColorManagedViewSettings *view = (ColorManagedViewSettings *) ptr->data;
388 const char *name = IMB_colormanagement_view_get_indexed_name(value);
391 BLI_strncpy(view->view_transform, name, sizeof(view->view_transform));
395 static EnumPropertyItem* rna_ColorManagedViewSettings_view_transform_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *UNUSED(prop), int *free)
397 wmWindow *win = CTX_wm_window(C);
398 EnumPropertyItem *items = NULL;
399 ColorManagedDisplaySettings *display_settings = &win->display_settings;
402 RNA_enum_item_add(&items, &totitem, &view_transform_items[0]);
403 IMB_colormanagement_view_items_add(&items, &totitem, display_settings->display_device);
404 RNA_enum_item_end(&items, &totitem);
412 static void rna_def_curvemappoint(BlenderRNA *brna)
416 static EnumPropertyItem prop_handle_type_items[] = {
417 {0, "AUTO", 0, "Auto Handle", ""},
418 {CUMA_VECTOR, "VECTOR", 0, "Vector Handle", ""},
419 {0, NULL, 0, NULL, NULL}
422 srna = RNA_def_struct(brna, "CurveMapPoint", NULL);
423 RNA_def_struct_ui_text(srna, "CurveMapPoint", "Point of a curve used for a curve mapping");
425 prop = RNA_def_property(srna, "location", PROP_FLOAT, PROP_XYZ);
426 RNA_def_property_float_sdna(prop, NULL, "x");
427 RNA_def_property_array(prop, 2);
428 RNA_def_property_ui_text(prop, "Location", "X/Y coordinates of the curve point");
430 prop = RNA_def_property(srna, "handle_type", PROP_ENUM, PROP_NONE);
431 RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
432 RNA_def_property_enum_items(prop, prop_handle_type_items);
433 RNA_def_property_ui_text(prop, "Handle Type", "Curve interpolation at this point: Bezier or vector");
435 prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
436 RNA_def_property_boolean_sdna(prop, NULL, "flag", CUMA_SELECT);
437 RNA_def_property_ui_text(prop, "Select", "Selection state of the curve point");
440 static void rna_def_curvemap_points_api(BlenderRNA *brna, PropertyRNA *cprop)
446 RNA_def_property_srna(cprop, "CurveMapPoints");
447 srna = RNA_def_struct(brna, "CurveMapPoints", NULL);
448 RNA_def_struct_sdna(srna, "CurveMap");
449 RNA_def_struct_ui_text(srna, "Curve Map Point", "Collection of Curve Map Points");
451 func = RNA_def_function(srna, "new", "curvemap_insert");
452 RNA_def_function_ui_description(func, "Add point to CurveMap");
453 parm = RNA_def_float(func, "position", 0.0f, -FLT_MAX, FLT_MAX, "Position", "Position to add point", -FLT_MAX, FLT_MAX);
454 RNA_def_property_flag(parm, PROP_REQUIRED);
455 parm = RNA_def_float(func, "value", 0.0f, -FLT_MAX, FLT_MAX, "Value", "Value of point", -FLT_MAX, FLT_MAX);
456 RNA_def_property_flag(parm, PROP_REQUIRED);
457 parm = RNA_def_pointer(func, "point", "CurveMapPoint", "", "New point");
458 RNA_def_function_return(func, parm);
460 func = RNA_def_function(srna, "remove", "curvemap_remove_point");
461 RNA_def_function_ui_description(func, "Delete point from CurveMap");
462 parm = RNA_def_pointer(func, "point", "CurveMapPoint", "", "PointElement to remove");
463 RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL);
466 static void rna_def_curvemap(BlenderRNA *brna)
469 PropertyRNA *prop, *parm;
472 static EnumPropertyItem prop_extend_items[] = {
473 {0, "HORIZONTAL", 0, "Horizontal", ""},
474 {CUMA_EXTEND_EXTRAPOLATE, "EXTRAPOLATED", 0, "Extrapolated", ""},
475 {0, NULL, 0, NULL, NULL}
478 srna = RNA_def_struct(brna, "CurveMap", NULL);
479 RNA_def_struct_ui_text(srna, "CurveMap", "Curve in a curve mapping");
481 prop = RNA_def_property(srna, "extend", PROP_ENUM, PROP_NONE);
482 RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
483 RNA_def_property_enum_items(prop, prop_extend_items);
484 RNA_def_property_ui_text(prop, "Extend", "Extrapolate the curve or extend it horizontally");
486 prop = RNA_def_property(srna, "points", PROP_COLLECTION, PROP_NONE);
487 RNA_def_property_collection_sdna(prop, NULL, "curve", "totpoint");
488 RNA_def_property_struct_type(prop, "CurveMapPoint");
489 RNA_def_property_ui_text(prop, "Points", "");
490 rna_def_curvemap_points_api(brna, prop);
492 func = RNA_def_function(srna, "evaluate", "curvemap_evaluateF");
493 RNA_def_function_ui_description(func, "Evaluate curve at given location");
494 parm = RNA_def_float(func, "position", 0.0f, -FLT_MAX, FLT_MAX, "Position", "Position to evaluate curve at", -FLT_MAX, FLT_MAX);
495 RNA_def_property_flag(parm, PROP_REQUIRED);
496 parm = RNA_def_float(func, "value", 0.0f, -FLT_MAX, FLT_MAX, "Value", "Value of curve at given location", -FLT_MAX, FLT_MAX);
497 RNA_def_function_return(func, parm);
500 static void rna_def_curvemapping(BlenderRNA *brna)
506 srna = RNA_def_struct(brna, "CurveMapping", NULL);
507 RNA_def_struct_ui_text(srna, "CurveMapping",
508 "Curve mapping to map color, vector and scalar values to other values using "
509 "a user defined curve");
511 prop = RNA_def_property(srna, "use_clip", PROP_BOOLEAN, PROP_NONE);
512 RNA_def_property_boolean_sdna(prop, NULL, "flag", CUMA_DO_CLIP);
513 RNA_def_property_ui_text(prop, "Clip", "Force the curve view to fit a defined boundary");
514 RNA_def_property_boolean_funcs(prop, NULL, "rna_CurveMapping_clip_set");
516 prop = RNA_def_property(srna, "clip_min_x", PROP_FLOAT, PROP_NONE);
517 RNA_def_property_float_sdna(prop, NULL, "clipr.xmin");
518 RNA_def_property_range(prop, -100.0f, 100.0f);
519 RNA_def_property_ui_text(prop, "Clip Min X", "");
520 RNA_def_property_float_funcs(prop, NULL, NULL, "rna_CurveMapping_clipminx_range");
522 prop = RNA_def_property(srna, "clip_min_y", PROP_FLOAT, PROP_NONE);
523 RNA_def_property_float_sdna(prop, NULL, "clipr.ymin");
524 RNA_def_property_range(prop, -100.0f, 100.0f);
525 RNA_def_property_ui_text(prop, "Clip Min Y", "");
526 RNA_def_property_float_funcs(prop, NULL, NULL, "rna_CurveMapping_clipminy_range");
528 prop = RNA_def_property(srna, "clip_max_x", PROP_FLOAT, PROP_NONE);
529 RNA_def_property_float_sdna(prop, NULL, "clipr.xmax");
530 RNA_def_property_range(prop, -100.0f, 100.0f);
531 RNA_def_property_ui_text(prop, "Clip Max X", "");
532 RNA_def_property_float_funcs(prop, NULL, NULL, "rna_CurveMapping_clipmaxx_range");
534 prop = RNA_def_property(srna, "clip_max_y", PROP_FLOAT, PROP_NONE);
535 RNA_def_property_float_sdna(prop, NULL, "clipr.ymax");
536 RNA_def_property_range(prop, -100.0f, 100.0f);
537 RNA_def_property_ui_text(prop, "Clip Max Y", "");
538 RNA_def_property_float_funcs(prop, NULL, NULL, "rna_CurveMapping_clipmaxy_range");
540 prop = RNA_def_property(srna, "curves", PROP_COLLECTION, PROP_NONE);
541 RNA_def_property_collection_funcs(prop, "rna_CurveMapping_curves_begin", "rna_iterator_array_next",
542 "rna_iterator_array_end", "rna_iterator_array_get",
543 "rna_CurveMapping_curves_length", NULL, NULL, NULL);
544 RNA_def_property_struct_type(prop, "CurveMap");
545 RNA_def_property_ui_text(prop, "Curves", "");
547 prop = RNA_def_property(srna, "black_level", PROP_FLOAT, PROP_COLOR);
548 RNA_def_property_float_sdna(prop, NULL, "black");
549 RNA_def_property_range(prop, -1000.0f, 1000.0f);
550 RNA_def_property_ui_text(prop, "Black Level", "For RGB curves, the color that black is mapped to");
551 RNA_def_property_float_funcs(prop, NULL, "rna_CurveMapping_black_level_set", NULL);
553 prop = RNA_def_property(srna, "white_level", PROP_FLOAT, PROP_COLOR);
554 RNA_def_property_float_sdna(prop, NULL, "white");
555 RNA_def_property_range(prop, -1000.0f, 1000.0f);
556 RNA_def_property_ui_text(prop, "White Level", "For RGB curves, the color that white is mapped to");
557 RNA_def_property_float_funcs(prop, NULL, "rna_CurveMapping_white_level_set", NULL);
559 func = RNA_def_function(srna, "update", "curvemapping_changed_all");
560 RNA_def_function_ui_description(func, "Update curve mapping after making changes");
563 static void rna_def_color_ramp_element(BlenderRNA *brna)
568 srna = RNA_def_struct(brna, "ColorRampElement", NULL);
569 RNA_def_struct_sdna(srna, "CBData");
570 RNA_def_struct_path_func(srna, "rna_ColorRampElement_path");
571 RNA_def_struct_ui_text(srna, "Color Ramp Element", "Element defining a color at a position in the color ramp");
573 prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR);
574 RNA_def_property_float_sdna(prop, NULL, "r");
575 RNA_def_property_array(prop, 4);
576 RNA_def_property_ui_text(prop, "Color", "Set color of selected color stop");
577 RNA_def_property_update(prop, 0, "rna_ColorRamp_update");
579 prop = RNA_def_property(srna, "position", PROP_FLOAT, PROP_NONE);
580 RNA_def_property_float_sdna(prop, NULL, "pos");
581 RNA_def_property_range(prop, 0, 1);
582 RNA_def_property_ui_text(prop, "Position", "Set position of selected color stop");
583 RNA_def_property_update(prop, 0, "rna_ColorRamp_update");
586 static void rna_def_color_ramp_element_api(BlenderRNA *brna, PropertyRNA *cprop)
592 RNA_def_property_srna(cprop, "ColorRampElements");
593 srna = RNA_def_struct(brna, "ColorRampElements", NULL);
594 RNA_def_struct_sdna(srna, "ColorBand");
595 RNA_def_struct_path_func(srna, "rna_ColorRampElement_path");
596 RNA_def_struct_ui_text(srna, "Color Ramp Elements", "Collection of Color Ramp Elements");
598 /* TODO, make these functions generic in texture.c */
599 func = RNA_def_function(srna, "new", "rna_ColorRampElement_new");
600 RNA_def_function_ui_description(func, "Add element to ColorRamp");
601 RNA_def_function_flag(func, FUNC_USE_REPORTS);
602 parm = RNA_def_float(func, "position", 0.0f, 0.0f, 1.0f, "Position", "Position to add element", 0.0f, 1.0f);
603 RNA_def_property_flag(parm, PROP_REQUIRED);
605 parm = RNA_def_pointer(func, "element", "ColorRampElement", "", "New element");
606 RNA_def_function_return(func, parm);
608 func = RNA_def_function(srna, "remove", "rna_ColorRampElement_remove");
609 RNA_def_function_ui_description(func, "Delete element from ColorRamp");
610 RNA_def_function_flag(func, FUNC_USE_REPORTS);
611 parm = RNA_def_pointer(func, "element", "ColorRampElement", "", "Element to remove");
612 RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL);
615 static void rna_def_color_ramp(BlenderRNA *brna)
621 static EnumPropertyItem prop_interpolation_items[] = {
622 {1, "EASE", 0, "Ease", ""},
623 {3, "CARDINAL", 0, "Cardinal", ""},
624 {0, "LINEAR", 0, "Linear", ""},
625 {2, "B_SPLINE", 0, "B-Spline", ""},
626 {4, "CONSTANT", 0, "Constant", ""},
627 {0, NULL, 0, NULL, NULL}
630 srna = RNA_def_struct(brna, "ColorRamp", NULL);
631 RNA_def_struct_sdna(srna, "ColorBand");
632 RNA_def_struct_path_func(srna, "rna_ColorRamp_path");
633 RNA_def_struct_ui_text(srna, "Color Ramp", "Color ramp mapping a scalar value to a color");
635 prop = RNA_def_property(srna, "elements", PROP_COLLECTION, PROP_COLOR);
636 RNA_def_property_collection_sdna(prop, NULL, "data", "tot");
637 RNA_def_property_struct_type(prop, "ColorRampElement");
638 RNA_def_property_ui_text(prop, "Elements", "");
639 RNA_def_property_update(prop, 0, "rna_ColorRamp_update");
640 rna_def_color_ramp_element_api(brna, prop);
642 prop = RNA_def_property(srna, "interpolation", PROP_ENUM, PROP_NONE);
643 RNA_def_property_enum_sdna(prop, NULL, "ipotype");
644 RNA_def_property_enum_items(prop, prop_interpolation_items);
645 RNA_def_property_ui_text(prop, "Interpolation", "");
646 RNA_def_property_update(prop, 0, "rna_ColorRamp_update");
648 #if 0 /* use len(elements) */
649 prop = RNA_def_property(srna, "total", PROP_INT, PROP_NONE);
650 RNA_def_property_int_sdna(prop, NULL, "tot");
651 /* needs a function to do the right thing when adding elements like colorband_add_cb() */
652 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
653 RNA_def_property_range(prop, 0, 31); /* MAXCOLORBAND = 32 */
654 RNA_def_property_ui_text(prop, "Total", "Total number of elements");
655 RNA_def_property_update(prop, 0, "rna_ColorRamp_update");
658 func = RNA_def_function(srna, "evaluate", "rna_ColorRamp_eval");
659 RNA_def_function_ui_description(func, "Evaluate ColorRamp");
660 prop = RNA_def_float(func, "position", 1.0f, 0.0f, 1.0f, "Position", "Evaluate ColorRamp at position", 0.0f, 1.0f);
661 RNA_def_property_flag(prop, PROP_REQUIRED);
663 prop = RNA_def_float_color(func, "color", 4, NULL, -FLT_MAX, FLT_MAX, "Color", "Color at given position",
665 RNA_def_property_flag(prop, PROP_THICK_WRAP);
666 RNA_def_function_output(func, prop);
669 static void rna_def_histogram(BlenderRNA *brna)
674 static EnumPropertyItem prop_mode_items[] = {
675 {HISTO_MODE_LUMA, "LUMA", 0, "Luma", "Luma"},
676 {HISTO_MODE_RGB, "RGB", 0, "RGB", "Red Green Blue"},
677 {HISTO_MODE_R, "R", 0, "R", "Red"},
678 {HISTO_MODE_G, "G", 0, "G", "Green"},
679 {HISTO_MODE_B, "B", 0, "B", "Blue"},
680 {HISTO_MODE_ALPHA, "A", 0, "A", "Alpha"},
681 {0, NULL, 0, NULL, NULL}
684 srna = RNA_def_struct(brna, "Histogram", NULL);
685 RNA_def_struct_ui_text(srna, "Histogram", "Statistical view of the levels of color in an image");
687 prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
688 RNA_def_property_enum_sdna(prop, NULL, "mode");
689 RNA_def_property_enum_items(prop, prop_mode_items);
690 RNA_def_property_ui_text(prop, "Mode", "Channels to display when drawing the histogram");
692 prop = RNA_def_property(srna, "show_line", PROP_BOOLEAN, PROP_NONE);
693 RNA_def_property_boolean_sdna(prop, NULL, "flag", HISTO_FLAG_LINE);
694 RNA_def_property_ui_text(prop, "Show Line", "Display lines rather then filled shapes");
695 RNA_def_property_ui_icon(prop, ICON_IPO, 0);
698 static void rna_def_scopes(BlenderRNA *brna)
703 static EnumPropertyItem prop_wavefrm_mode_items[] = {
704 {SCOPES_WAVEFRM_LUMA, "LUMA", ICON_COLOR, "Luma", ""},
705 {SCOPES_WAVEFRM_RGB, "RGB", ICON_COLOR, "Red Green Blue", ""},
706 {SCOPES_WAVEFRM_YCC_601, "YCBCR601", ICON_COLOR, "YCbCr (ITU 601)", ""},
707 {SCOPES_WAVEFRM_YCC_709, "YCBCR709", ICON_COLOR, "YCbCr (ITU 709)", ""},
708 {SCOPES_WAVEFRM_YCC_JPEG, "YCBCRJPG", ICON_COLOR, "YCbCr (Jpeg)", ""},
709 {0, NULL, 0, NULL, NULL}
712 srna = RNA_def_struct(brna, "Scopes", NULL);
713 RNA_def_struct_ui_text(srna, "Scopes", "Scopes for statistical view of an image");
715 prop = RNA_def_property(srna, "use_full_resolution", PROP_BOOLEAN, PROP_NONE);
716 RNA_def_property_boolean_sdna(prop, "Scopes", "sample_full", 1);
717 RNA_def_property_ui_text(prop, "Full Sample", "Sample every pixel of the image");
718 RNA_def_property_update(prop, 0, "rna_Scopes_update");
720 prop = RNA_def_property(srna, "accuracy", PROP_FLOAT, PROP_PERCENTAGE);
721 RNA_def_property_float_sdna(prop, "Scopes", "accuracy");
722 RNA_def_property_range(prop, 0.0, 100.0);
723 RNA_def_property_ui_range(prop, 0.0, 100.0, 10, 1);
724 RNA_def_property_ui_text(prop, "Accuracy", "Proportion of original image source pixel lines to sample");
725 RNA_def_property_update(prop, 0, "rna_Scopes_update");
727 prop = RNA_def_property(srna, "histogram", PROP_POINTER, PROP_NONE);
728 RNA_def_property_pointer_sdna(prop, "Scopes", "hist");
729 RNA_def_property_struct_type(prop, "Histogram");
730 RNA_def_property_ui_text(prop, "Histogram", "Histogram for viewing image statistics");
732 prop = RNA_def_property(srna, "waveform_mode", PROP_ENUM, PROP_NONE);
733 RNA_def_property_enum_sdna(prop, "Scopes", "wavefrm_mode");
734 RNA_def_property_enum_items(prop, prop_wavefrm_mode_items);
735 RNA_def_property_ui_text(prop, "Waveform Mode", "");
736 RNA_def_property_update(prop, 0, "rna_Scopes_update");
738 prop = RNA_def_property(srna, "waveform_alpha", PROP_FLOAT, PROP_FACTOR);
739 RNA_def_property_float_sdna(prop, "Scopes", "wavefrm_alpha");
740 RNA_def_property_range(prop, 0, 1);
741 RNA_def_property_ui_text(prop, "Waveform Opacity", "Opacity of the points");
743 prop = RNA_def_property(srna, "vectorscope_alpha", PROP_FLOAT, PROP_FACTOR);
744 RNA_def_property_float_sdna(prop, "Scopes", "vecscope_alpha");
745 RNA_def_property_range(prop, 0, 1);
746 RNA_def_property_ui_text(prop, "Vectorscope Opacity", "Opacity of the points");
749 static void rna_def_colormanage(BlenderRNA *brna)
754 static EnumPropertyItem display_device_items[] = {
755 {0, "DEFAULT", 0, "Default", ""},
756 {0, NULL, 0, NULL, NULL}
759 /* ** Display Settings ** */
760 srna = RNA_def_struct(brna, "ColorManagedDisplaySettings", NULL);
761 RNA_def_struct_ui_text(srna, "ColorManagedDisplaySettings", "Color management specific to display device");
763 prop= RNA_def_property(srna, "display_device", PROP_ENUM, PROP_NONE);
764 RNA_def_property_enum_items(prop, display_device_items);
765 RNA_def_property_enum_funcs(prop, "rna_ColorManagedDisplaySettings_display_device_get",
766 "rna_ColorManagedDisplaySettings_display_device_set",
767 "rna_ColorManagedDisplaySettings_display_device_itemf");
768 RNA_def_property_ui_text(prop, "Display Device", "Display device name");
769 RNA_def_property_update(prop, NC_WINDOW, NULL);
771 /* ** View Settings ** */
772 srna = RNA_def_struct(brna, "ColorManagedViewSettings", NULL);
773 RNA_def_struct_ui_text(srna, "ColorManagedViewSettings", "Color management settings used for displaying images on the display");
775 prop = RNA_def_property(srna, "use_global_settings", PROP_BOOLEAN, PROP_NONE);
776 RNA_def_property_boolean_sdna(prop, NULL, "flag", COLORMANAGE_VIEW_USE_GLOBAL);
777 RNA_def_property_ui_text(prop, "Use Global Settings", "Use global display settings instead of per-space setting");
778 RNA_def_property_update(prop, NC_WINDOW, NULL);
780 prop= RNA_def_property(srna, "view_transform", PROP_ENUM, PROP_NONE);
781 RNA_def_property_enum_items(prop, view_transform_items);
782 RNA_def_property_enum_funcs(prop, "rna_ColorManagedViewSettings_view_transform_get",
783 "rna_ColorManagedViewSettings_view_transform_set",
784 "rna_ColorManagedViewSettings_view_transform_itemf");
785 RNA_def_property_ui_text(prop, "View Transform", "View transform used for this image editor");
786 RNA_def_property_update(prop, NC_WINDOW, NULL);
788 prop = RNA_def_property(srna, "exposure", PROP_FLOAT, PROP_FACTOR);
789 RNA_def_property_float_sdna(prop, NULL, "exposure");
790 RNA_def_property_range(prop, -10.0f, 10.0f);
791 RNA_def_property_float_default(prop, 0.0f);
792 RNA_def_property_ui_text(prop, "Exposure", "Exposure (stops) applied on displaying image buffers");
793 RNA_def_property_update(prop, NC_WINDOW, NULL);
795 prop = RNA_def_property(srna, "gamma", PROP_FLOAT, PROP_FACTOR);
796 RNA_def_property_float_sdna(prop, NULL, "gamma");
797 RNA_def_property_float_default(prop, 1.0f);
798 RNA_def_property_range(prop, 0.0f, 5.0f);
799 RNA_def_property_ui_text(prop, "Gamma", "Amount f gamma modification for displaying image buffers");
800 RNA_def_property_update(prop, NC_WINDOW, NULL);
803 void RNA_def_color(BlenderRNA *brna)
805 rna_def_curvemappoint(brna);
806 rna_def_curvemap(brna);
807 rna_def_curvemapping(brna);
808 rna_def_color_ramp_element(brna);
809 rna_def_color_ramp(brna);
810 rna_def_histogram(brna);
811 rna_def_scopes(brna);
812 rna_def_colormanage(brna);