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
30 #include "DNA_color_types.h"
31 #include "DNA_texture_types.h"
33 #include "BLI_utildefines.h"
35 #include "RNA_define.h"
36 #include "rna_internal.h"
43 #include "RNA_access.h"
45 #include "DNA_image_types.h"
46 #include "DNA_material_types.h"
47 #include "DNA_movieclip_types.h"
48 #include "DNA_node_types.h"
49 #include "DNA_sequence_types.h"
51 #include "MEM_guardedalloc.h"
53 #include "BKE_colortools.h"
54 #include "BKE_depsgraph.h"
55 #include "BKE_image.h"
56 #include "BKE_movieclip.h"
58 #include "BKE_sequencer.h"
59 #include "BKE_texture.h"
60 #include "BKE_linestyle.h"
64 #include "IMB_colormanagement.h"
66 static int rna_CurveMapping_curves_length(PointerRNA *ptr)
68 CurveMapping *cumap = (CurveMapping *)ptr->data;
71 for (len = 0; len < CM_TOT; len++)
72 if (!cumap->cm[len].curve)
78 static void rna_CurveMapping_curves_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
80 CurveMapping *cumap = (CurveMapping *)ptr->data;
82 rna_iterator_array_begin(iter, cumap->cm, sizeof(CurveMap), rna_CurveMapping_curves_length(ptr), 0, NULL);
85 static void rna_CurveMapping_clip_set(PointerRNA *ptr, int value)
87 CurveMapping *cumap = (CurveMapping *)ptr->data;
89 if (value) cumap->flag |= CUMA_DO_CLIP;
90 else cumap->flag &= ~CUMA_DO_CLIP;
92 curvemapping_changed(cumap, FALSE);
95 static void rna_CurveMapping_black_level_set(PointerRNA *ptr, const float *values)
97 CurveMapping *cumap = (CurveMapping *)ptr->data;
98 cumap->black[0] = values[0];
99 cumap->black[1] = values[1];
100 cumap->black[2] = values[2];
101 curvemapping_set_black_white(cumap, NULL, NULL);
104 static void rna_CurveMapping_white_level_set(PointerRNA *ptr, const float *values)
106 CurveMapping *cumap = (CurveMapping *)ptr->data;
107 cumap->white[0] = values[0];
108 cumap->white[1] = values[1];
109 cumap->white[2] = values[2];
110 curvemapping_set_black_white(cumap, NULL, NULL);
113 static void rna_CurveMapping_clipminx_range(PointerRNA *ptr, float *min, float *max, float *softmin, float *softmax)
115 CurveMapping *cumap = (CurveMapping *)ptr->data;
118 *max = cumap->clipr.xmax;
121 static void rna_CurveMapping_clipminy_range(PointerRNA *ptr, float *min, float *max, float *softmin, float *softmax)
123 CurveMapping *cumap = (CurveMapping *)ptr->data;
126 *max = cumap->clipr.ymax;
129 static void rna_CurveMapping_clipmaxx_range(PointerRNA *ptr, float *min, float *max, float *softmin, float *softmax)
131 CurveMapping *cumap = (CurveMapping *)ptr->data;
133 *min = cumap->clipr.xmin;
137 static void rna_CurveMapping_clipmaxy_range(PointerRNA *ptr, float *min, float *max, float *softmin, float *softmax)
139 CurveMapping *cumap = (CurveMapping *)ptr->data;
141 *min = cumap->clipr.ymin;
146 static char *rna_ColorRamp_path(PointerRNA *ptr)
150 /* handle the cases where a single datablock may have 2 ramp types */
152 ID *id = ptr->id.data;
154 switch (GS(id->name)) {
155 case ID_MA: /* material has 2 cases - diffuse and specular */
157 Material *ma = (Material *)id;
159 if (ptr->data == ma->ramp_col)
160 path = BLI_strdup("diffuse_ramp");
161 else if (ptr->data == ma->ramp_spec)
162 path = BLI_strdup("specular_ramp");
168 bNodeTree *ntree = (bNodeTree *)id;
173 for (node = ntree->nodes.first; node; node = node->next) {
174 if (ELEM3(node->type, SH_NODE_VALTORGB, CMP_NODE_VALTORGB, TEX_NODE_VALTORGB)) {
175 if (node->storage == ptr->data) {
176 /* all node color ramp properties called 'color_ramp'
177 * prepend path from ID to the node
179 RNA_pointer_create(id, &RNA_Node, node, &node_ptr);
180 node_path = RNA_path_from_ID_to_struct(&node_ptr);
181 path = BLI_sprintfN("%s.color_ramp", node_path);
182 MEM_freeN(node_path);
191 char *path = BKE_path_from_ID_to_color_ramp((FreestyleLineStyle *)id, (ColorBand *)ptr->data);
198 /* everything else just uses 'color_ramp' */
199 path = BLI_strdup("color_ramp");
204 /* everything else just uses 'color_ramp' */
205 path = BLI_strdup("color_ramp");
211 static char *rna_ColorRampElement_path(PointerRNA *ptr)
218 /* helper macro for use here to try and get the path
219 * - this calls the standard code for getting a path to a texture...
222 #define COLRAMP_GETPATH \
224 prop = RNA_struct_find_property(&ramp_ptr, "elements"); \
226 index = RNA_property_collection_lookup_index(&ramp_ptr, prop, ptr); \
228 char *texture_path = rna_ColorRamp_path(&ramp_ptr); \
229 path = BLI_sprintfN("%s.elements[%d]", texture_path, index); \
230 MEM_freeN(texture_path); \
235 /* determine the path from the ID-block to the ramp */
236 /* FIXME: this is a very slow way to do it, but it will have to suffice... */
238 ID *id = ptr->id.data;
240 switch (GS(id->name)) {
241 case ID_MA: /* 2 cases for material - diffuse and spec */
243 Material *ma = (Material *)id;
245 /* try diffuse first */
247 RNA_pointer_create(id, &RNA_ColorRamp, ma->ramp_col, &ramp_ptr);
250 /* try specular if not diffuse */
251 if (!path && ma->ramp_spec) {
252 RNA_pointer_create(id, &RNA_ColorRamp, ma->ramp_spec, &ramp_ptr);
259 bNodeTree *ntree = (bNodeTree *)id;
262 for (node = ntree->nodes.first; node; node = node->next) {
263 if (ELEM3(node->type, SH_NODE_VALTORGB, CMP_NODE_VALTORGB, TEX_NODE_VALTORGB)) {
264 RNA_pointer_create(id, &RNA_ColorRamp, node->storage, &ramp_ptr);
275 BKE_list_modifier_color_ramps((FreestyleLineStyle *)id, &listbase);
276 for (link = (LinkData *)listbase.first; link; link = link->next) {
277 RNA_pointer_create(id, &RNA_ColorRamp, link->data, &ramp_ptr);
280 BLI_freelistN(&listbase);
284 default: /* everything else should have a "color_ramp" property */
286 /* create pointer to the ID block, and try to resolve "color_ramp" pointer */
287 RNA_id_pointer_create(id, &ramp_ptr);
288 if (RNA_path_resolve(&ramp_ptr, "color_ramp", &ramp_ptr, &prop)) {
296 /* cleanup the macro we defined */
297 #undef COLRAMP_GETPATH
302 static void rna_ColorRamp_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
305 ID *id = ptr->id.data;
307 switch (GS(id->name)) {
310 Material *ma = ptr->id.data;
312 DAG_id_tag_update(&ma->id, 0);
313 WM_main_add_notifier(NC_MATERIAL | ND_SHADING_DRAW, ma);
318 bNodeTree *ntree = (bNodeTree *)id;
321 for (node = ntree->nodes.first; node; node = node->next) {
322 if (ELEM3(node->type, SH_NODE_VALTORGB, CMP_NODE_VALTORGB, TEX_NODE_VALTORGB)) {
323 ED_node_tag_update_nodetree(bmain, ntree);
330 Tex *tex = ptr->id.data;
332 DAG_id_tag_update(&tex->id, 0);
333 WM_main_add_notifier(NC_TEXTURE, tex);
338 FreestyleLineStyle *linestyle = ptr->id.data;
340 WM_main_add_notifier(NC_LINESTYLE, linestyle);
349 static void rna_ColorRamp_eval(struct ColorBand *coba, float position, float color[4])
351 do_colorband(coba, position, color);
354 static CBData *rna_ColorRampElement_new(struct ColorBand *coba, ReportList *reports, float position)
356 CBData *element = colorband_element_add(coba, position);
359 BKE_reportf(reports, RPT_ERROR, "Unable to add element to colorband (limit %d)", MAXCOLORBAND);
364 static void rna_ColorRampElement_remove(struct ColorBand *coba, ReportList *reports, PointerRNA *element_ptr)
366 CBData *element = element_ptr->data;
367 int index = (int)(element - coba->data);
368 if (colorband_element_remove(coba, index) == FALSE) {
369 BKE_report(reports, RPT_ERROR, "Element not found in element collection or last element");
373 RNA_POINTER_INVALIDATE(element_ptr);
376 void rna_CurveMap_remove_point(CurveMap *cuma, ReportList *reports, PointerRNA *point_ptr)
378 CurveMapPoint *point = point_ptr->data;
379 if (curvemap_remove_point(cuma, point) == FALSE) {
380 BKE_report(reports, RPT_ERROR, "Unable to remove curve point");
384 RNA_POINTER_INVALIDATE(point_ptr);
387 static void rna_Scopes_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
389 Scopes *s = (Scopes *)ptr->data;
393 static int rna_ColorManagedDisplaySettings_display_device_get(struct PointerRNA *ptr)
395 ColorManagedDisplaySettings *display = (ColorManagedDisplaySettings *) ptr->data;
397 return IMB_colormanagement_display_get_named_index(display->display_device);
400 static void rna_ColorManagedDisplaySettings_display_device_set(struct PointerRNA *ptr, int value)
402 ColorManagedDisplaySettings *display = (ColorManagedDisplaySettings *) ptr->data;
403 const char *name = IMB_colormanagement_display_get_indexed_name(value);
406 BLI_strncpy(display->display_device, name, sizeof(display->display_device));
410 static EnumPropertyItem *rna_ColorManagedDisplaySettings_display_device_itemf(bContext *UNUSED(C), PointerRNA *ptr,
411 PropertyRNA *UNUSED(prop), int *free)
413 EnumPropertyItem *items = NULL;
416 IMB_colormanagement_display_items_add(&items, &totitem);
417 RNA_enum_item_end(&items, &totitem);
424 static void rna_ColorManagedDisplaySettings_display_device_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
426 ID *id = ptr->id.data;
431 if (GS(id->name) == ID_SCE) {
432 Scene *scene = (Scene *) id;
434 IMB_colormanagement_validate_settings(&scene->display_settings, &scene->view_settings);
436 WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, NULL);
440 static int rna_ColorManagedViewSettings_view_transform_get(PointerRNA *ptr)
442 ColorManagedViewSettings *view = (ColorManagedViewSettings *) ptr->data;
444 return IMB_colormanagement_view_get_named_index(view->view_transform);
447 static void rna_ColorManagedViewSettings_view_transform_set(PointerRNA *ptr, int value)
449 ColorManagedViewSettings *view = (ColorManagedViewSettings *) ptr->data;
451 const char *name = IMB_colormanagement_view_get_indexed_name(value);
454 BLI_strncpy(view->view_transform, name, sizeof(view->view_transform));
458 static EnumPropertyItem *rna_ColorManagedViewSettings_view_transform_itemf(bContext *C, PointerRNA *ptr,
459 PropertyRNA *UNUSED(prop), int *free)
461 Scene *scene = CTX_data_scene(C);
462 EnumPropertyItem *items = NULL;
463 ColorManagedDisplaySettings *display_settings = &scene->display_settings;
466 IMB_colormanagement_view_items_add(&items, &totitem, display_settings->display_device);
467 RNA_enum_item_end(&items, &totitem);
473 static void rna_ColorManagedViewSettings_use_curves_set(PointerRNA *ptr, int value)
475 ColorManagedViewSettings *view_settings = (ColorManagedViewSettings *) ptr->data;
478 view_settings->flag |= COLORMANAGE_VIEW_USE_CURVES;
480 if (view_settings->curve_mapping == NULL) {
481 view_settings->curve_mapping = curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f);
485 view_settings->flag &= ~COLORMANAGE_VIEW_USE_CURVES;
489 static int rna_ColorManagedColorspaceSettings_colorspace_get(struct PointerRNA *ptr)
491 ColorManagedColorspaceSettings *colorspace = (ColorManagedColorspaceSettings *) ptr->data;
493 return IMB_colormanagement_colorspace_get_named_index(colorspace->name);
496 static void rna_ColorManagedColorspaceSettings_colorspace_set(struct PointerRNA *ptr, int value)
498 ColorManagedColorspaceSettings *colorspace = (ColorManagedColorspaceSettings *) ptr->data;
499 const char *name = IMB_colormanagement_colorspace_get_indexed_name(value);
502 BLI_strncpy(colorspace->name, name, sizeof(colorspace->name));
506 static EnumPropertyItem *rna_ColorManagedColorspaceSettings_colorspace_itemf(bContext *UNUSED(C), PointerRNA *ptr,
507 PropertyRNA *UNUSED(prop), int *free)
509 EnumPropertyItem *items = NULL;
512 IMB_colormanagement_colorspace_items_add(&items, &totitem);
513 RNA_enum_item_end(&items, &totitem);
520 static void rna_ColorManagedColorspaceSettings_reload_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
522 ID *id = ptr->id.data;
524 if (GS(id->name) == ID_IM) {
525 Image *ima = (Image *) id;
527 DAG_id_tag_update(&ima->id, 0);
529 BKE_image_signal(ima, NULL, IMA_SIGNAL_COLORMANAGE);
531 WM_main_add_notifier(NC_IMAGE | ND_DISPLAY, &ima->id);
532 WM_main_add_notifier(NC_IMAGE | NA_EDITED, &ima->id);
534 else if (GS(id->name) == ID_MC) {
535 MovieClip *clip = (MovieClip *) id;
537 BKE_movieclip_reload(clip);
539 /* all sequencers for now, we don't know which scenes are using this clip as a strip */
540 BKE_sequencer_cache_cleanup();
541 BKE_sequencer_preprocessed_cache_cleanup();
543 WM_main_add_notifier(NC_MOVIECLIP | ND_DISPLAY, &clip->id);
544 WM_main_add_notifier(NC_MOVIECLIP | NA_EDITED, &clip->id);
546 else if (GS(id->name) == ID_SCE) {
547 Scene *scene = (Scene *) id;
550 ColorManagedColorspaceSettings *colorspace_settings = (ColorManagedColorspaceSettings *) ptr->data;
552 int seq_found = FALSE;
554 if (&scene->sequencer_colorspace_settings != colorspace_settings) {
555 SEQ_BEGIN(scene->ed, seq);
557 if (seq->strip && &seq->strip->colorspace_settings == colorspace_settings) {
566 BKE_sequence_invalidate_cache(scene, seq);
567 BKE_sequencer_preprocessed_cache_cleanup_sequence(seq);
570 BKE_sequencer_cache_cleanup();
571 BKE_sequencer_preprocessed_cache_cleanup();
574 WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, NULL);
579 static void rna_ColorManagement_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
581 ID *id = ptr->id.data;
586 if (GS(id->name) == ID_SCE) {
587 DAG_id_tag_update(id, 0);
588 WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, NULL);
592 /* this function only exists because #curvemap_evaluateF uses a 'const' qualifier */
593 static float rna_CurveMap_evaluateF(struct CurveMap *cuma, float value)
595 return curvemap_evaluateF(cuma, value);
600 static void rna_def_curvemappoint(BlenderRNA *brna)
604 static EnumPropertyItem prop_handle_type_items[] = {
605 {0, "AUTO", 0, "Auto Handle", ""},
606 {CUMA_VECTOR, "VECTOR", 0, "Vector Handle", ""},
607 {0, NULL, 0, NULL, NULL}
610 srna = RNA_def_struct(brna, "CurveMapPoint", NULL);
611 RNA_def_struct_ui_text(srna, "CurveMapPoint", "Point of a curve used for a curve mapping");
613 prop = RNA_def_property(srna, "location", PROP_FLOAT, PROP_XYZ);
614 RNA_def_property_float_sdna(prop, NULL, "x");
615 RNA_def_property_array(prop, 2);
616 RNA_def_property_ui_text(prop, "Location", "X/Y coordinates of the curve point");
618 prop = RNA_def_property(srna, "handle_type", PROP_ENUM, PROP_NONE);
619 RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
620 RNA_def_property_enum_items(prop, prop_handle_type_items);
621 RNA_def_property_ui_text(prop, "Handle Type", "Curve interpolation at this point: Bezier or vector");
623 prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
624 RNA_def_property_boolean_sdna(prop, NULL, "flag", CUMA_SELECT);
625 RNA_def_property_ui_text(prop, "Select", "Selection state of the curve point");
628 static void rna_def_curvemap_points_api(BlenderRNA *brna, PropertyRNA *cprop)
634 RNA_def_property_srna(cprop, "CurveMapPoints");
635 srna = RNA_def_struct(brna, "CurveMapPoints", NULL);
636 RNA_def_struct_sdna(srna, "CurveMap");
637 RNA_def_struct_ui_text(srna, "Curve Map Point", "Collection of Curve Map Points");
639 func = RNA_def_function(srna, "new", "curvemap_insert");
640 RNA_def_function_ui_description(func, "Add point to CurveMap");
641 parm = RNA_def_float(func, "position", 0.0f, -FLT_MAX, FLT_MAX, "Position", "Position to add point", -FLT_MAX, FLT_MAX);
642 RNA_def_property_flag(parm, PROP_REQUIRED);
643 parm = RNA_def_float(func, "value", 0.0f, -FLT_MAX, FLT_MAX, "Value", "Value of point", -FLT_MAX, FLT_MAX);
644 RNA_def_property_flag(parm, PROP_REQUIRED);
645 parm = RNA_def_pointer(func, "point", "CurveMapPoint", "", "New point");
646 RNA_def_function_return(func, parm);
648 func = RNA_def_function(srna, "remove", "rna_CurveMap_remove_point");
649 RNA_def_function_flag(func, FUNC_USE_REPORTS);
650 RNA_def_function_ui_description(func, "Delete point from CurveMap");
651 parm = RNA_def_pointer(func, "point", "CurveMapPoint", "", "PointElement to remove");
652 RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR);
653 RNA_def_property_clear_flag(parm, PROP_THICK_WRAP);
656 static void rna_def_curvemap(BlenderRNA *brna)
659 PropertyRNA *prop, *parm;
662 static EnumPropertyItem prop_extend_items[] = {
663 {0, "HORIZONTAL", 0, "Horizontal", ""},
664 {CUMA_EXTEND_EXTRAPOLATE, "EXTRAPOLATED", 0, "Extrapolated", ""},
665 {0, NULL, 0, NULL, NULL}
668 srna = RNA_def_struct(brna, "CurveMap", NULL);
669 RNA_def_struct_ui_text(srna, "CurveMap", "Curve in a curve mapping");
671 prop = RNA_def_property(srna, "extend", PROP_ENUM, PROP_NONE);
672 RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
673 RNA_def_property_enum_items(prop, prop_extend_items);
674 RNA_def_property_ui_text(prop, "Extend", "Extrapolate the curve or extend it horizontally");
676 prop = RNA_def_property(srna, "points", PROP_COLLECTION, PROP_NONE);
677 RNA_def_property_collection_sdna(prop, NULL, "curve", "totpoint");
678 RNA_def_property_struct_type(prop, "CurveMapPoint");
679 RNA_def_property_ui_text(prop, "Points", "");
680 rna_def_curvemap_points_api(brna, prop);
682 func = RNA_def_function(srna, "evaluate", "rna_CurveMap_evaluateF");
683 RNA_def_function_ui_description(func, "Evaluate curve at given location");
684 parm = RNA_def_float(func, "position", 0.0f, -FLT_MAX, FLT_MAX, "Position", "Position to evaluate curve at", -FLT_MAX, FLT_MAX);
685 RNA_def_property_flag(parm, PROP_REQUIRED);
686 parm = RNA_def_float(func, "value", 0.0f, -FLT_MAX, FLT_MAX, "Value", "Value of curve at given location", -FLT_MAX, FLT_MAX);
687 RNA_def_function_return(func, parm);
690 static void rna_def_curvemapping(BlenderRNA *brna)
696 srna = RNA_def_struct(brna, "CurveMapping", NULL);
697 RNA_def_struct_ui_text(srna, "CurveMapping",
698 "Curve mapping to map color, vector and scalar values to other values using "
699 "a user defined curve");
701 prop = RNA_def_property(srna, "use_clip", PROP_BOOLEAN, PROP_NONE);
702 RNA_def_property_boolean_sdna(prop, NULL, "flag", CUMA_DO_CLIP);
703 RNA_def_property_ui_text(prop, "Clip", "Force the curve view to fit a defined boundary");
704 RNA_def_property_boolean_funcs(prop, NULL, "rna_CurveMapping_clip_set");
706 prop = RNA_def_property(srna, "clip_min_x", PROP_FLOAT, PROP_NONE);
707 RNA_def_property_float_sdna(prop, NULL, "clipr.xmin");
708 RNA_def_property_range(prop, -100.0f, 100.0f);
709 RNA_def_property_ui_text(prop, "Clip Min X", "");
710 RNA_def_property_float_funcs(prop, NULL, NULL, "rna_CurveMapping_clipminx_range");
712 prop = RNA_def_property(srna, "clip_min_y", PROP_FLOAT, PROP_NONE);
713 RNA_def_property_float_sdna(prop, NULL, "clipr.ymin");
714 RNA_def_property_range(prop, -100.0f, 100.0f);
715 RNA_def_property_ui_text(prop, "Clip Min Y", "");
716 RNA_def_property_float_funcs(prop, NULL, NULL, "rna_CurveMapping_clipminy_range");
718 prop = RNA_def_property(srna, "clip_max_x", PROP_FLOAT, PROP_NONE);
719 RNA_def_property_float_sdna(prop, NULL, "clipr.xmax");
720 RNA_def_property_range(prop, -100.0f, 100.0f);
721 RNA_def_property_ui_text(prop, "Clip Max X", "");
722 RNA_def_property_float_funcs(prop, NULL, NULL, "rna_CurveMapping_clipmaxx_range");
724 prop = RNA_def_property(srna, "clip_max_y", PROP_FLOAT, PROP_NONE);
725 RNA_def_property_float_sdna(prop, NULL, "clipr.ymax");
726 RNA_def_property_range(prop, -100.0f, 100.0f);
727 RNA_def_property_ui_text(prop, "Clip Max Y", "");
728 RNA_def_property_float_funcs(prop, NULL, NULL, "rna_CurveMapping_clipmaxy_range");
730 prop = RNA_def_property(srna, "curves", PROP_COLLECTION, PROP_NONE);
731 RNA_def_property_collection_funcs(prop, "rna_CurveMapping_curves_begin", "rna_iterator_array_next",
732 "rna_iterator_array_end", "rna_iterator_array_get",
733 "rna_CurveMapping_curves_length", NULL, NULL, NULL);
734 RNA_def_property_struct_type(prop, "CurveMap");
735 RNA_def_property_ui_text(prop, "Curves", "");
737 prop = RNA_def_property(srna, "black_level", PROP_FLOAT, PROP_COLOR);
738 RNA_def_property_float_sdna(prop, NULL, "black");
739 RNA_def_property_range(prop, -1000.0f, 1000.0f);
740 RNA_def_property_ui_text(prop, "Black Level", "For RGB curves, the color that black is mapped to");
741 RNA_def_property_float_funcs(prop, NULL, "rna_CurveMapping_black_level_set", NULL);
743 prop = RNA_def_property(srna, "white_level", PROP_FLOAT, PROP_COLOR);
744 RNA_def_property_float_sdna(prop, NULL, "white");
745 RNA_def_property_range(prop, -1000.0f, 1000.0f);
746 RNA_def_property_ui_text(prop, "White Level", "For RGB curves, the color that white is mapped to");
747 RNA_def_property_float_funcs(prop, NULL, "rna_CurveMapping_white_level_set", NULL);
749 func = RNA_def_function(srna, "update", "curvemapping_changed_all");
750 RNA_def_function_ui_description(func, "Update curve mapping after making changes");
753 static void rna_def_color_ramp_element(BlenderRNA *brna)
758 srna = RNA_def_struct(brna, "ColorRampElement", NULL);
759 RNA_def_struct_sdna(srna, "CBData");
760 RNA_def_struct_path_func(srna, "rna_ColorRampElement_path");
761 RNA_def_struct_ui_text(srna, "Color Ramp Element", "Element defining a color at a position in the color ramp");
763 prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR);
764 RNA_def_property_float_sdna(prop, NULL, "r");
765 RNA_def_property_array(prop, 4);
766 RNA_def_property_ui_text(prop, "Color", "Set color of selected color stop");
767 RNA_def_property_update(prop, 0, "rna_ColorRamp_update");
769 prop = RNA_def_property(srna, "position", PROP_FLOAT, PROP_NONE);
770 RNA_def_property_float_sdna(prop, NULL, "pos");
771 RNA_def_property_range(prop, 0, 1);
772 RNA_def_property_ui_text(prop, "Position", "Set position of selected color stop");
773 RNA_def_property_update(prop, 0, "rna_ColorRamp_update");
776 static void rna_def_color_ramp_element_api(BlenderRNA *brna, PropertyRNA *cprop)
782 RNA_def_property_srna(cprop, "ColorRampElements");
783 srna = RNA_def_struct(brna, "ColorRampElements", NULL);
784 RNA_def_struct_sdna(srna, "ColorBand");
785 RNA_def_struct_path_func(srna, "rna_ColorRampElement_path");
786 RNA_def_struct_ui_text(srna, "Color Ramp Elements", "Collection of Color Ramp Elements");
788 /* TODO, make these functions generic in texture.c */
789 func = RNA_def_function(srna, "new", "rna_ColorRampElement_new");
790 RNA_def_function_ui_description(func, "Add element to ColorRamp");
791 RNA_def_function_flag(func, FUNC_USE_REPORTS);
792 parm = RNA_def_float(func, "position", 0.0f, 0.0f, 1.0f, "Position", "Position to add element", 0.0f, 1.0f);
793 RNA_def_property_flag(parm, PROP_REQUIRED);
795 parm = RNA_def_pointer(func, "element", "ColorRampElement", "", "New element");
796 RNA_def_function_return(func, parm);
798 func = RNA_def_function(srna, "remove", "rna_ColorRampElement_remove");
799 RNA_def_function_ui_description(func, "Delete element from ColorRamp");
800 RNA_def_function_flag(func, FUNC_USE_REPORTS);
801 parm = RNA_def_pointer(func, "element", "ColorRampElement", "", "Element to remove");
802 RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR);
803 RNA_def_property_clear_flag(parm, PROP_THICK_WRAP);
806 static void rna_def_color_ramp(BlenderRNA *brna)
812 static EnumPropertyItem prop_interpolation_items[] = {
813 {1, "EASE", 0, "Ease", ""},
814 {3, "CARDINAL", 0, "Cardinal", ""},
815 {0, "LINEAR", 0, "Linear", ""},
816 {2, "B_SPLINE", 0, "B-Spline", ""},
817 {4, "CONSTANT", 0, "Constant", ""},
818 {0, NULL, 0, NULL, NULL}
821 srna = RNA_def_struct(brna, "ColorRamp", NULL);
822 RNA_def_struct_sdna(srna, "ColorBand");
823 RNA_def_struct_path_func(srna, "rna_ColorRamp_path");
824 RNA_def_struct_ui_text(srna, "Color Ramp", "Color ramp mapping a scalar value to a color");
826 prop = RNA_def_property(srna, "elements", PROP_COLLECTION, PROP_COLOR);
827 RNA_def_property_collection_sdna(prop, NULL, "data", "tot");
828 RNA_def_property_struct_type(prop, "ColorRampElement");
829 RNA_def_property_ui_text(prop, "Elements", "");
830 RNA_def_property_update(prop, 0, "rna_ColorRamp_update");
831 rna_def_color_ramp_element_api(brna, prop);
833 prop = RNA_def_property(srna, "interpolation", PROP_ENUM, PROP_NONE);
834 RNA_def_property_enum_sdna(prop, NULL, "ipotype");
835 RNA_def_property_enum_items(prop, prop_interpolation_items);
836 RNA_def_property_ui_text(prop, "Interpolation", "");
837 RNA_def_property_update(prop, 0, "rna_ColorRamp_update");
839 #if 0 /* use len(elements) */
840 prop = RNA_def_property(srna, "total", PROP_INT, PROP_NONE);
841 RNA_def_property_int_sdna(prop, NULL, "tot");
842 /* needs a function to do the right thing when adding elements like colorband_add_cb() */
843 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
844 RNA_def_property_range(prop, 0, 31); /* MAXCOLORBAND = 32 */
845 RNA_def_property_ui_text(prop, "Total", "Total number of elements");
846 RNA_def_property_update(prop, 0, "rna_ColorRamp_update");
849 func = RNA_def_function(srna, "evaluate", "rna_ColorRamp_eval");
850 RNA_def_function_ui_description(func, "Evaluate ColorRamp");
851 prop = RNA_def_float(func, "position", 1.0f, 0.0f, 1.0f, "Position", "Evaluate ColorRamp at position", 0.0f, 1.0f);
852 RNA_def_property_flag(prop, PROP_REQUIRED);
854 prop = RNA_def_float_color(func, "color", 4, NULL, -FLT_MAX, FLT_MAX, "Color", "Color at given position",
856 RNA_def_property_flag(prop, PROP_THICK_WRAP);
857 RNA_def_function_output(func, prop);
860 static void rna_def_histogram(BlenderRNA *brna)
865 static EnumPropertyItem prop_mode_items[] = {
866 {HISTO_MODE_LUMA, "LUMA", 0, "Luma", "Luma"},
867 {HISTO_MODE_RGB, "RGB", 0, "RGB", "Red Green Blue"},
868 {HISTO_MODE_R, "R", 0, "R", "Red"},
869 {HISTO_MODE_G, "G", 0, "G", "Green"},
870 {HISTO_MODE_B, "B", 0, "B", "Blue"},
871 {HISTO_MODE_ALPHA, "A", 0, "A", "Alpha"},
872 {0, NULL, 0, NULL, NULL}
875 srna = RNA_def_struct(brna, "Histogram", NULL);
876 RNA_def_struct_ui_text(srna, "Histogram", "Statistical view of the levels of color in an image");
878 prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
879 RNA_def_property_enum_sdna(prop, NULL, "mode");
880 RNA_def_property_enum_items(prop, prop_mode_items);
881 RNA_def_property_ui_text(prop, "Mode", "Channels to display when drawing the histogram");
883 prop = RNA_def_property(srna, "show_line", PROP_BOOLEAN, PROP_NONE);
884 RNA_def_property_boolean_sdna(prop, NULL, "flag", HISTO_FLAG_LINE);
885 RNA_def_property_ui_text(prop, "Show Line", "Display lines rather than filled shapes");
886 RNA_def_property_ui_icon(prop, ICON_IPO, 0);
889 static void rna_def_scopes(BlenderRNA *brna)
894 static EnumPropertyItem prop_wavefrm_mode_items[] = {
895 {SCOPES_WAVEFRM_LUMA, "LUMA", ICON_COLOR, "Luma", ""},
896 {SCOPES_WAVEFRM_RGB, "RGB", ICON_COLOR, "Red Green Blue", ""},
897 {SCOPES_WAVEFRM_YCC_601, "YCBCR601", ICON_COLOR, "YCbCr (ITU 601)", ""},
898 {SCOPES_WAVEFRM_YCC_709, "YCBCR709", ICON_COLOR, "YCbCr (ITU 709)", ""},
899 {SCOPES_WAVEFRM_YCC_JPEG, "YCBCRJPG", ICON_COLOR, "YCbCr (Jpeg)", ""},
900 {0, NULL, 0, NULL, NULL}
903 srna = RNA_def_struct(brna, "Scopes", NULL);
904 RNA_def_struct_ui_text(srna, "Scopes", "Scopes for statistical view of an image");
906 prop = RNA_def_property(srna, "use_full_resolution", PROP_BOOLEAN, PROP_NONE);
907 RNA_def_property_boolean_sdna(prop, "Scopes", "sample_full", 1);
908 RNA_def_property_ui_text(prop, "Full Sample", "Sample every pixel of the image");
909 RNA_def_property_update(prop, 0, "rna_Scopes_update");
911 prop = RNA_def_property(srna, "accuracy", PROP_FLOAT, PROP_PERCENTAGE);
912 RNA_def_property_float_sdna(prop, "Scopes", "accuracy");
913 RNA_def_property_range(prop, 0.0, 100.0);
914 RNA_def_property_ui_range(prop, 0.0, 100.0, 10, 1);
915 RNA_def_property_ui_text(prop, "Accuracy", "Proportion of original image source pixel lines to sample");
916 RNA_def_property_update(prop, 0, "rna_Scopes_update");
918 prop = RNA_def_property(srna, "histogram", PROP_POINTER, PROP_NONE);
919 RNA_def_property_pointer_sdna(prop, "Scopes", "hist");
920 RNA_def_property_struct_type(prop, "Histogram");
921 RNA_def_property_ui_text(prop, "Histogram", "Histogram for viewing image statistics");
923 prop = RNA_def_property(srna, "waveform_mode", PROP_ENUM, PROP_NONE);
924 RNA_def_property_enum_sdna(prop, "Scopes", "wavefrm_mode");
925 RNA_def_property_enum_items(prop, prop_wavefrm_mode_items);
926 RNA_def_property_ui_text(prop, "Waveform Mode", "");
927 RNA_def_property_update(prop, 0, "rna_Scopes_update");
929 prop = RNA_def_property(srna, "waveform_alpha", PROP_FLOAT, PROP_FACTOR);
930 RNA_def_property_float_sdna(prop, "Scopes", "wavefrm_alpha");
931 RNA_def_property_range(prop, 0, 1);
932 RNA_def_property_ui_text(prop, "Waveform Opacity", "Opacity of the points");
934 prop = RNA_def_property(srna, "vectorscope_alpha", PROP_FLOAT, PROP_FACTOR);
935 RNA_def_property_float_sdna(prop, "Scopes", "vecscope_alpha");
936 RNA_def_property_range(prop, 0, 1);
937 RNA_def_property_ui_text(prop, "Vectorscope Opacity", "Opacity of the points");
940 static void rna_def_colormanage(BlenderRNA *brna)
945 static EnumPropertyItem display_device_items[] = {
946 {0, "DEFAULT", 0, "Default", ""},
947 {0, NULL, 0, NULL, NULL}
950 static EnumPropertyItem view_transform_items[] = {
951 {0, "NONE", 0, "None", "Do not perform any color transform on display, use old non-color managed technique for display"},
952 {0, NULL, 0, NULL, NULL}
955 static EnumPropertyItem color_space_items[] = {
956 {0, "NONE", 0, "None", "Do not perform any color transform on load, treat colors as in scene linear space already"},
957 {0, NULL, 0, NULL, NULL}
960 /* ** Display Settings ** */
961 srna = RNA_def_struct(brna, "ColorManagedDisplaySettings", NULL);
962 RNA_def_struct_ui_text(srna, "ColorManagedDisplaySettings", "Color management specific to display device");
964 prop = RNA_def_property(srna, "display_device", PROP_ENUM, PROP_NONE);
965 RNA_def_property_enum_items(prop, display_device_items);
966 RNA_def_property_enum_funcs(prop, "rna_ColorManagedDisplaySettings_display_device_get",
967 "rna_ColorManagedDisplaySettings_display_device_set",
968 "rna_ColorManagedDisplaySettings_display_device_itemf");
969 RNA_def_property_ui_text(prop, "Display Device", "Display device name");
970 RNA_def_property_update(prop, NC_WINDOW, "rna_ColorManagedDisplaySettings_display_device_update");
972 /* ** View Settings ** */
973 srna = RNA_def_struct(brna, "ColorManagedViewSettings", NULL);
974 RNA_def_struct_ui_text(srna, "ColorManagedViewSettings", "Color management settings used for displaying images on the display");
976 prop = RNA_def_property(srna, "view_transform", PROP_ENUM, PROP_NONE);
977 RNA_def_property_enum_items(prop, view_transform_items);
978 RNA_def_property_enum_funcs(prop, "rna_ColorManagedViewSettings_view_transform_get",
979 "rna_ColorManagedViewSettings_view_transform_set",
980 "rna_ColorManagedViewSettings_view_transform_itemf");
981 RNA_def_property_ui_text(prop, "View Transform", "View used ");
982 RNA_def_property_update(prop, NC_WINDOW, "rna_ColorManagement_update");
984 prop = RNA_def_property(srna, "exposure", PROP_FLOAT, PROP_FACTOR);
985 RNA_def_property_float_sdna(prop, NULL, "exposure");
986 RNA_def_property_range(prop, -10.0f, 10.0f);
987 RNA_def_property_float_default(prop, 0.0f);
988 RNA_def_property_ui_text(prop, "Exposure", "Exposure (stops) applied before display transform");
989 RNA_def_property_update(prop, NC_WINDOW, "rna_ColorManagement_update");
991 prop = RNA_def_property(srna, "gamma", PROP_FLOAT, PROP_FACTOR);
992 RNA_def_property_float_sdna(prop, NULL, "gamma");
993 RNA_def_property_float_default(prop, 1.0f);
994 RNA_def_property_range(prop, 0.0f, 5.0f);
995 RNA_def_property_ui_text(prop, "Gamma", "Amount of gamma modification applied after display transform");
996 RNA_def_property_update(prop, NC_WINDOW, "rna_ColorManagement_update");
998 prop = RNA_def_property(srna, "curve_mapping", PROP_POINTER, PROP_NONE);
999 RNA_def_property_pointer_sdna(prop, NULL, "curve_mapping");
1000 RNA_def_property_ui_text(prop, "Curve", "Color curve mapping applied before display transform");
1001 RNA_def_property_update(prop, NC_WINDOW, "rna_ColorManagement_update");
1003 prop = RNA_def_property(srna, "use_curve_mapping", PROP_BOOLEAN, PROP_NONE);
1004 RNA_def_property_boolean_sdna(prop, NULL, "flag", COLORMANAGE_VIEW_USE_CURVES);
1005 RNA_def_property_boolean_funcs(prop, NULL, "rna_ColorManagedViewSettings_use_curves_set");
1006 RNA_def_property_ui_text(prop, "Use Curves", "Use RGB curved for pre-display transformation");
1007 RNA_def_property_update(prop, NC_WINDOW, "rna_ColorManagement_update");
1009 /* ** Colorspace ** */
1010 srna = RNA_def_struct(brna, "ColorManagedInputColorspaceSettings", NULL);
1011 RNA_def_struct_ui_text(srna, "ColorManagedInputColorspaceSettings", "Input color space settings");
1013 prop = RNA_def_property(srna, "name", PROP_ENUM, PROP_NONE);
1014 RNA_def_property_flag(prop, PROP_ENUM_NO_CONTEXT);
1015 RNA_def_property_enum_items(prop, color_space_items);
1016 RNA_def_property_enum_funcs(prop, "rna_ColorManagedColorspaceSettings_colorspace_get",
1017 "rna_ColorManagedColorspaceSettings_colorspace_set",
1018 "rna_ColorManagedColorspaceSettings_colorspace_itemf");
1019 RNA_def_property_ui_text(prop, "Input Color Space", "Color space of the image or movie on disk");
1020 RNA_def_property_update(prop, NC_WINDOW, "rna_ColorManagedColorspaceSettings_reload_update");
1022 srna = RNA_def_struct(brna, "ColorManagedSequencerColorspaceSettings", NULL);
1023 RNA_def_struct_ui_text(srna, "ColorManagedSequencerColorspaceSettings", "Input color space settings");
1025 prop = RNA_def_property(srna, "name", PROP_ENUM, PROP_NONE);
1026 RNA_def_property_flag(prop, PROP_ENUM_NO_CONTEXT);
1027 RNA_def_property_enum_items(prop, color_space_items);
1028 RNA_def_property_enum_funcs(prop, "rna_ColorManagedColorspaceSettings_colorspace_get",
1029 "rna_ColorManagedColorspaceSettings_colorspace_set",
1030 "rna_ColorManagedColorspaceSettings_colorspace_itemf");
1031 RNA_def_property_ui_text(prop, "Color Space", "Color space that the sequencer operates in");
1032 RNA_def_property_update(prop, NC_WINDOW, "rna_ColorManagedColorspaceSettings_reload_update");
1035 void RNA_def_color(BlenderRNA *brna)
1037 rna_def_curvemappoint(brna);
1038 rna_def_curvemap(brna);
1039 rna_def_curvemapping(brna);
1040 rna_def_color_ramp_element(brna);
1041 rna_def_color_ramp(brna);
1042 rna_def_histogram(brna);
1043 rna_def_scopes(brna);
1044 rna_def_colormanage(brna);