09cdb3a4ee96eba8b69575a22b5f5765ae6f8373
[blender-staging.git] / source / blender / imbuf / IMB_colormanagement.h
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
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.
8  *
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.
13  *
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.
17  *
18  * The Original Code is Copyright (C) 2012 by Blender Foundation.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): Xavier Thomas,
24  *                 Lukas Toenne,
25  *                 Sergey Sharybin
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  *
29  */
30
31 #ifndef __IMB_COLORMANAGEMENT_H__
32 #define __IMB_COLORMANAGEMENT_H__
33
34 /** \file blender/imbuf/IMB_colormanagement.h
35  *  \ingroup imbuf
36  */
37
38 #include "BLI_sys_types.h"
39
40 #define BCM_CONFIG_FILE "config.ocio"
41
42 struct bContext;
43 struct ColorManagedColorspaceSettings;
44 struct ColorManagedDisplaySettings;
45 struct ColorManagedViewSettings;
46 struct ColormanageProcessor;
47 struct EnumPropertyItem;
48 struct ImBuf;
49 struct Main;
50 struct rcti;
51 struct PartialBufferUpdateContext;
52 struct wmWindow;
53 struct Scene;
54 struct ImageFormatData;
55
56 struct ColorSpace;
57 struct ColorManagedDisplay;
58
59 /* ** Generic functions ** */
60
61 void IMB_colormanagement_check_file_config(struct Main *bmain);
62
63 void IMB_colormanagement_validate_settings(struct ColorManagedDisplaySettings *display_settings,
64                                            struct ColorManagedViewSettings *view_settings);
65
66 const char *IMB_colormanagement_role_colorspace_name_get(int role);
67 void IMB_colormanagement_check_is_data(struct ImBuf *ibuf, const char *name);
68 void IMB_colormanagement_assign_float_colorspace(struct ImBuf *ibuf, const char *name);
69 void IMB_colormanagement_assign_rect_colorspace(struct ImBuf *ibuf, const char *name);
70
71 const char *IMB_colormanagement_get_float_colorspace(struct ImBuf *ibuf);
72 const char *IMB_colormanagement_get_rect_colorspace(struct ImBuf *ibuf);
73
74 /* ** Color space transformation functions ** */
75 void IMB_colormanagement_transform(float *buffer, int width, int height, int channels,
76                                    const char *from_colorspace, const char *to_colorspace, bool predivide);
77 void IMB_colormanagement_transform_threaded(float *buffer, int width, int height, int channels,
78                                             const char *from_colorspace, const char *to_colorspace, bool predivide);
79 void IMB_colormanagement_transform_v4(float pixel[4], const char *from_colorspace, const char *to_colorspace);
80
81 void IMB_colormanagement_colorspace_to_scene_linear_v3(float pixel[3], struct ColorSpace *colorspace);
82 void IMB_colormanagement_colorspace_to_scene_linear_v4(float pixel[4], bool predivide, struct ColorSpace *colorspace);
83
84 void IMB_colormanagement_scene_linear_to_colorspace_v3(float pixel[3], struct ColorSpace *colorspace);
85
86 void IMB_colormanagement_colorspace_to_scene_linear(float *buffer, int width, int height, int channels, struct ColorSpace *colorspace, bool predivide);
87
88 void IMB_colormanagement_scene_linear_to_display_v3(float pixel[3], struct ColorManagedDisplay *display);
89 void IMB_colormanagement_display_to_scene_linear_v3(float pixel[3], struct ColorManagedDisplay *display);
90
91 void IMB_colormanagement_pixel_to_display_space_v4(float result[4], const float pixel[4],  const struct ColorManagedViewSettings *view_settings,
92                                                    const struct ColorManagedDisplaySettings *display_settings);
93
94 void IMB_colormanagement_pixel_to_display_space_v3(float result[3], const float pixel[3],  const struct ColorManagedViewSettings *view_settings,
95                                                    const struct ColorManagedDisplaySettings *display_settings);
96
97 void IMB_colormanagement_imbuf_make_display_space(struct ImBuf *ibuf, const struct ColorManagedViewSettings *view_settings,
98                                                   const struct ColorManagedDisplaySettings *display_settings);
99
100 struct ImBuf *IMB_colormanagement_imbuf_for_write(struct ImBuf *ibuf, bool save_as_render, bool allocate_result,
101                                                   const struct ColorManagedViewSettings *view_settings,
102                                                   const struct ColorManagedDisplaySettings *display_settings,
103                                                   struct ImageFormatData *image_format_data);
104
105 void IMB_colormanagement_buffer_make_display_space(float *buffer, unsigned char *display_buffer,
106                                                    int width, int height, int channels, float dither,
107                                                    const struct ColorManagedViewSettings *view_settings,
108                                                    const struct ColorManagedDisplaySettings *display_settings);
109
110 /* ** Public display buffers interfaces ** */
111
112 void IMB_colormanagement_display_settings_from_ctx(const struct bContext *C,
113                                                    struct ColorManagedViewSettings **view_settings_r,
114                                                    struct ColorManagedDisplaySettings **display_settings_r);
115
116 unsigned char *IMB_display_buffer_acquire(struct ImBuf *ibuf, const struct ColorManagedViewSettings *view_settings,
117                                           const struct ColorManagedDisplaySettings *display_settings, void **cache_handle);
118 unsigned char *IMB_display_buffer_acquire_ctx(const struct bContext *C, struct ImBuf *ibuf, void **cache_handle);
119
120 void IMB_display_buffer_transform_apply(unsigned char *display_buffer, float *linear_buffer, int width, int height,
121                                         int channels, const struct ColorManagedViewSettings *view_settings,
122                                         const struct ColorManagedDisplaySettings *display_settings, bool predivide);
123
124 void IMB_display_buffer_release(void *cache_handle);
125
126 /* ** Display funcrions ** */
127 int IMB_colormanagement_display_get_named_index(const char *name);
128 const char *IMB_colormanagement_display_get_indexed_name(int index);
129 const char *IMB_colormanagement_display_get_default_name(void);
130 struct ColorManagedDisplay *IMB_colormanagement_display_get_named(const char *name);
131 const char *IMB_colormanagement_display_get_none_name(void);
132
133 /* ** View funcrions ** */
134 int IMB_colormanagement_view_get_named_index(const char *name);
135 const char *IMB_colormanagement_view_get_indexed_name(int index);
136
137 /* ** Look funcrions ** */
138 int IMB_colormanagement_look_get_named_index(const char *name);
139 const char *IMB_colormanagement_look_get_indexed_name(int index);
140
141 /* ** Color space functions ** */
142 int IMB_colormanagement_colorspace_get_named_index(const char *name);
143 const char *IMB_colormanagement_colorspace_get_indexed_name(int index);
144 const char *IMB_colormanagement_view_get_default_name(const char *display_name);
145
146 void IMB_colormanagment_colorspace_from_ibuf_ftype(struct ColorManagedColorspaceSettings *colorspace_settings, struct ImBuf *ibuf);
147
148 /* ** RNA helper functions ** */
149 void IMB_colormanagement_display_items_add(struct EnumPropertyItem **items, int *totitem);
150 void IMB_colormanagement_view_items_add(struct EnumPropertyItem **items, int *totitem, const char *display_name);
151 void IMB_colormanagement_look_items_add(struct EnumPropertyItem **items, int *totitem);
152 void IMB_colormanagement_colorspace_items_add(struct EnumPropertyItem **items, int *totitem);
153
154 /* ** Tile-based buffer management ** */
155 void IMB_partial_display_buffer_update(struct ImBuf *ibuf, const float *linear_buffer, const unsigned char *buffer_byte,
156                                        int stride, int offset_x, int offset_y, const struct ColorManagedViewSettings *view_settings,
157                                        const struct ColorManagedDisplaySettings *display_settings,
158                                        int xmin, int ymin, int xmax, int ymax,
159                                        bool update_orig_byte_buffer);
160
161 void IMB_partial_display_buffer_update_delayed(struct ImBuf *ibuf, int xmin, int ymin, int xmax, int ymax);
162
163 /* ** Pixel processor functions ** */
164 struct ColormanageProcessor *IMB_colormanagement_display_processor_new(const struct ColorManagedViewSettings *view_settings,
165                                                                        const struct ColorManagedDisplaySettings *display_settings);
166 struct ColormanageProcessor *IMB_colormanagement_colorspace_processor_new(const char *from_colorspace, const char *to_colorspace);
167 void IMB_colormanagement_processor_apply_v4(struct ColormanageProcessor *cm_processor, float pixel[4]);
168 void IMB_colormanagement_processor_apply_v4_predivide(struct ColormanageProcessor *cm_processor, float pixel[4]);
169 void IMB_colormanagement_processor_apply_v3(struct ColormanageProcessor *cm_processor, float pixel[3]);
170 void IMB_colormanagement_processor_apply(struct ColormanageProcessor *cm_processor, float *buffer, int width, int height,
171                                          int channels, bool predivide);
172 void IMB_colormanagement_processor_free(struct ColormanageProcessor *cm_processor);
173
174 /* ** OpenGL drawing routines using GLSL for color space transform ** */
175
176 /* Test if GLSL drawing is supported for combination of graphics card and this configuration */
177 bool IMB_colormanagement_support_glsl_draw(const struct ColorManagedViewSettings *view_settings);
178 /* Configures GLSL shader for conversion from scene linear to display space */
179 bool IMB_colormanagement_setup_glsl_draw(const struct ColorManagedViewSettings *view_settings,
180                                          const struct ColorManagedDisplaySettings *display_settings,
181                                          bool predivide);
182 /* Same as above, but display space conversion happens from a specified space */
183 bool IMB_colormanagement_setup_glsl_draw_from_space(const struct ColorManagedViewSettings *view_settings,
184                                                     const struct ColorManagedDisplaySettings *display_settings,
185                                                     struct ColorSpace *colorspace,
186                                                     bool predivide);
187 /* Same as setup_glsl_draw, but color management settings are guessing from a given context */
188 bool IMB_colormanagement_setup_glsl_draw_ctx(const struct bContext *C, bool predivide);
189 /* Same as setup_glsl_draw_from_space, but color management settings are guessing from a given context */
190 bool IMB_colormanagement_setup_glsl_draw_from_space_ctx(const struct bContext *C, struct ColorSpace *colorspace, bool predivide);
191 /* Finish GLSL-based display space conversion */
192 void IMB_colormanagement_finish_glsl_draw(void);
193
194 /* Roles */
195 enum {
196         COLOR_ROLE_SCENE_LINEAR = 0,
197         COLOR_ROLE_COLOR_PICKING,
198         COLOR_ROLE_TEXTURE_PAINTING,
199         COLOR_ROLE_DEFAULT_SEQUENCER,
200         COLOR_ROLE_DEFAULT_BYTE,
201         COLOR_ROLE_DEFAULT_FLOAT,
202 };
203
204 #endif  /* __IMB_COLORMANAGEMENT_H__ */