Color Management: float generated images had is_data flag set incorrect
[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 struct ImageFormatData;
49
50 struct ColorSpace;
51 struct ColorManagedDisplay;
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 const char *IMB_colormanagement_role_colorspace_name_get(int role);
61 void IMB_colormanagement_check_is_data(struct ImBuf *ibuf, const char *name);
62 void IMB_colormanagement_assign_rect_colorspace(struct ImBuf *ibuf, const char *name);
63
64 /* ** Color space transformation functions ** */
65 void IMB_colormanagement_transform(float *buffer, int width, int height, int channels,
66                                    const char *from_colorspace, const char *to_colorspace, int predivide);
67 void IMB_colormanagement_transform_threaded(float *buffer, int width, int height, int channels,
68                                             const char *from_colorspace, const char *to_colorspace, int predivide);
69 void IMB_colormanagement_transform_v4(float pixel[4], const char *from_colorspace, const char *to_colorspace);
70
71 void IMB_colormanagement_colorspace_to_scene_linear_v3(float pixel[3], struct ColorSpace *colorspace);
72 void IMB_colormanagement_scene_linear_to_colorspace_v3(float pixel[3], struct ColorSpace *colorspace);
73
74 void IMB_colormanagement_colorspace_to_scene_linear(float *buffer, int width, int height, int channels, struct ColorSpace *colorspace, int predivide);
75
76 void IMB_colormanagement_scene_linear_to_display_v3(float pixel[3], struct ColorManagedDisplay *display);
77 void IMB_colormanagement_display_to_scene_linear_v3(float pixel[3], struct ColorManagedDisplay *display);
78
79 void IMB_colormanagement_pixel_to_display_space_v4(float result[4], const float pixel[4],  const struct ColorManagedViewSettings *view_settings,
80                                                    const struct ColorManagedDisplaySettings *display_settings);
81
82 void IMB_colormanagement_pixel_to_display_space_v3(float result[3], const float pixel[3],  const struct ColorManagedViewSettings *view_settings,
83                                                    const struct ColorManagedDisplaySettings *display_settings);
84
85 void IMB_colormanagement_imbuf_assign_float_space(struct ImBuf *ibuf, struct ColorManagedColorspaceSettings *colorspace_settings);
86
87 void IMB_colormanagement_imbuf_make_display_space(struct ImBuf *ibuf, const struct ColorManagedViewSettings *view_settings,
88                                                   const struct ColorManagedDisplaySettings *display_settings);
89
90 struct ImBuf *IMB_colormanagement_imbuf_for_write(struct ImBuf *ibuf, int save_as_render, int allocate_result,
91                                                   const struct ColorManagedViewSettings *view_settings,
92                                                   const struct ColorManagedDisplaySettings *display_settings,
93                                                   struct ImageFormatData *image_format_data);
94
95 /* ** Public display buffers interfaces ** */
96
97 unsigned char *IMB_display_buffer_acquire(struct ImBuf *ibuf, const struct ColorManagedViewSettings *view_settings,
98                                           const struct ColorManagedDisplaySettings *display_settings, void **cache_handle);
99 unsigned char *IMB_display_buffer_acquire_ctx(const struct bContext *C, struct ImBuf *ibuf, void **cache_handle);
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 */