UVEdit: Add back uv angle stretch aspect correction
[blender.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 #include "BLI_compiler_compat.h"
40
41 #define BCM_CONFIG_FILE "config.ocio"
42
43
44 struct bContext;
45 struct ColorManagedColorspaceSettings;
46 struct ColorManagedDisplaySettings;
47 struct ColorManagedViewSettings;
48 struct ColormanageProcessor;
49 struct EnumPropertyItem;
50 struct ImBuf;
51 struct Main;
52 struct ImageFormatData;
53
54 struct ColorSpace;
55 struct ColorManagedDisplay;
56
57 /* ** Generic functions ** */
58
59 void IMB_colormanagement_check_file_config(struct Main *bmain);
60
61 void IMB_colormanagement_validate_settings(struct ColorManagedDisplaySettings *display_settings,
62                                            struct ColorManagedViewSettings *view_settings);
63
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);
68
69 const char *IMB_colormanagement_get_float_colorspace(struct ImBuf *ibuf);
70 const char *IMB_colormanagement_get_rect_colorspace(struct ImBuf *ibuf);
71
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]);
74 BLI_INLINE void IMB_colormangement_xyz_to_rgb(float rgb[3], const float xyz[3]);
75 BLI_INLINE void IMB_colormangement_rgb_to_xyz(float xyz[3], const float rgb[3]);
76
77 /* ** Color space transformation functions ** */
78 void IMB_colormanagement_transform(float *buffer, int width, int height, int channels,
79                                    const char *from_colorspace, const char *to_colorspace, bool predivide);
80 void IMB_colormanagement_transform_threaded(float *buffer, int width, int height, int channels,
81                                             const char *from_colorspace, const char *to_colorspace, bool predivide);
82 void IMB_colormanagement_transform_byte(unsigned char *buffer, int width, int height, int channels,
83                                         const char *from_colorspace, const char *to_colorspace);
84 void IMB_colormanagement_transform_byte_threaded(unsigned char *buffer, int width, int height, int channels,
85                                                  const char *from_colorspace, const char *to_colorspace);
86 void IMB_colormanagement_transform_from_byte(float *float_buffer, unsigned char *byte_buffer,
87                                              int width, int height, int channels,
88                                              const char *from_colorspace, const char *to_colorspace);
89 void IMB_colormanagement_transform_from_byte_threaded(float *float_buffer, unsigned char *byte_buffer,
90                                                       int width, int height, int channels,
91                                                       const char *from_colorspace, const char *to_colorspace);
92 void IMB_colormanagement_transform_v4(float pixel[4], const char *from_colorspace, const char *to_colorspace);
93
94 void IMB_colormanagement_colorspace_to_scene_linear_v3(float pixel[3], struct ColorSpace *colorspace);
95 void IMB_colormanagement_colorspace_to_scene_linear_v4(float pixel[4], bool predivide, struct ColorSpace *colorspace);
96
97 void IMB_colormanagement_scene_linear_to_colorspace_v3(float pixel[3], struct ColorSpace *colorspace);
98
99 void IMB_colormanagement_colorspace_to_scene_linear(float *buffer, int width, int height, int channels, struct ColorSpace *colorspace, bool predivide);
100
101 void IMB_colormanagement_scene_linear_to_color_picking_v3(float pixel[3]);
102 void IMB_colormanagement_color_picking_to_scene_linear_v3(float pixel[3]);
103
104 void IMB_colormanagement_scene_linear_to_srgb_v3(float pixel[3]);
105 void IMB_colormanagement_srgb_to_scene_linear_v3(float pixel[3]);
106
107 void IMB_colormanagement_scene_linear_to_display_v3(float pixel[3], struct ColorManagedDisplay *display);
108 void IMB_colormanagement_display_to_scene_linear_v3(float pixel[3], struct ColorManagedDisplay *display);
109
110 void IMB_colormanagement_pixel_to_display_space_v4(float result[4], const float pixel[4],  const struct ColorManagedViewSettings *view_settings,
111                                                    const struct ColorManagedDisplaySettings *display_settings);
112
113 void IMB_colormanagement_pixel_to_display_space_v3(float result[3], const float pixel[3],  const struct ColorManagedViewSettings *view_settings,
114                                                    const struct ColorManagedDisplaySettings *display_settings);
115
116 void IMB_colormanagement_imbuf_make_display_space(struct ImBuf *ibuf, const struct ColorManagedViewSettings *view_settings,
117                                                   const struct ColorManagedDisplaySettings *display_settings);
118
119 struct ImBuf *IMB_colormanagement_imbuf_for_write(struct ImBuf *ibuf, bool save_as_render, bool allocate_result,
120                                                   const struct ColorManagedViewSettings *view_settings,
121                                                   const struct ColorManagedDisplaySettings *display_settings,
122                                                   struct ImageFormatData *image_format_data);
123
124 void IMB_colormanagement_buffer_make_display_space(float *buffer, unsigned char *display_buffer,
125                                                    int width, int height, int channels, float dither,
126                                                    const struct ColorManagedViewSettings *view_settings,
127                                                    const struct ColorManagedDisplaySettings *display_settings);
128
129 /* ** Public display buffers interfaces ** */
130
131 void IMB_colormanagement_display_settings_from_ctx(const struct bContext *C,
132                                                    struct ColorManagedViewSettings **view_settings_r,
133                                                    struct ColorManagedDisplaySettings **display_settings_r);
134
135 const char *IMB_colormanagement_get_display_colorspace_name(const struct ColorManagedViewSettings *view_settings,
136                                                             const struct ColorManagedDisplaySettings *display_settings);
137
138 unsigned char *IMB_display_buffer_acquire(struct ImBuf *ibuf, const struct ColorManagedViewSettings *view_settings,
139                                           const struct ColorManagedDisplaySettings *display_settings, void **cache_handle);
140 unsigned char *IMB_display_buffer_acquire_ctx(const struct bContext *C, struct ImBuf *ibuf, void **cache_handle);
141
142 void IMB_display_buffer_transform_apply(unsigned char *display_buffer, float *linear_buffer, int width, int height,
143                                         int channels, const struct ColorManagedViewSettings *view_settings,
144                                         const struct ColorManagedDisplaySettings *display_settings, bool predivide);
145
146 void IMB_display_buffer_release(void *cache_handle);
147
148 /* ** Display functions ** */
149 int IMB_colormanagement_display_get_named_index(const char *name);
150 const char *IMB_colormanagement_display_get_indexed_name(int index);
151 const char *IMB_colormanagement_display_get_default_name(void);
152 struct ColorManagedDisplay *IMB_colormanagement_display_get_named(const char *name);
153 const char *IMB_colormanagement_display_get_none_name(void);
154 const char *IMB_colormanagement_display_get_default_view_transform_name(
155         struct ColorManagedDisplay *display);
156
157 /* ** View functions ** */
158 int IMB_colormanagement_view_get_named_index(const char *name);
159 const char *IMB_colormanagement_view_get_indexed_name(int index);
160
161 /* ** Look functions ** */
162 int IMB_colormanagement_look_get_named_index(const char *name);
163 const char *IMB_colormanagement_look_get_indexed_name(int index);
164
165 /* ** Color space functions ** */
166 int IMB_colormanagement_colorspace_get_named_index(const char *name);
167 const char *IMB_colormanagement_colorspace_get_indexed_name(int index);
168 const char *IMB_colormanagement_view_get_default_name(const char *display_name);
169
170 void IMB_colormanagement_colorspace_from_ibuf_ftype(struct ColorManagedColorspaceSettings *colorspace_settings, struct ImBuf *ibuf);
171
172 /* ** RNA helper functions ** */
173 void IMB_colormanagement_display_items_add(struct EnumPropertyItem **items, int *totitem);
174 void IMB_colormanagement_view_items_add(struct EnumPropertyItem **items, int *totitem, const char *display_name);
175 void IMB_colormanagement_look_items_add(struct EnumPropertyItem **items, int *totitem, const char *view_name);
176 void IMB_colormanagement_colorspace_items_add(struct EnumPropertyItem **items, int *totitem);
177
178 /* ** Tile-based buffer management ** */
179 void IMB_partial_display_buffer_update(struct ImBuf *ibuf, const float *linear_buffer, const unsigned char *buffer_byte,
180                                        int stride, 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);
185
186 void IMB_partial_display_buffer_update_threaded(struct ImBuf *ibuf,
187                                                 const float *linear_buffer,
188                                                 const unsigned char *buffer_byte,
189                                                 int stride,
190                                                 int offset_x, int offset_y,
191                                                 const struct ColorManagedViewSettings *view_settings,
192                                                 const struct ColorManagedDisplaySettings *display_settings,
193                                                 int xmin, int ymin, int xmax, int ymax,
194                                                 bool copy_display_to_byte_buffer);
195
196 void IMB_partial_display_buffer_update_delayed(struct ImBuf *ibuf, int xmin, int ymin, int xmax, int ymax);
197
198 /* ** Pixel processor functions ** */
199 struct ColormanageProcessor *IMB_colormanagement_display_processor_new(const struct ColorManagedViewSettings *view_settings,
200                                                                        const struct ColorManagedDisplaySettings *display_settings);
201 struct ColormanageProcessor *IMB_colormanagement_colorspace_processor_new(const char *from_colorspace, const char *to_colorspace);
202 void IMB_colormanagement_processor_apply_v4(struct ColormanageProcessor *cm_processor, float pixel[4]);
203 void IMB_colormanagement_processor_apply_v4_predivide(struct ColormanageProcessor *cm_processor, float pixel[4]);
204 void IMB_colormanagement_processor_apply_v3(struct ColormanageProcessor *cm_processor, float pixel[3]);
205 void IMB_colormanagement_processor_apply_pixel(struct ColormanageProcessor *cm_processor, float *pixel, int channels);
206 void IMB_colormanagement_processor_apply(struct ColormanageProcessor *cm_processor, float *buffer, int width, int height,
207                                          int channels, bool predivide);
208 void IMB_colormanagement_processor_apply_byte(struct ColormanageProcessor *cm_processor,
209                                               unsigned char *buffer, int width, int height, int channels);
210 void IMB_colormanagement_processor_free(struct ColormanageProcessor *cm_processor);
211
212 /* ** OpenGL drawing routines using GLSL for color space transform ** */
213
214 /* Test if GLSL drawing is supported for combination of graphics card and this configuration */
215 bool IMB_colormanagement_support_glsl_draw(const struct ColorManagedViewSettings *view_settings);
216 /* Configures GLSL shader for conversion from scene linear to display space */
217 bool IMB_colormanagement_setup_glsl_draw(const struct ColorManagedViewSettings *view_settings,
218                                          const struct ColorManagedDisplaySettings *display_settings,
219                                          float dither, bool predivide);
220 /* Same as above, but display space conversion happens from a specified space */
221 bool IMB_colormanagement_setup_glsl_draw_from_space(const struct ColorManagedViewSettings *view_settings,
222                                                     const struct ColorManagedDisplaySettings *display_settings,
223                                                     struct ColorSpace *colorspace,
224                                                     float dither, bool predivide);
225 /* Same as setup_glsl_draw, but color management settings are guessing from a given context */
226 bool IMB_colormanagement_setup_glsl_draw_ctx(const struct bContext *C, float dither, bool predivide);
227 /* Same as setup_glsl_draw_from_space, but color management settings are guessing from a given context */
228 bool IMB_colormanagement_setup_glsl_draw_from_space_ctx(const struct bContext *C, struct ColorSpace *colorspace,
229                                                         float dither, bool predivide);
230 /* Finish GLSL-based display space conversion */
231 void IMB_colormanagement_finish_glsl_draw(void);
232
233 /* ** View transform ** */
234 void IMB_colormanagement_init_default_view_settings(
235         struct ColorManagedViewSettings *view_settings,
236         const struct ColorManagedDisplaySettings *display_settings);
237
238 /* Roles */
239 enum {
240         COLOR_ROLE_SCENE_LINEAR = 0,
241         COLOR_ROLE_COLOR_PICKING,
242         COLOR_ROLE_TEXTURE_PAINTING,
243         COLOR_ROLE_DEFAULT_SEQUENCER,
244         COLOR_ROLE_DEFAULT_BYTE,
245         COLOR_ROLE_DEFAULT_FLOAT,
246 };
247
248 #include "intern/colormanagement_inline.c"
249
250 #endif  /* __IMB_COLORMANAGEMENT_H__ */