Color Management: made OpenColorIO transformations aware of color unpremultiply
[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 EnumPropertyItem;
41 struct ImBuf;
42 struct Main;
43 struct rcti;
44 struct PartialBufferUpdateContext;
45 struct wmWindow;
46 struct Scene;
47
48 /* ** Initialization / De-initialization ** */
49
50 void IMB_colormanagement_init(void);
51 void IMB_colormanagement_exit(void);
52
53 /* ** Generic functions ** */
54
55 void IMB_colormanagement_check_file_config(struct Main *bmain);
56
57 void IMB_colormanagement_validate_settings(struct ColorManagedDisplaySettings *display_settings,
58                                            struct ColorManagedViewSettings *view_settings);
59
60 /* ** Color space transformation functions ** */
61 void IMB_colormanagement_colorspace_transform(float *buffer, int width, int height, int channels,
62                                               const char *from_colorspace, const char *to_colorspace,
63                                               int predivide);
64
65 void IMB_colormanagement_pixel_to_role(float pixel[4], int role);
66 void IMB_colormanagement_pixel_from_role(float pixel[4], int role);
67
68 void IMB_colormanagement_imbuf_to_role(struct ImBuf *ibuf, int role);
69 void IMB_colormanagement_imbuf_from_role(struct ImBuf *ibuf, int role);
70
71 void IMB_colormanagement_imbuf_make_scene_linear(struct ImBuf *ibuf, struct ColorManagedColorspaceSettings *colorspace_settings);
72
73 void IMB_colormanagement_imbuf_make_display_space(struct ImBuf *ibuf, const struct ColorManagedViewSettings *view_settings,
74                                                   const struct ColorManagedDisplaySettings *display_settings);
75
76 /* ** Public display buffers interfaces ** */
77
78 void IMB_colormanage_cache_free(struct ImBuf *ibuf);
79
80 unsigned char *IMB_display_buffer_acquire(struct ImBuf *ibuf, const struct ColorManagedViewSettings *view_settings,
81                                           const struct ColorManagedDisplaySettings *display_settings, void **cache_handle);
82 unsigned char *IMB_display_buffer_acquire_ctx(const struct bContext *C, struct ImBuf *ibuf, void **cache_handle);
83
84 void IMB_display_buffer_pixel(float result[4], const float pixel[4],  const struct ColorManagedViewSettings *view_settings,
85                               const struct ColorManagedDisplaySettings *display_settings);
86
87 void IMB_display_buffer_to_imbuf_rect(struct ImBuf *ibuf, const struct ColorManagedViewSettings *view_settings,
88                                       const struct ColorManagedDisplaySettings *display_settings);
89
90 void IMB_display_buffer_release(void *cache_handle);
91
92 void IMB_display_buffer_invalidate(struct ImBuf *ibuf);
93
94 /* ** Display funcrions ** */
95 int IMB_colormanagement_display_get_named_index(const char *name);
96 const char *IMB_colormanagement_display_get_indexed_name(int index);
97 const char *IMB_colormanagement_display_get_default_name(void);
98
99 /* ** View funcrions ** */
100 int IMB_colormanagement_view_get_named_index(const char *name);
101 const char *IMB_colormanagement_view_get_indexed_name(int index);
102
103 /* ** Color space functions ** */
104 int IMB_colormanagement_colorspace_get_named_index(const char *name);
105 const char *IMB_colormanagement_colorspace_get_indexed_name(int index);
106
107 /* ** RNA helper functions ** */
108 void IMB_colormanagement_display_items_add(struct EnumPropertyItem **items, int *totitem);
109 void IMB_colormanagement_view_items_add(struct EnumPropertyItem **items, int *totitem, const char *display_name);
110 void IMB_colormanagement_colorspace_items_add(struct EnumPropertyItem **items, int *totitem);
111
112 /* ** Tile-based buffer management ** */
113 void IMB_partial_display_buffer_update(struct ImBuf *ibuf, const float *linear_buffer,
114                                        int stride, int offset_x, int offset_y,
115                                        int xmin, int ymin, int xmax, int ymax);
116
117 /* ** Area-specific functions ** */
118
119 /* Sequencer */
120
121 void IMB_colormanagement_imbuf_to_sequencer_space(struct ImBuf *ibuf, int make_float);
122 void IMB_colormanagement_imbuf_from_sequencer_space(struct ImBuf *ibuf);
123
124 void IMB_colormanagement_pixel_from_sequencer_space(float pixel[4]);
125
126
127 /* Roles */
128 enum {
129         COLOR_ROLE_SCENE_LINEAR = 0,
130         COLOR_ROLE_COLOR_PICKING,
131         COLOR_ROLE_TEXTURE_PAINTING,
132         COLOR_ROLE_SEQUENCER,
133 };
134
135 #endif // IMB_COLORMANAGEMENT_H