Merge branch 'blender2.7'
[blender.git] / source / blender / imbuf / IMB_colormanagement.h
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2012 by Blender Foundation.
17  * All rights reserved.
18  */
19
20 #ifndef __IMB_COLORMANAGEMENT_H__
21 #define __IMB_COLORMANAGEMENT_H__
22
23 /** \file \ingroup imbuf
24  */
25
26 #include "BLI_sys_types.h"
27 #include "BLI_compiler_compat.h"
28
29 #define BCM_CONFIG_FILE "config.ocio"
30
31
32 struct ColorManagedColorspaceSettings;
33 struct ColorManagedDisplaySettings;
34 struct ColorManagedViewSettings;
35 struct ColormanageProcessor;
36 struct EnumPropertyItem;
37 struct ImBuf;
38 struct ImageFormatData;
39 struct Main;
40 struct bContext;
41
42 struct ColorManagedDisplay;
43 struct ColorSpace;
44
45 /* ** Generic functions ** */
46
47 void IMB_colormanagement_check_file_config(struct Main *bmain);
48
49 void IMB_colormanagement_validate_settings(const struct ColorManagedDisplaySettings *display_settings,
50                                            struct ColorManagedViewSettings *view_settings);
51
52 const char *IMB_colormanagement_role_colorspace_name_get(int role);
53 void IMB_colormanagement_check_is_data(struct ImBuf *ibuf, const char *name);
54 void IMB_colormanagement_assign_float_colorspace(struct ImBuf *ibuf, const char *name);
55 void IMB_colormanagement_assign_rect_colorspace(struct ImBuf *ibuf, const char *name);
56
57 const char *IMB_colormanagement_get_float_colorspace(struct ImBuf *ibuf);
58 const char *IMB_colormanagement_get_rect_colorspace(struct ImBuf *ibuf);
59
60 BLI_INLINE float IMB_colormanagement_get_luminance(const float rgb[3]);
61 BLI_INLINE unsigned char IMB_colormanagement_get_luminance_byte(const unsigned char[3]);
62 BLI_INLINE void IMB_colormangement_xyz_to_rgb(float rgb[3], const float xyz[3]);
63 BLI_INLINE void IMB_colormangement_rgb_to_xyz(float xyz[3], const float rgb[3]);
64
65 /* ** Color space transformation functions ** */
66 void IMB_colormanagement_transform(float *buffer, int width, int height, int channels,
67                                    const char *from_colorspace, const char *to_colorspace, bool predivide);
68 void IMB_colormanagement_transform_threaded(float *buffer, int width, int height, int channels,
69                                             const char *from_colorspace, const char *to_colorspace, bool predivide);
70 void IMB_colormanagement_transform_byte(unsigned char *buffer, int width, int height, int channels,
71                                         const char *from_colorspace, const char *to_colorspace);
72 void IMB_colormanagement_transform_byte_threaded(unsigned char *buffer, int width, int height, int channels,
73                                                  const char *from_colorspace, const char *to_colorspace);
74 void IMB_colormanagement_transform_from_byte(float *float_buffer, unsigned char *byte_buffer,
75                                              int width, int height, int channels,
76                                              const char *from_colorspace, const char *to_colorspace);
77 void IMB_colormanagement_transform_from_byte_threaded(float *float_buffer, unsigned char *byte_buffer,
78                                                       int width, int height, int channels,
79                                                       const char *from_colorspace, const char *to_colorspace);
80 void IMB_colormanagement_transform_v4(float pixel[4], const char *from_colorspace, const char *to_colorspace);
81
82 void IMB_colormanagement_colorspace_to_scene_linear_v3(float pixel[3], struct ColorSpace *colorspace);
83 void IMB_colormanagement_colorspace_to_scene_linear_v4(float pixel[4], bool predivide, struct ColorSpace *colorspace);
84
85 void IMB_colormanagement_scene_linear_to_colorspace_v3(float pixel[3], struct ColorSpace *colorspace);
86
87 void IMB_colormanagement_colorspace_to_scene_linear(float *buffer, int width, int height, int channels, struct ColorSpace *colorspace, bool predivide);
88
89 void IMB_colormanagement_scene_linear_to_color_picking_v3(float pixel[3]);
90 void IMB_colormanagement_color_picking_to_scene_linear_v3(float pixel[3]);
91
92 void IMB_colormanagement_scene_linear_to_srgb_v3(float pixel[3]);
93 void IMB_colormanagement_srgb_to_scene_linear_v3(float pixel[3]);
94
95 void IMB_colormanagement_scene_linear_to_display_v3(float pixel[3], struct ColorManagedDisplay *display);
96 void IMB_colormanagement_display_to_scene_linear_v3(float pixel[3], struct ColorManagedDisplay *display);
97
98 void IMB_colormanagement_pixel_to_display_space_v4(float result[4], const float pixel[4],  const struct ColorManagedViewSettings *view_settings,
99                                                    const struct ColorManagedDisplaySettings *display_settings);
100
101 void IMB_colormanagement_pixel_to_display_space_v3(float result[3], const float pixel[3],  const struct ColorManagedViewSettings *view_settings,
102                                                    const struct ColorManagedDisplaySettings *display_settings);
103
104 void IMB_colormanagement_imbuf_make_display_space(struct ImBuf *ibuf, const struct ColorManagedViewSettings *view_settings,
105                                                   const struct ColorManagedDisplaySettings *display_settings);
106
107 struct ImBuf *IMB_colormanagement_imbuf_for_write(struct ImBuf *ibuf, bool save_as_render, bool allocate_result,
108                                                   const struct ColorManagedViewSettings *view_settings,
109                                                   const struct ColorManagedDisplaySettings *display_settings,
110                                                   struct ImageFormatData *image_format_data);
111
112 void IMB_colormanagement_buffer_make_display_space(float *buffer, unsigned char *display_buffer,
113                                                    int width, int height, int channels, float dither,
114                                                    const struct ColorManagedViewSettings *view_settings,
115                                                    const struct ColorManagedDisplaySettings *display_settings);
116
117 /* ** Public display buffers interfaces ** */
118
119 void IMB_colormanagement_display_settings_from_ctx(const struct bContext *C,
120                                                    struct ColorManagedViewSettings **view_settings_r,
121                                                    struct ColorManagedDisplaySettings **display_settings_r);
122
123 const char *IMB_colormanagement_get_display_colorspace_name(const struct ColorManagedViewSettings *view_settings,
124                                                             const struct ColorManagedDisplaySettings *display_settings);
125
126 unsigned char *IMB_display_buffer_acquire(struct ImBuf *ibuf, const struct ColorManagedViewSettings *view_settings,
127                                           const struct ColorManagedDisplaySettings *display_settings, void **cache_handle);
128 unsigned char *IMB_display_buffer_acquire_ctx(const struct bContext *C, struct ImBuf *ibuf, void **cache_handle);
129
130 void IMB_display_buffer_transform_apply(unsigned char *display_buffer, float *linear_buffer, int width, int height,
131                                         int channels, const struct ColorManagedViewSettings *view_settings,
132                                         const struct ColorManagedDisplaySettings *display_settings, bool predivide);
133
134 void IMB_display_buffer_release(void *cache_handle);
135
136 /* ** Display functions ** */
137 int IMB_colormanagement_display_get_named_index(const char *name);
138 const char *IMB_colormanagement_display_get_indexed_name(int index);
139 const char *IMB_colormanagement_display_get_default_name(void);
140 struct ColorManagedDisplay *IMB_colormanagement_display_get_named(const char *name);
141 const char *IMB_colormanagement_display_get_none_name(void);
142 const char *IMB_colormanagement_display_get_default_view_transform_name(
143         struct ColorManagedDisplay *display);
144
145 /* ** View functions ** */
146 int IMB_colormanagement_view_get_named_index(const char *name);
147 const char *IMB_colormanagement_view_get_indexed_name(int index);
148
149 /* ** Look functions ** */
150 int IMB_colormanagement_look_get_named_index(const char *name);
151 const char *IMB_colormanagement_look_get_indexed_name(int index);
152
153 /* ** Color space functions ** */
154 int IMB_colormanagement_colorspace_get_named_index(const char *name);
155 const char *IMB_colormanagement_colorspace_get_indexed_name(int index);
156 const char *IMB_colormanagement_view_get_default_name(const char *display_name);
157
158 void IMB_colormanagement_colorspace_from_ibuf_ftype(struct ColorManagedColorspaceSettings *colorspace_settings, struct ImBuf *ibuf);
159
160 /* ** RNA helper functions ** */
161 void IMB_colormanagement_display_items_add(struct EnumPropertyItem **items, int *totitem);
162 void IMB_colormanagement_view_items_add(struct EnumPropertyItem **items, int *totitem, const char *display_name);
163 void IMB_colormanagement_look_items_add(struct EnumPropertyItem **items, int *totitem, const char *view_name);
164 void IMB_colormanagement_colorspace_items_add(struct EnumPropertyItem **items, int *totitem);
165
166 /* ** Tile-based buffer management ** */
167 void IMB_partial_display_buffer_update(struct ImBuf *ibuf, const float *linear_buffer, const unsigned char *buffer_byte,
168                                        int stride, int offset_x, int offset_y,
169                                        const struct ColorManagedViewSettings *view_settings,
170                                        const struct ColorManagedDisplaySettings *display_settings,
171                                        int xmin, int ymin, int xmax, int ymax,
172                                        bool copy_display_to_byte_buffer);
173
174 void IMB_partial_display_buffer_update_threaded(struct ImBuf *ibuf,
175                                                 const float *linear_buffer,
176                                                 const unsigned char *buffer_byte,
177                                                 int stride,
178                                                 int offset_x, int offset_y,
179                                                 const struct ColorManagedViewSettings *view_settings,
180                                                 const struct ColorManagedDisplaySettings *display_settings,
181                                                 int xmin, int ymin, int xmax, int ymax,
182                                                 bool copy_display_to_byte_buffer);
183
184 void IMB_partial_display_buffer_update_delayed(struct ImBuf *ibuf, int xmin, int ymin, int xmax, int ymax);
185
186 /* ** Pixel processor functions ** */
187 struct ColormanageProcessor *IMB_colormanagement_display_processor_new(const struct ColorManagedViewSettings *view_settings,
188                                                                        const struct ColorManagedDisplaySettings *display_settings);
189 struct ColormanageProcessor *IMB_colormanagement_colorspace_processor_new(const char *from_colorspace, const char *to_colorspace);
190 void IMB_colormanagement_processor_apply_v4(struct ColormanageProcessor *cm_processor, float pixel[4]);
191 void IMB_colormanagement_processor_apply_v4_predivide(struct ColormanageProcessor *cm_processor, float pixel[4]);
192 void IMB_colormanagement_processor_apply_v3(struct ColormanageProcessor *cm_processor, float pixel[3]);
193 void IMB_colormanagement_processor_apply_pixel(struct ColormanageProcessor *cm_processor, float *pixel, int channels);
194 void IMB_colormanagement_processor_apply(struct ColormanageProcessor *cm_processor, float *buffer, int width, int height,
195                                          int channels, bool predivide);
196 void IMB_colormanagement_processor_apply_byte(struct ColormanageProcessor *cm_processor,
197                                               unsigned char *buffer, int width, int height, int channels);
198 void IMB_colormanagement_processor_free(struct ColormanageProcessor *cm_processor);
199
200 /* ** OpenGL drawing routines using GLSL for color space transform ** */
201
202 /* Test if GLSL drawing is supported for combination of graphics card and this configuration */
203 bool IMB_colormanagement_support_glsl_draw(const struct ColorManagedViewSettings *view_settings);
204 /* Configures GLSL shader for conversion from scene linear to display space */
205 bool IMB_colormanagement_setup_glsl_draw(const struct ColorManagedViewSettings *view_settings,
206                                          const struct ColorManagedDisplaySettings *display_settings,
207                                          float dither, bool predivide);
208 /* Same as above, but display space conversion happens from a specified space */
209 bool IMB_colormanagement_setup_glsl_draw_from_space(const struct ColorManagedViewSettings *view_settings,
210                                                     const struct ColorManagedDisplaySettings *display_settings,
211                                                     struct ColorSpace *colorspace,
212                                                     float dither, bool predivide);
213 /* Same as setup_glsl_draw, but color management settings are guessing from a given context */
214 bool IMB_colormanagement_setup_glsl_draw_ctx(const struct bContext *C, float dither, bool predivide);
215 /* Same as setup_glsl_draw_from_space, but color management settings are guessing from a given context */
216 bool IMB_colormanagement_setup_glsl_draw_from_space_ctx(const struct bContext *C, struct ColorSpace *colorspace,
217                                                         float dither, bool predivide);
218 /* Finish GLSL-based display space conversion */
219 void IMB_colormanagement_finish_glsl_draw(void);
220
221 /* ** View transform ** */
222 void IMB_colormanagement_init_default_view_settings(
223         struct ColorManagedViewSettings *view_settings,
224         const struct ColorManagedDisplaySettings *display_settings);
225
226 /* Roles */
227 enum {
228         COLOR_ROLE_SCENE_LINEAR = 0,
229         COLOR_ROLE_COLOR_PICKING,
230         COLOR_ROLE_TEXTURE_PAINTING,
231         COLOR_ROLE_DEFAULT_SEQUENCER,
232         COLOR_ROLE_DEFAULT_BYTE,
233         COLOR_ROLE_DEFAULT_FLOAT,
234 };
235
236 #include "intern/colormanagement_inline.c"
237
238 #endif  /* __IMB_COLORMANAGEMENT_H__ */