Color Management, Stage 2: Switch color pipeline to use OpenColorIO
[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 #define BCM_CONFIG_FILE "config.ocio"
35
36 struct bContext;
37 struct ColorManagedColorspaceSettings;
38 struct ColorManagedDisplaySettings;
39 struct ColorManagedViewSettings;
40 struct ColormanageProcessor;
41 struct EnumPropertyItem;
42 struct ImBuf;
43 struct Main;
44 struct rcti;
45 struct PartialBufferUpdateContext;
46 struct wmWindow;
47 struct Scene;
48
49 struct ColorSpace;
50 struct ColorManagedDisplay;
51
52 /* ** Initialization / De-initialization ** */
53
54 void IMB_colormanagement_init(void);
55 void IMB_colormanagement_exit(void);
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
66 /* ** Color space transformation functions ** */
67 void IMB_colormanagement_transform(float *buffer, int width, int height, int channels,
68                                    const char *from_colorspace, const char *to_colorspace, int predivide);
69 void IMB_colormanagement_transform_threaded(float *buffer, int width, int height, int channels,
70                                             const char *from_colorspace, const char *to_colorspace, int predivide);
71 void IMB_colormanagement_transform_v4(float pixel[4], const char *from_colorspace, const char *to_colorspace);
72
73 void IMB_colormanagement_colorspace_to_scene_linear_v3(float pixel[3], struct ColorSpace *colorspace);
74 void IMB_colormanagement_scene_linear_to_colorspace_v3(float pixel[3], struct ColorSpace *colorspace);
75
76 void IMB_colormanagement_colorspace_to_scene_linear(float *buffer, int width, int height, int channels, struct ColorSpace *colorspace, int predivide);
77
78 void IMB_colormanagement_scene_linear_to_display_v3(float pixel[3], struct ColorManagedDisplay *display);
79 void IMB_colormanagement_display_to_scene_linear_v3(float pixel[3], struct ColorManagedDisplay *display);
80
81 void IMB_colormanagement_pixel_to_display_space_v4(float result[4], const float pixel[4],  const struct ColorManagedViewSettings *view_settings,
82                                                    const struct ColorManagedDisplaySettings *display_settings);
83
84 void IMB_colormanagement_pixel_to_display_space_v3(float result[3], const float pixel[3],  const struct ColorManagedViewSettings *view_settings,
85                                                    const struct ColorManagedDisplaySettings *display_settings);
86
87 void IMB_colormanagement_imbuf_assign_float_space(struct ImBuf *ibuf, struct ColorManagedColorspaceSettings *colorspace_settings);
88
89 void IMB_colormanagement_imbuf_make_display_space(struct ImBuf *ibuf, const struct ColorManagedViewSettings *view_settings,
90                                                   const struct ColorManagedDisplaySettings *display_settings);
91
92 /* ** Public display buffers interfaces ** */
93
94 unsigned char *IMB_display_buffer_acquire(struct ImBuf *ibuf, const struct ColorManagedViewSettings *view_settings,
95                                           const struct ColorManagedDisplaySettings *display_settings, void **cache_handle);
96 unsigned char *IMB_display_buffer_acquire_ctx(const struct bContext *C, struct ImBuf *ibuf, void **cache_handle);
97
98 void IMB_display_buffer_to_imbuf_rect(struct ImBuf *ibuf, const struct ColorManagedViewSettings *view_settings,
99                                       const struct ColorManagedDisplaySettings *display_settings);
100
101 void IMB_display_buffer_transform_apply(unsigned char *display_buffer, float *linear_buffer, int width, int height,
102                                         int channels, const struct ColorManagedViewSettings *view_settings,
103                                         const struct ColorManagedDisplaySettings *display_settings, int predivide);
104
105 void IMB_display_buffer_release(void *cache_handle);
106
107 /* ** Display funcrions ** */
108 int IMB_colormanagement_display_get_named_index(const char *name);
109 const char *IMB_colormanagement_display_get_indexed_name(int index);
110 const char *IMB_colormanagement_display_get_default_name(void);
111 struct ColorManagedDisplay *IMB_colormanagement_display_get_named(const char *name);
112
113 /* ** View funcrions ** */
114 int IMB_colormanagement_view_get_named_index(const char *name);
115 const char *IMB_colormanagement_view_get_indexed_name(int index);
116
117 /* ** Color space functions ** */
118 int IMB_colormanagement_colorspace_get_named_index(const char *name);
119 const char *IMB_colormanagement_colorspace_get_indexed_name(int index);
120 const char *IMB_colormanagement_view_get_default_name(const char *display_name);
121
122 void IMB_colormanagment_colorspace_from_ibuf_ftype(struct ColorManagedColorspaceSettings *colorspace_settings, struct ImBuf *ibuf);
123
124 /* ** RNA helper functions ** */
125 void IMB_colormanagement_display_items_add(struct EnumPropertyItem **items, int *totitem);
126 void IMB_colormanagement_view_items_add(struct EnumPropertyItem **items, int *totitem, const char *display_name);
127 void IMB_colormanagement_colorspace_items_add(struct EnumPropertyItem **items, int *totitem);
128
129 /* ** Tile-based buffer management ** */
130 void IMB_partial_display_buffer_update(struct ImBuf *ibuf, const float *linear_buffer, const unsigned char *buffer_byte,
131                                        int stride, int offset_x, int offset_y, const struct ColorManagedViewSettings *view_settings,
132                                        const struct ColorManagedDisplaySettings *display_settings,
133                                        int xmin, int ymin, int xmax, int ymax);
134
135 /* ** Pixel processor functions ** */
136 struct ColormanageProcessor *IMB_colormanagement_display_processor_new(const struct ColorManagedViewSettings *view_settings,
137                                                                        const struct ColorManagedDisplaySettings *display_settings);
138 struct ColormanageProcessor *IMB_colormanagement_colorspace_processor_new(const char *from_colorspace, const char *to_colorspace);
139 void IMB_colormanagement_processor_apply_v4(struct ColormanageProcessor *cm_processor, float pixel[4]);
140 void IMB_colormanagement_processor_apply_v3(struct ColormanageProcessor *cm_processor, float pixel[3]);
141 void IMB_colormanagement_processor_apply(struct ColormanageProcessor *cm_processor, float *buffer, int width, int height,
142                                          int channels, int predivide);
143 void IMB_colormanagement_processor_free(struct ColormanageProcessor *cm_processor);
144
145 /* Roles */
146 enum {
147         COLOR_ROLE_SCENE_LINEAR = 0,
148         COLOR_ROLE_COLOR_PICKING,
149         COLOR_ROLE_TEXTURE_PAINTING,
150         COLOR_ROLE_DEFAULT_SEQUENCER,
151         COLOR_ROLE_DEFAULT_BYTE,
152         COLOR_ROLE_DEFAULT_FLOAT,
153 };
154
155 #endif  /* IMB_COLORMANAGEMENT_H */