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"
48 #include "DNA_sequence_types.h"
50 #include "MEM_guardedalloc.h"
52 #include "BKE_colortools.h"
53 #include "BKE_depsgraph.h"
54 #include "BKE_image.h"
55 #include "BKE_movieclip.h"
57 #include "BKE_sequencer.h"
58 #include "BKE_texture.h"
60 # include "BKE_linestyle.h"
65 #include "IMB_colormanagement.h"
67 static int rna_CurveMapping_curves_length(PointerRNA *ptr)
69 CurveMapping *cumap = (CurveMapping *)ptr->data;
72 for (len = 0; len < CM_TOT; len++)
73 if (!cumap->cm[len].curve)
79 static void rna_CurveMapping_curves_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
81 CurveMapping *cumap = (CurveMapping *)ptr->data;
83 rna_iterator_array_begin(iter, cumap->cm, sizeof(CurveMap), rna_CurveMapping_curves_length(ptr), 0, NULL);
86 static void rna_CurveMapping_clip_set(PointerRNA *ptr, int value)
88 CurveMapping *cumap = (CurveMapping *)ptr->data;
90 if (value) cumap->flag |= CUMA_DO_CLIP;
91 else cumap->flag &= ~CUMA_DO_CLIP;
93 curvemapping_changed(cumap, FALSE);
96 static void rna_CurveMapping_black_level_set(PointerRNA *ptr, const float *values)
98 CurveMapping *cumap = (CurveMapping *)ptr->data;
99 cumap->black[0] = values[0];
100 cumap->black[1] = values[1];
101 cumap->black[2] = values[2];
102 curvemapping_set_black_white(cumap, NULL, NULL);
105 static void rna_CurveMapping_white_level_set(PointerRNA *ptr, const float *values)
107 CurveMapping *cumap = (CurveMapping *)ptr->data;
108 cumap->white[0] = values[0];
109 cumap->white[1] = values[1];
110 cumap->white[2] = values[2];
111 curvemapping_set_black_white(cumap, NULL, NULL);
114 static void rna_CurveMapping_clipminx_range(PointerRNA *ptr, float *min, float *max, float *softmin, float *softmax)
116 CurveMapping *cumap = (CurveMapping *)ptr->data;
119 *max = cumap->clipr.xmax;
122 static void rna_CurveMapping_clipminy_range(PointerRNA *ptr, float *min, float *max, float *softmin, float *softmax)
124 CurveMapping *cumap = (CurveMapping *)ptr->data;
127 *max = cumap->clipr.ymax;
130 static void rna_CurveMapping_clipmaxx_range(PointerRNA *ptr, float *min, float *max, float *softmin, float *softmax)
132 CurveMapping *cumap = (CurveMapping *)ptr->data;
134 *min = cumap->clipr.xmin;
138 static void rna_CurveMapping_clipmaxy_range(PointerRNA *ptr, float *min, float *max, float *softmin, float *softmax)
140 CurveMapping *cumap = (CurveMapping *)ptr->data;
142 *min = cumap->clipr.ymin;
147 static char *rna_ColorRamp_path(PointerRNA *ptr)
151 /* handle the cases where a single datablock may have 2 ramp types */
153 ID *id = ptr->id.data;
155 switch (GS(id->name)) {
156 case ID_MA: /* material has 2 cases - diffuse and specular */
158 Material *ma = (Material *)id;
160 if (ptr->data == ma->ramp_col)
161 path = BLI_strdup("diffuse_ramp");
162 else if (ptr->data == ma->ramp_spec)
163 path = BLI_strdup("specular_ramp");
169 bNodeTree *ntree = (bNodeTree *)id;
174 for (node = ntree->nodes.first; node; node = node->next) {
175 if (ELEM3(node->type, SH_NODE_VALTORGB, CMP_NODE_VALTORGB, TEX_NODE_VALTORGB)) {
176 if (node->storage == ptr->data) {
177 /* all node color ramp properties called 'color_ramp'
178 * prepend path from ID to the node
180 RNA_pointer_create(id, &RNA_Node, node, &node_ptr);
181 node_path = RNA_path_from_ID_to_struct(&node_ptr);
182 path = BLI_sprintfN("%s.color_ramp", node_path);
183 MEM_freeN(node_path);
191 /* everything else just uses 'color_ramp' */
192 path = BLI_strdup("color_ramp");
195 #ifdef WITH_FREESTYLE
198 char *path = FRS_path_from_ID_to_color_ramp((FreestyleLineStyle *)id, (ColorBand *)ptr->data);
207 /* everything else just uses 'color_ramp' */
208 path = BLI_strdup("color_ramp");
214 static char *rna_ColorRampElement_path(PointerRNA *ptr)
221 /* helper macro for use here to try and get the path
222 * - this calls the standard code for getting a path to a texture...
225 #define COLRAMP_GETPATH \
227 prop = RNA_struct_find_property(&ramp_ptr, "elements"); \
229 index = RNA_property_collection_lookup_index(&ramp_ptr, prop, ptr); \
231 char *texture_path = rna_ColorRamp_path(&ramp_ptr); \
232 path = BLI_sprintfN("%s.elements[%d]", texture_path, index); \
233 MEM_freeN(texture_path); \
238 /* determine the path from the ID-block to the ramp */
239 /* FIXME: this is a very slow way to do it, but it will have to suffice... */
241 ID *id = ptr->id.data;
243 switch (GS(id->name)) {
244 case ID_MA: /* 2 cases for material - diffuse and spec */
246 Material *ma = (Material *)id;
248 /* try diffuse first */
250 RNA_pointer_create(id, &RNA_ColorRamp, ma->ramp_col, &ramp_ptr);
253 /* try specular if not diffuse */
254 if (!path && ma->ramp_spec) {
255 RNA_pointer_create(id, &RNA_ColorRamp, ma->ramp_spec, &ramp_ptr);
263 bNodeTree *ntree = (bNodeTree *)id;
266 for (node = ntree->nodes.first; node; node = node->next) {
267 if (ELEM3(node->type, SH_NODE_VALTORGB, CMP_NODE_VALTORGB, TEX_NODE_VALTORGB)) {
268 RNA_pointer_create(id, &RNA_ColorRamp, node->storage, &ramp_ptr);
275 #ifdef WITH_FREESTYLE
281 FRS_list_modifier_color_ramps((FreestyleLineStyle *)id, &listbase);
282 for (link = (LinkData *)listbase.first; link; link = link->next) {
283 RNA_pointer_create(id, &RNA_ColorRamp, link->data, &ramp_ptr);
286 BLI_freelistN(&listbase);
291 default: /* everything else should have a "color_ramp" property */
293 /* create pointer to the ID block, and try to resolve "color_ramp" pointer */
294 RNA_id_pointer_create(id, &ramp_ptr);
295 if (RNA_path_resolve(&ramp_ptr, "color_ramp", &ramp_ptr, &prop)) {
302 /* cleanup the macro we defined */
303 #undef COLRAMP_GETPATH
308 static void rna_ColorRamp_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
311 ID *id = ptr->id.data;
313 switch (GS(id->name)) {
316 Material *ma = ptr->id.data;
318 DAG_id_tag_update(&ma->id, 0);
319 WM_main_add_notifier(NC_MATERIAL | ND_SHADING_DRAW, ma);
324 bNodeTree *ntree = (bNodeTree *)id;
327 for (node = ntree->nodes.first; node; node = node->next) {
328 if (ELEM3(node->type, SH_NODE_VALTORGB, CMP_NODE_VALTORGB, TEX_NODE_VALTORGB)) {
329 ED_node_generic_update(bmain, ntree, node);
336 Tex *tex = ptr->id.data;
338 DAG_id_tag_update(&tex->id, 0);
339 WM_main_add_notifier(NC_TEXTURE, tex);
342 #ifdef WITH_FREESTYLE
345 FreestyleLineStyle *linestyle= ptr->id.data;
347 WM_main_add_notifier(NC_LINESTYLE, linestyle);
357 static void rna_ColorRamp_eval(struct ColorBand *coba, float position, float color[4])
359 do_colorband(coba, position, color);
362 static CBData *rna_ColorRampElement_new(struct ColorBand *coba, ReportList *reports, float position)
364 CBData *element = colorband_element_add(coba, position);
367 BKE_reportf(reports, RPT_ERROR, "Unable to add element to colorband (limit %d)", MAXCOLORBAND);
372 static void rna_ColorRampElement_remove(struct ColorBand *coba, ReportList *reports, PointerRNA *element_ptr)
374 CBData *element = element_ptr->data;
375 int index = (int)(element - coba->data);
376 if (colorband_element_remove(coba, index) == FALSE) {
377 BKE_report(reports, RPT_ERROR, "Element not found in element collection or last element");
381 RNA_POINTER_INVALIDATE(element_ptr);
384 void rna_CurveMap_remove_point(CurveMap *cuma, ReportList *reports, PointerRNA *point_ptr)
386 CurveMapPoint *point = point_ptr->data;
387 if (curvemap_remove_point(cuma, point) == FALSE) {
388 BKE_report(reports, RPT_ERROR, "Unable to remove curve point");
392 RNA_POINTER_INVALIDATE(point_ptr);
395 static void rna_Scopes_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
397 Scopes *s = (Scopes *)ptr->data;
401 static int rna_ColorManagedDisplaySettings_display_device_get(struct PointerRNA *ptr)
403 ColorManagedDisplaySettings *display = (ColorManagedDisplaySettings *) ptr->data;
405 return IMB_colormanagement_display_get_named_index(display->display_device);
408 static void rna_ColorManagedDisplaySettings_display_device_set(struct PointerRNA *ptr, int value)
410 ColorManagedDisplaySettings *display = (ColorManagedDisplaySettings *) ptr->data;
411 const char *name = IMB_colormanagement_display_get_indexed_name(value);
414 BLI_strncpy(display->display_device, name, sizeof(display->display_device));
418 static EnumPropertyItem *rna_ColorManagedDisplaySettings_display_device_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *UNUSED(prop), int *free)
420 EnumPropertyItem *items = NULL;
423 IMB_colormanagement_display_items_add(&items, &totitem);
424 RNA_enum_item_end(&items, &totitem);
431 static void rna_ColorManagedDisplaySettings_display_device_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
433 ID *id = ptr->id.data;
438 if (GS(id->name) == ID_SCE) {
439 Scene *scene = (Scene *) id;
441 IMB_colormanagement_validate_settings(&scene->display_settings, &scene->view_settings);
443 WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, NULL);
447 static int rna_ColorManagedViewSettings_view_transform_get(PointerRNA *ptr)
449 ColorManagedViewSettings *view = (ColorManagedViewSettings *) ptr->data;
451 return IMB_colormanagement_view_get_named_index(view->view_transform);
454 static void rna_ColorManagedViewSettings_view_transform_set(PointerRNA *ptr, int value)
456 ColorManagedViewSettings *view = (ColorManagedViewSettings *) ptr->data;
458 const char *name = IMB_colormanagement_view_get_indexed_name(value);
461 BLI_strncpy(view->view_transform, name, sizeof(view->view_transform));
465 static EnumPropertyItem* rna_ColorManagedViewSettings_view_transform_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *UNUSED(prop), int *free)
467 Scene *scene = CTX_data_scene(C);
468 EnumPropertyItem *items = NULL;
469 ColorManagedDisplaySettings *display_settings = &scene->display_settings;
472 IMB_colormanagement_view_items_add(&items, &totitem, display_settings->display_device);
473 RNA_enum_item_end(&items, &totitem);
479 static void rna_ColorManagedViewSettings_use_curves_set(PointerRNA *ptr, int value)
481 ColorManagedViewSettings *view_settings = (ColorManagedViewSettings *) ptr->data;
484 view_settings->flag |= COLORMANAGE_VIEW_USE_CURVES;
486 if (view_settings->curve_mapping == NULL) {
487 view_settings->curve_mapping = curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f);
491 view_settings->flag &= ~COLORMANAGE_VIEW_USE_CURVES;
495 static int rna_ColorManagedColorspaceSettings_colorspace_get(struct PointerRNA *ptr)
497 ColorManagedColorspaceSettings *colorspace = (ColorManagedColorspaceSettings *) ptr->data;
499 return IMB_colormanagement_colorspace_get_named_index(colorspace->name);
502 static void rna_ColorManagedColorspaceSettings_colorspace_set(struct PointerRNA *ptr, int value)
504 ColorManagedColorspaceSettings *colorspace = (ColorManagedColorspaceSettings *) ptr->data;
505 const char *name = IMB_colormanagement_colorspace_get_indexed_name(value);
508 BLI_strncpy(colorspace->name, name, sizeof(colorspace->name));
512 static EnumPropertyItem *rna_ColorManagedColorspaceSettings_colorspace_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *UNUSED(prop), int *free)
514 EnumPropertyItem *items = NULL;
517 IMB_colormanagement_colorspace_items_add(&items, &totitem);
518 RNA_enum_item_end(&items, &totitem);
525 static void rna_ColorManagedColorspaceSettings_reload_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
527 ID *id = ptr->id.data;
529 if (GS(id->name) == ID_IM) {
530 Image *ima = (Image *) id;
532 DAG_id_tag_update(&ima->id, 0);
534 BKE_image_signal(ima, NULL, IMA_SIGNAL_COLORMANAGE);
536 WM_main_add_notifier(NC_IMAGE | ND_DISPLAY, &ima->id);
537 WM_main_add_notifier(NC_IMAGE | NA_EDITED, &ima->id);
539 else if (GS(id->name) == ID_MC) {
540 MovieClip *clip = (MovieClip *) id;
542 BKE_movieclip_reload(clip);
544 /* all sequencers for now, we don't know which scenes are using this clip as a strip */
545 BKE_sequencer_cache_cleanup();
546 BKE_sequencer_preprocessed_cache_cleanup();
548 WM_main_add_notifier(NC_MOVIECLIP | ND_DISPLAY, &clip->id);
549 WM_main_add_notifier(NC_MOVIECLIP | NA_EDITED, &clip->id);
551 else if (GS(id->name) == ID_SCE) {
552 Scene *scene = (Scene *) id;
555 ColorManagedColorspaceSettings *colorspace_settings = (ColorManagedColorspaceSettings *) ptr->data;
557 int seq_found = FALSE;
559 if (&scene->sequencer_colorspace_settings != colorspace_settings) {
560 SEQ_BEGIN(scene->ed, seq);
562 if (seq->strip && &seq->strip->colorspace_settings == colorspace_settings) {
571 BKE_sequence_invalidate_cache(scene, seq);
572 BKE_sequencer_preprocessed_cache_cleanup_sequence(seq);
575 BKE_sequencer_cache_cleanup();
576 BKE_sequencer_preprocessed_cache_cleanup();
579 WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, NULL);
584 static void rna_ColorManagement_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
586 ID *id = ptr->id.data;
591 if (GS(id->name) == ID_SCE) {
592 WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, NULL);
596 /* this function only exists because #curvemap_evaluateF uses a 'const' qualifier */
597 static float rna_CurveMap_evaluateF(struct CurveMap *cuma, float value)
599 return curvemap_evaluateF(cuma, value);
604 static void rna_def_curvemappoint(BlenderRNA *brna)
608 static EnumPropertyItem prop_handle_type_items[] = {
609 {0, "AUTO", 0, "Auto Handle", ""},
610 {CUMA_VECTOR, "VECTOR", 0, "Vector Handle", ""},
611 {0, NULL, 0, NULL, NULL}
614 srna = RNA_def_struct(brna, "CurveMapPoint", NULL);
615 RNA_def_struct_ui_text(srna, "CurveMapPoint", "Point of a curve used for a curve mapping");
617 prop = RNA_def_property(srna, "location", PROP_FLOAT, PROP_XYZ);
618 RNA_def_property_float_sdna(prop, NULL, "x");
619 RNA_def_property_array(prop, 2);
620 RNA_def_property_ui_text(prop, "Location", "X/Y coordinates of the curve point");
622 prop = RNA_def_property(srna, "handle_type", PROP_ENUM, PROP_NONE);
623 RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
624 RNA_def_property_enum_items(prop, prop_handle_type_items);
625 RNA_def_property_ui_text(prop, "Handle Type", "Curve interpolation at this point: Bezier or vector");
627 prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
628 RNA_def_property_boolean_sdna(prop, NULL, "flag", CUMA_SELECT);
629 RNA_def_property_ui_text(prop, "Select", "Selection state of the curve point");
632 static void rna_def_curvemap_points_api(BlenderRNA *brna, PropertyRNA *cprop)
638 RNA_def_property_srna(cprop, "CurveMapPoints");
639 srna = RNA_def_struct(brna, "CurveMapPoints", NULL);
640 RNA_def_struct_sdna(srna, "CurveMap");
641 RNA_def_struct_ui_text(srna, "Curve Map Point", "Collection of Curve Map Points");
643 func = RNA_def_function(srna, "new", "curvemap_insert");
644 RNA_def_function_ui_description(func, "Add point to CurveMap");
645 parm = RNA_def_float(func, "position", 0.0f, -FLT_MAX, FLT_MAX, "Position", "Position to add point", -FLT_MAX, FLT_MAX);
646 RNA_def_property_flag(parm, PROP_REQUIRED);
647 parm = RNA_def_float(func, "value", 0.0f, -FLT_MAX, FLT_MAX, "Value", "Value of point", -FLT_MAX, FLT_MAX);
648 RNA_def_property_flag(parm, PROP_REQUIRED);
649 parm = RNA_def_pointer(func, "point", "CurveMapPoint", "", "New point");
650 RNA_def_function_return(func, parm);
652 func = RNA_def_function(srna, "remove", "rna_CurveMap_remove_point");
653 RNA_def_function_flag(func, FUNC_USE_REPORTS);
654 RNA_def_function_ui_description(func, "Delete point from CurveMap");
655 parm = RNA_def_pointer(func, "point", "CurveMapPoint", "", "PointElement to remove");
656 RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR);
657 RNA_def_property_clear_flag(parm, PROP_THICK_WRAP);
660 static void rna_def_curvemap(BlenderRNA *brna)
663 PropertyRNA *prop, *parm;
666 static EnumPropertyItem prop_extend_items[] = {
667 {0, "HORIZONTAL", 0, "Horizontal", ""},
668 {CUMA_EXTEND_EXTRAPOLATE, "EXTRAPOLATED", 0, "Extrapolated", ""},
669 {0, NULL, 0, NULL, NULL}
672 srna = RNA_def_struct(brna, "CurveMap", NULL);
673 RNA_def_struct_ui_text(srna, "CurveMap", "Curve in a curve mapping");
675 prop = RNA_def_property(srna, "extend", PROP_ENUM, PROP_NONE);
676 RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
677 RNA_def_property_enum_items(prop, prop_extend_items);
678 RNA_def_property_ui_text(prop, "Extend", "Extrapolate the curve or extend it horizontally");
680 prop = RNA_def_property(srna, "points", PROP_COLLECTION, PROP_NONE);
681 RNA_def_property_collection_sdna(prop, NULL, "curve", "totpoint");
682 RNA_def_property_struct_type(prop, "CurveMapPoint");
683 RNA_def_property_ui_text(prop, "Points", "");
684 rna_def_curvemap_points_api(brna, prop);
686 func = RNA_def_function(srna, "evaluate", "rna_CurveMap_evaluateF");
687 RNA_def_function_ui_description(func, "Evaluate curve at given location");
688 parm = RNA_def_float(func, "position", 0.0f, -FLT_MAX, FLT_MAX, "Position", "Position to evaluate curve at", -FLT_MAX, FLT_MAX);
689 RNA_def_property_flag(parm, PROP_REQUIRED);
690 parm = RNA_def_float(func, "value", 0.0f, -FLT_MAX, FLT_MAX, "Value", "Value of curve at given location", -FLT_MAX, FLT_MAX);
691 RNA_def_function_return(func, parm);
694 static void rna_def_curvemapping(BlenderRNA *brna)
700 srna = RNA_def_struct(brna, "CurveMapping", NULL);
701 RNA_def_struct_ui_text(srna, "CurveMapping",
702 "Curve mapping to map color, vector and scalar values to other values using "
703 "a user defined curve");
705 prop = RNA_def_property(srna, "use_clip", PROP_BOOLEAN, PROP_NONE);
706 RNA_def_property_boolean_sdna(prop, NULL, "flag", CUMA_DO_CLIP);
707 RNA_def_property_ui_text(prop, "Clip", "Force the curve view to fit a defined boundary");
708 RNA_def_property_boolean_funcs(prop, NULL, "rna_CurveMapping_clip_set");
710 prop = RNA_def_property(srna, "clip_min_x", PROP_FLOAT, PROP_NONE);
711 RNA_def_property_float_sdna(prop, NULL, "clipr.xmin");
712 RNA_def_property_range(prop, -100.0f, 100.0f);
713 RNA_def_property_ui_text(prop, "Clip Min X", "");
714 RNA_def_property_float_funcs(prop, NULL, NULL, "rna_CurveMapping_clipminx_range");
716 prop = RNA_def_property(srna, "clip_min_y", PROP_FLOAT, PROP_NONE);
717 RNA_def_property_float_sdna(prop, NULL, "clipr.ymin");
718 RNA_def_property_range(prop, -100.0f, 100.0f);
719 RNA_def_property_ui_text(prop, "Clip Min Y", "");
720 RNA_def_property_float_funcs(prop, NULL, NULL, "rna_CurveMapping_clipminy_range");
722 prop = RNA_def_property(srna, "clip_max_x", PROP_FLOAT, PROP_NONE);
723 RNA_def_property_float_sdna(prop, NULL, "clipr.xmax");
724 RNA_def_property_range(prop, -100.0f, 100.0f);
725 RNA_def_property_ui_text(prop, "Clip Max X", "");
726 RNA_def_property_float_funcs(prop, NULL, NULL, "rna_CurveMapping_clipmaxx_range");
728 prop = RNA_def_property(srna, "clip_max_y", PROP_FLOAT, PROP_NONE);
729 RNA_def_property_float_sdna(prop, NULL, "clipr.ymax");
730 RNA_def_property_range(prop, -100.0f, 100.0f);
731 RNA_def_property_ui_text(prop, "Clip Max Y", "");
732 RNA_def_property_float_funcs(prop, NULL, NULL, "rna_CurveMapping_clipmaxy_range");
734 prop = RNA_def_property(srna, "curves", PROP_COLLECTION, PROP_NONE);
735 RNA_def_property_collection_funcs(prop, "rna_CurveMapping_curves_begin", "rna_iterator_array_next",
736 "rna_iterator_array_end", "rna_iterator_array_get",
737 "rna_CurveMapping_curves_length", NULL, NULL, NULL);
738 RNA_def_property_struct_type(prop, "CurveMap");
739 RNA_def_property_ui_text(prop, "Curves", "");
741 prop = RNA_def_property(srna, "black_level", PROP_FLOAT, PROP_COLOR);
742 RNA_def_property_float_sdna(prop, NULL, "black");
743 RNA_def_property_range(prop, -1000.0f, 1000.0f);
744 RNA_def_property_ui_text(prop, "Black Level", "For RGB curves, the color that black is mapped to");
745 RNA_def_property_float_funcs(prop, NULL, "rna_CurveMapping_black_level_set", NULL);
747 prop = RNA_def_property(srna, "white_level", PROP_FLOAT, PROP_COLOR);
748 RNA_def_property_float_sdna(prop, NULL, "white");
749 RNA_def_property_range(prop, -1000.0f, 1000.0f);
750 RNA_def_property_ui_text(prop, "White Level", "For RGB curves, the color that white is mapped to");
751 RNA_def_property_float_funcs(prop, NULL, "rna_CurveMapping_white_level_set", NULL);
753 func = RNA_def_function(srna, "update", "curvemapping_changed_all");
754 RNA_def_function_ui_description(func, "Update curve mapping after making changes");
757 static void rna_def_color_ramp_element(BlenderRNA *brna)
762 srna = RNA_def_struct(brna, "ColorRampElement", NULL);
763 RNA_def_struct_sdna(srna, "CBData");
764 RNA_def_struct_path_func(srna, "rna_ColorRampElement_path");
765 RNA_def_struct_ui_text(srna, "Color Ramp Element", "Element defining a color at a position in the color ramp");
767 prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR);
768 RNA_def_property_float_sdna(prop, NULL, "r");
769 RNA_def_property_array(prop, 4);
770 RNA_def_property_ui_text(prop, "Color", "Set color of selected color stop");
771 RNA_def_property_update(prop, 0, "rna_ColorRamp_update");
773 prop = RNA_def_property(srna, "position", PROP_FLOAT, PROP_NONE);
774 RNA_def_property_float_sdna(prop, NULL, "pos");
775 RNA_def_property_range(prop, 0, 1);
776 RNA_def_property_ui_text(prop, "Position", "Set position of selected color stop");
777 RNA_def_property_update(prop, 0, "rna_ColorRamp_update");
780 static void rna_def_color_ramp_element_api(BlenderRNA *brna, PropertyRNA *cprop)
786 RNA_def_property_srna(cprop, "ColorRampElements");
787 srna = RNA_def_struct(brna, "ColorRampElements", NULL);
788 RNA_def_struct_sdna(srna, "ColorBand");
789 RNA_def_struct_path_func(srna, "rna_ColorRampElement_path");
790 RNA_def_struct_ui_text(srna, "Color Ramp Elements", "Collection of Color Ramp Elements");
792 /* TODO, make these functions generic in texture.c */
793 func = RNA_def_function(srna, "new", "rna_ColorRampElement_new");
794 RNA_def_function_ui_description(func, "Add element to ColorRamp");
795 RNA_def_function_flag(func, FUNC_USE_REPORTS);
796 parm = RNA_def_float(func, "position", 0.0f, 0.0f, 1.0f, "Position", "Position to add element", 0.0f, 1.0f);
797 RNA_def_property_flag(parm, PROP_REQUIRED);
799 parm = RNA_def_pointer(func, "element", "ColorRampElement", "", "New element");
800 RNA_def_function_return(func, parm);
802 func = RNA_def_function(srna, "remove", "rna_ColorRampElement_remove");
803 RNA_def_function_ui_description(func, "Delete element from ColorRamp");
804 RNA_def_function_flag(func, FUNC_USE_REPORTS);
805 parm = RNA_def_pointer(func, "element", "ColorRampElement", "", "Element to remove");
806 RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR);
807 RNA_def_property_clear_flag(parm, PROP_THICK_WRAP);
810 static void rna_def_color_ramp(BlenderRNA *brna)
816 static EnumPropertyItem prop_interpolation_items[] = {
817 {1, "EASE", 0, "Ease", ""},
818 {3, "CARDINAL", 0, "Cardinal", ""},
819 {0, "LINEAR", 0, "Linear", ""},
820 {2, "B_SPLINE", 0, "B-Spline", ""},
821 {4, "CONSTANT", 0, "Constant", ""},
822 {0, NULL, 0, NULL, NULL}
825 srna = RNA_def_struct(brna, "ColorRamp", NULL);
826 RNA_def_struct_sdna(srna, "ColorBand");
827 RNA_def_struct_path_func(srna, "rna_ColorRamp_path");
828 RNA_def_struct_ui_text(srna, "Color Ramp", "Color ramp mapping a scalar value to a color");
830 prop = RNA_def_property(srna, "elements", PROP_COLLECTION, PROP_COLOR);
831 RNA_def_property_collection_sdna(prop, NULL, "data", "tot");
832 RNA_def_property_struct_type(prop, "ColorRampElement");
833 RNA_def_property_ui_text(prop, "Elements", "");
834 RNA_def_property_update(prop, 0, "rna_ColorRamp_update");
835 rna_def_color_ramp_element_api(brna, prop);
837 prop = RNA_def_property(srna, "interpolation", PROP_ENUM, PROP_NONE);
838 RNA_def_property_enum_sdna(prop, NULL, "ipotype");
839 RNA_def_property_enum_items(prop, prop_interpolation_items);
840 RNA_def_property_ui_text(prop, "Interpolation", "");
841 RNA_def_property_update(prop, 0, "rna_ColorRamp_update");
843 #if 0 /* use len(elements) */
844 prop = RNA_def_property(srna, "total", PROP_INT, PROP_NONE);
845 RNA_def_property_int_sdna(prop, NULL, "tot");
846 /* needs a function to do the right thing when adding elements like colorband_add_cb() */
847 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
848 RNA_def_property_range(prop, 0, 31); /* MAXCOLORBAND = 32 */
849 RNA_def_property_ui_text(prop, "Total", "Total number of elements");
850 RNA_def_property_update(prop, 0, "rna_ColorRamp_update");
853 func = RNA_def_function(srna, "evaluate", "rna_ColorRamp_eval");
854 RNA_def_function_ui_description(func, "Evaluate ColorRamp");
855 prop = RNA_def_float(func, "position", 1.0f, 0.0f, 1.0f, "Position", "Evaluate ColorRamp at position", 0.0f, 1.0f);
856 RNA_def_property_flag(prop, PROP_REQUIRED);
858 prop = RNA_def_float_color(func, "color", 4, NULL, -FLT_MAX, FLT_MAX, "Color", "Color at given position",
860 RNA_def_property_flag(prop, PROP_THICK_WRAP);
861 RNA_def_function_output(func, prop);
864 static void rna_def_histogram(BlenderRNA *brna)
869 static EnumPropertyItem prop_mode_items[] = {
870 {HISTO_MODE_LUMA, "LUMA", 0, "Luma", "Luma"},
871 {HISTO_MODE_RGB, "RGB", 0, "RGB", "Red Green Blue"},
872 {HISTO_MODE_R, "R", 0, "R", "Red"},
873 {HISTO_MODE_G, "G", 0, "G", "Green"},
874 {HISTO_MODE_B, "B", 0, "B", "Blue"},
875 {HISTO_MODE_ALPHA, "A", 0, "A", "Alpha"},
876 {0, NULL, 0, NULL, NULL}
879 srna = RNA_def_struct(brna, "Histogram", NULL);
880 RNA_def_struct_ui_text(srna, "Histogram", "Statistical view of the levels of color in an image");
882 prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
883 RNA_def_property_enum_sdna(prop, NULL, "mode");
884 RNA_def_property_enum_items(prop, prop_mode_items);
885 RNA_def_property_ui_text(prop, "Mode", "Channels to display when drawing the histogram");
887 prop = RNA_def_property(srna, "show_line", PROP_BOOLEAN, PROP_NONE);
888 RNA_def_property_boolean_sdna(prop, NULL, "flag", HISTO_FLAG_LINE);
889 RNA_def_property_ui_text(prop, "Show Line", "Display lines rather then filled shapes");
890 RNA_def_property_ui_icon(prop, ICON_IPO, 0);
893 static void rna_def_scopes(BlenderRNA *brna)
898 static EnumPropertyItem prop_wavefrm_mode_items[] = {
899 {SCOPES_WAVEFRM_LUMA, "LUMA", ICON_COLOR, "Luma", ""},
900 {SCOPES_WAVEFRM_RGB, "RGB", ICON_COLOR, "Red Green Blue", ""},
901 {SCOPES_WAVEFRM_YCC_601, "YCBCR601", ICON_COLOR, "YCbCr (ITU 601)", ""},
902 {SCOPES_WAVEFRM_YCC_709, "YCBCR709", ICON_COLOR, "YCbCr (ITU 709)", ""},
903 {SCOPES_WAVEFRM_YCC_JPEG, "YCBCRJPG", ICON_COLOR, "YCbCr (Jpeg)", ""},
904 {0, NULL, 0, NULL, NULL}
907 srna = RNA_def_struct(brna, "Scopes", NULL);
908 RNA_def_struct_ui_text(srna, "Scopes", "Scopes for statistical view of an image");
910 prop = RNA_def_property(srna, "use_full_resolution", PROP_BOOLEAN, PROP_NONE);
911 RNA_def_property_boolean_sdna(prop, "Scopes", "sample_full", 1);
912 RNA_def_property_ui_text(prop, "Full Sample", "Sample every pixel of the image");
913 RNA_def_property_update(prop, 0, "rna_Scopes_update");
915 prop = RNA_def_property(srna, "accuracy", PROP_FLOAT, PROP_PERCENTAGE);
916 RNA_def_property_float_sdna(prop, "Scopes", "accuracy");
917 RNA_def_property_range(prop, 0.0, 100.0);
918 RNA_def_property_ui_range(prop, 0.0, 100.0, 10, 1);
919 RNA_def_property_ui_text(prop, "Accuracy", "Proportion of original image source pixel lines to sample");
920 RNA_def_property_update(prop, 0, "rna_Scopes_update");
922 prop = RNA_def_property(srna, "histogram", PROP_POINTER, PROP_NONE);
923 RNA_def_property_pointer_sdna(prop, "Scopes", "hist");
924 RNA_def_property_struct_type(prop, "Histogram");
925 RNA_def_property_ui_text(prop, "Histogram", "Histogram for viewing image statistics");
927 prop = RNA_def_property(srna, "waveform_mode", PROP_ENUM, PROP_NONE);
928 RNA_def_property_enum_sdna(prop, "Scopes", "wavefrm_mode");
929 RNA_def_property_enum_items(prop, prop_wavefrm_mode_items);
930 RNA_def_property_ui_text(prop, "Waveform Mode", "");
931 RNA_def_property_update(prop, 0, "rna_Scopes_update");
933 prop = RNA_def_property(srna, "waveform_alpha", PROP_FLOAT, PROP_FACTOR);
934 RNA_def_property_float_sdna(prop, "Scopes", "wavefrm_alpha");
935 RNA_def_property_range(prop, 0, 1);
936 RNA_def_property_ui_text(prop, "Waveform Opacity", "Opacity of the points");
938 prop = RNA_def_property(srna, "vectorscope_alpha", PROP_FLOAT, PROP_FACTOR);
939 RNA_def_property_float_sdna(prop, "Scopes", "vecscope_alpha");
940 RNA_def_property_range(prop, 0, 1);
941 RNA_def_property_ui_text(prop, "Vectorscope Opacity", "Opacity of the points");
944 static void rna_def_colormanage(BlenderRNA *brna)
949 static EnumPropertyItem display_device_items[] = {
950 {0, "DEFAULT", 0, "Default", ""},
951 {0, NULL, 0, NULL, NULL}
954 static EnumPropertyItem view_transform_items[] = {
955 {0, "NONE", 0, "None", "Do not perform any color transform on display, use old non-color managed technique for display"},
956 {0, NULL, 0, NULL, NULL}
959 static EnumPropertyItem color_space_items[] = {
960 {0, "NONE", 0, "None", "Do not perform any color transform on load, treat colors as in scene linear space already"},
961 {0, NULL, 0, NULL, NULL}
964 /* ** Display Settings ** */
965 srna = RNA_def_struct(brna, "ColorManagedDisplaySettings", NULL);
966 RNA_def_struct_ui_text(srna, "ColorManagedDisplaySettings", "Color management specific to display device");
968 prop = RNA_def_property(srna, "display_device", PROP_ENUM, PROP_NONE);
969 RNA_def_property_enum_items(prop, display_device_items);
970 RNA_def_property_enum_funcs(prop, "rna_ColorManagedDisplaySettings_display_device_get",
971 "rna_ColorManagedDisplaySettings_display_device_set",
972 "rna_ColorManagedDisplaySettings_display_device_itemf");
973 RNA_def_property_ui_text(prop, "Display Device", "Display device name");
974 RNA_def_property_update(prop, NC_WINDOW, "rna_ColorManagedDisplaySettings_display_device_update");
976 /* ** View Settings ** */
977 srna = RNA_def_struct(brna, "ColorManagedViewSettings", NULL);
978 RNA_def_struct_ui_text(srna, "ColorManagedViewSettings", "Color management settings used for displaying images on the display");
980 prop = RNA_def_property(srna, "view_transform", PROP_ENUM, PROP_NONE);
981 RNA_def_property_enum_items(prop, view_transform_items);
982 RNA_def_property_enum_funcs(prop, "rna_ColorManagedViewSettings_view_transform_get",
983 "rna_ColorManagedViewSettings_view_transform_set",
984 "rna_ColorManagedViewSettings_view_transform_itemf");
985 RNA_def_property_ui_text(prop, "View Transform", "View used ");
986 RNA_def_property_update(prop, NC_WINDOW, "rna_ColorManagement_update");
988 prop = RNA_def_property(srna, "exposure", PROP_FLOAT, PROP_FACTOR);
989 RNA_def_property_float_sdna(prop, NULL, "exposure");
990 RNA_def_property_range(prop, -10.0f, 10.0f);
991 RNA_def_property_float_default(prop, 0.0f);
992 RNA_def_property_ui_text(prop, "Exposure", "Exposure (stops) applied before display transform");
993 RNA_def_property_update(prop, NC_WINDOW, "rna_ColorManagement_update");
995 prop = RNA_def_property(srna, "gamma", PROP_FLOAT, PROP_FACTOR);
996 RNA_def_property_float_sdna(prop, NULL, "gamma");
997 RNA_def_property_float_default(prop, 1.0f);
998 RNA_def_property_range(prop, 0.0f, 5.0f);
999 RNA_def_property_ui_text(prop, "Gamma", "Amount of gamma modification applied after display transform");
1000 RNA_def_property_update(prop, NC_WINDOW, "rna_ColorManagement_update");
1002 prop = RNA_def_property(srna, "curve_mapping", PROP_POINTER, PROP_NONE);
1003 RNA_def_property_pointer_sdna(prop, NULL, "curve_mapping");
1004 RNA_def_property_ui_text(prop, "Curve", "Color curve mapping applied before display transform");
1005 RNA_def_property_update(prop, NC_WINDOW, "rna_ColorManagement_update");
1007 prop = RNA_def_property(srna, "use_curve_mapping", PROP_BOOLEAN, PROP_NONE);
1008 RNA_def_property_boolean_sdna(prop, NULL, "flag", COLORMANAGE_VIEW_USE_CURVES);
1009 RNA_def_property_boolean_funcs(prop, NULL, "rna_ColorManagedViewSettings_use_curves_set");
1010 RNA_def_property_ui_text(prop, "Use Curves", "Use RGB curved for pre-display transformation");
1011 RNA_def_property_update(prop, NC_WINDOW, "rna_ColorManagement_update");
1013 /* ** Colorspace ** */
1014 srna = RNA_def_struct(brna, "ColorManagedInputColorspaceSettings", NULL);
1015 RNA_def_struct_ui_text(srna, "ColorManagedInputColorspaceSettings", "Input color space settings");
1017 prop = RNA_def_property(srna, "name", PROP_ENUM, PROP_NONE);
1018 RNA_def_property_enum_items(prop, color_space_items);
1019 RNA_def_property_enum_funcs(prop, "rna_ColorManagedColorspaceSettings_colorspace_get",
1020 "rna_ColorManagedColorspaceSettings_colorspace_set",
1021 "rna_ColorManagedColorspaceSettings_colorspace_itemf");
1022 RNA_def_property_ui_text(prop, "Input Color Space", "Color space of the image or movie on disk");
1023 RNA_def_property_update(prop, NC_WINDOW, "rna_ColorManagedColorspaceSettings_reload_update");
1025 srna = RNA_def_struct(brna, "ColorManagedSequencerColorspaceSettings", NULL);
1026 RNA_def_struct_ui_text(srna, "ColorManagedSequencerColorspaceSettings", "Input color space settings");
1028 prop = RNA_def_property(srna, "name", PROP_ENUM, PROP_NONE);
1029 RNA_def_property_enum_items(prop, color_space_items);
1030 RNA_def_property_enum_funcs(prop, "rna_ColorManagedColorspaceSettings_colorspace_get",
1031 "rna_ColorManagedColorspaceSettings_colorspace_set",
1032 "rna_ColorManagedColorspaceSettings_colorspace_itemf");
1033 RNA_def_property_ui_text(prop, "Color Space", "Color space that the sequencer operates in");
1034 RNA_def_property_update(prop, NC_WINDOW, "rna_ColorManagedColorspaceSettings_reload_update");
1037 void RNA_def_color(BlenderRNA *brna)
1039 rna_def_curvemappoint(brna);
1040 rna_def_curvemap(brna);
1041 rna_def_curvemapping(brna);
1042 rna_def_color_ramp_element(brna);
1043 rna_def_color_ramp(brna);
1044 rna_def_histogram(brna);
1045 rna_def_scopes(brna);
1046 rna_def_colormanage(brna);