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 * The Original Code is Copyright (C) 2012 by Blender Foundation.
19 * All rights reserved.
21 * The Original Code is: all of this file.
23 * Contributor(s): Xavier Thomas,
27 * ***** END GPL LICENSE BLOCK *****
31 #ifndef __IMB_COLORMANAGEMENT_H__
32 #define __IMB_COLORMANAGEMENT_H__
34 /** \file blender/imbuf/IMB_colormanagement.h
38 #include "BLI_sys_types.h"
39 #include "BLI_compiler_compat.h"
41 #define BCM_CONFIG_FILE "config.ocio"
45 struct ColorManagedColorspaceSettings;
46 struct ColorManagedDisplaySettings;
47 struct ColorManagedViewSettings;
48 struct ColormanageProcessor;
49 struct EnumPropertyItem;
52 struct ImageFormatData;
55 struct ColorManagedDisplay;
57 /* ** Generic functions ** */
59 void IMB_colormanagement_check_file_config(struct Main *bmain);
61 void IMB_colormanagement_validate_settings(struct ColorManagedDisplaySettings *display_settings,
62 struct ColorManagedViewSettings *view_settings);
64 const char *IMB_colormanagement_role_colorspace_name_get(int role);
65 void IMB_colormanagement_check_is_data(struct ImBuf *ibuf, const char *name);
66 void IMB_colormanagement_assign_float_colorspace(struct ImBuf *ibuf, const char *name);
67 void IMB_colormanagement_assign_rect_colorspace(struct ImBuf *ibuf, const char *name);
69 const char *IMB_colormanagement_get_float_colorspace(struct ImBuf *ibuf);
70 const char *IMB_colormanagement_get_rect_colorspace(struct ImBuf *ibuf);
72 BLI_INLINE float IMB_colormanagement_get_luminance(const float rgb[3]);
73 BLI_INLINE unsigned char IMB_colormanagement_get_luminance_byte(const unsigned char[3]);
75 /* ** Color space transformation functions ** */
76 void IMB_colormanagement_transform(float *buffer, int width, int height, int channels,
77 const char *from_colorspace, const char *to_colorspace, bool predivide);
78 void IMB_colormanagement_transform_threaded(float *buffer, int width, int height, int channels,
79 const char *from_colorspace, const char *to_colorspace, bool predivide);
80 void IMB_colormanagement_transform_byte(unsigned char *buffer, int width, int height, int channels,
81 const char *from_colorspace, const char *to_colorspace);
82 void IMB_colormanagement_transform_byte_threaded(unsigned char *buffer, int width, int height, int channels,
83 const char *from_colorspace, const char *to_colorspace);
84 void IMB_colormanagement_transform_from_byte(float *float_buffer, unsigned char *byte_buffer,
85 int width, int height, int channels,
86 const char *from_colorspace, const char *to_colorspace);
87 void IMB_colormanagement_transform_from_byte_threaded(float *float_buffer, unsigned char *byte_buffer,
88 int width, int height, int channels,
89 const char *from_colorspace, const char *to_colorspace);
90 void IMB_colormanagement_transform_v4(float pixel[4], const char *from_colorspace, const char *to_colorspace);
92 void IMB_colormanagement_colorspace_to_scene_linear_v3(float pixel[3], struct ColorSpace *colorspace);
93 void IMB_colormanagement_colorspace_to_scene_linear_v4(float pixel[4], bool predivide, struct ColorSpace *colorspace);
95 void IMB_colormanagement_scene_linear_to_colorspace_v3(float pixel[3], struct ColorSpace *colorspace);
97 void IMB_colormanagement_colorspace_to_scene_linear(float *buffer, int width, int height, int channels, struct ColorSpace *colorspace, bool predivide);
99 void IMB_colormanagement_scene_linear_to_display_v3(float pixel[3], struct ColorManagedDisplay *display);
100 void IMB_colormanagement_display_to_scene_linear_v3(float pixel[3], struct ColorManagedDisplay *display);
102 void IMB_colormanagement_pixel_to_display_space_v4(float result[4], const float pixel[4], const struct ColorManagedViewSettings *view_settings,
103 const struct ColorManagedDisplaySettings *display_settings);
105 void IMB_colormanagement_pixel_to_display_space_v3(float result[3], const float pixel[3], const struct ColorManagedViewSettings *view_settings,
106 const struct ColorManagedDisplaySettings *display_settings);
108 void IMB_colormanagement_imbuf_make_display_space(struct ImBuf *ibuf, const struct ColorManagedViewSettings *view_settings,
109 const struct ColorManagedDisplaySettings *display_settings);
111 struct ImBuf *IMB_colormanagement_imbuf_for_write(struct ImBuf *ibuf, bool save_as_render, bool allocate_result,
112 const struct ColorManagedViewSettings *view_settings,
113 const struct ColorManagedDisplaySettings *display_settings,
114 struct ImageFormatData *image_format_data);
116 void IMB_colormanagement_buffer_make_display_space(float *buffer, unsigned char *display_buffer,
117 int width, int height, int channels, float dither,
118 const struct ColorManagedViewSettings *view_settings,
119 const struct ColorManagedDisplaySettings *display_settings);
121 /* ** Public display buffers interfaces ** */
123 void IMB_colormanagement_display_settings_from_ctx(const struct bContext *C,
124 struct ColorManagedViewSettings **view_settings_r,
125 struct ColorManagedDisplaySettings **display_settings_r);
127 const char *IMB_colormanagement_get_display_colorspace_name(const struct ColorManagedViewSettings *view_settings,
128 const struct ColorManagedDisplaySettings *display_settings);
130 unsigned char *IMB_display_buffer_acquire(struct ImBuf *ibuf, const struct ColorManagedViewSettings *view_settings,
131 const struct ColorManagedDisplaySettings *display_settings, void **cache_handle);
132 unsigned char *IMB_display_buffer_acquire_ctx(const struct bContext *C, struct ImBuf *ibuf, void **cache_handle);
134 void IMB_display_buffer_transform_apply(unsigned char *display_buffer, float *linear_buffer, int width, int height,
135 int channels, const struct ColorManagedViewSettings *view_settings,
136 const struct ColorManagedDisplaySettings *display_settings, bool predivide);
138 void IMB_display_buffer_release(void *cache_handle);
140 /* ** Display funcrions ** */
141 int IMB_colormanagement_display_get_named_index(const char *name);
142 const char *IMB_colormanagement_display_get_indexed_name(int index);
143 const char *IMB_colormanagement_display_get_default_name(void);
144 struct ColorManagedDisplay *IMB_colormanagement_display_get_named(const char *name);
145 const char *IMB_colormanagement_display_get_none_name(void);
147 /* ** View funcrions ** */
148 int IMB_colormanagement_view_get_named_index(const char *name);
149 const char *IMB_colormanagement_view_get_indexed_name(int index);
151 /* ** Look funcrions ** */
152 int IMB_colormanagement_look_get_named_index(const char *name);
153 const char *IMB_colormanagement_look_get_indexed_name(int index);
155 /* ** Color space functions ** */
156 int IMB_colormanagement_colorspace_get_named_index(const char *name);
157 const char *IMB_colormanagement_colorspace_get_indexed_name(int index);
158 const char *IMB_colormanagement_view_get_default_name(const char *display_name);
160 void IMB_colormanagment_colorspace_from_ibuf_ftype(struct ColorManagedColorspaceSettings *colorspace_settings, struct ImBuf *ibuf);
162 /* ** RNA helper functions ** */
163 void IMB_colormanagement_display_items_add(struct EnumPropertyItem **items, int *totitem);
164 void IMB_colormanagement_view_items_add(struct EnumPropertyItem **items, int *totitem, const char *display_name);
165 void IMB_colormanagement_look_items_add(struct EnumPropertyItem **items, int *totitem, const char *view_name);
166 void IMB_colormanagement_colorspace_items_add(struct EnumPropertyItem **items, int *totitem);
168 /* ** Tile-based buffer management ** */
169 void IMB_partial_display_buffer_update(struct ImBuf *ibuf, const float *linear_buffer, const unsigned char *buffer_byte,
170 int stride, int offset_x, int offset_y,
171 const struct ColorManagedViewSettings *view_settings,
172 const struct ColorManagedDisplaySettings *display_settings,
173 int xmin, int ymin, int xmax, int ymax,
174 bool copy_display_to_byte_buffer);
176 void IMB_partial_display_buffer_update_threaded(struct ImBuf *ibuf,
177 const float *linear_buffer,
178 const unsigned char *buffer_byte,
180 int offset_x, int offset_y,
181 const struct ColorManagedViewSettings *view_settings,
182 const struct ColorManagedDisplaySettings *display_settings,
183 int xmin, int ymin, int xmax, int ymax,
184 bool copy_display_to_byte_buffer);
186 void IMB_partial_display_buffer_update_delayed(struct ImBuf *ibuf, int xmin, int ymin, int xmax, int ymax);
188 /* ** Pixel processor functions ** */
189 struct ColormanageProcessor *IMB_colormanagement_display_processor_new(const struct ColorManagedViewSettings *view_settings,
190 const struct ColorManagedDisplaySettings *display_settings);
191 struct ColormanageProcessor *IMB_colormanagement_colorspace_processor_new(const char *from_colorspace, const char *to_colorspace);
192 void IMB_colormanagement_processor_apply_v4(struct ColormanageProcessor *cm_processor, float pixel[4]);
193 void IMB_colormanagement_processor_apply_v4_predivide(struct ColormanageProcessor *cm_processor, float pixel[4]);
194 void IMB_colormanagement_processor_apply_v3(struct ColormanageProcessor *cm_processor, float pixel[3]);
195 void IMB_colormanagement_processor_apply_pixel(struct ColormanageProcessor *cm_processor, float *pixel, int channels);
196 void IMB_colormanagement_processor_apply(struct ColormanageProcessor *cm_processor, float *buffer, int width, int height,
197 int channels, bool predivide);
198 void IMB_colormanagement_processor_apply_byte(struct ColormanageProcessor *cm_processor,
199 unsigned char *buffer, int width, int height, int channels);
200 void IMB_colormanagement_processor_free(struct ColormanageProcessor *cm_processor);
202 /* ** OpenGL drawing routines using GLSL for color space transform ** */
204 /* Test if GLSL drawing is supported for combination of graphics card and this configuration */
205 bool IMB_colormanagement_support_glsl_draw(const struct ColorManagedViewSettings *view_settings);
206 /* Configures GLSL shader for conversion from scene linear to display space */
207 bool IMB_colormanagement_setup_glsl_draw(const struct ColorManagedViewSettings *view_settings,
208 const struct ColorManagedDisplaySettings *display_settings,
209 float dither, bool predivide);
210 /* Same as above, but display space conversion happens from a specified space */
211 bool IMB_colormanagement_setup_glsl_draw_from_space(const struct ColorManagedViewSettings *view_settings,
212 const struct ColorManagedDisplaySettings *display_settings,
213 struct ColorSpace *colorspace,
214 float dither, bool predivide);
215 /* Same as setup_glsl_draw, but color management settings are guessing from a given context */
216 bool IMB_colormanagement_setup_glsl_draw_ctx(const struct bContext *C, float dither, bool predivide);
217 /* Same as setup_glsl_draw_from_space, but color management settings are guessing from a given context */
218 bool IMB_colormanagement_setup_glsl_draw_from_space_ctx(const struct bContext *C, struct ColorSpace *colorspace,
219 float dither, bool predivide);
220 /* Finish GLSL-based display space conversion */
221 void IMB_colormanagement_finish_glsl_draw(void);
225 COLOR_ROLE_SCENE_LINEAR = 0,
226 COLOR_ROLE_COLOR_PICKING,
227 COLOR_ROLE_TEXTURE_PAINTING,
228 COLOR_ROLE_DEFAULT_SEQUENCER,
229 COLOR_ROLE_DEFAULT_BYTE,
230 COLOR_ROLE_DEFAULT_FLOAT,
233 #include "intern/colormanagement_inline.c"
235 #endif /* __IMB_COLORMANAGEMENT_H__ */