1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2012 Blender Foundation.
17  * All rights reserved.
18  */
19 
20 #ifndef __OCIO_CAPI_H__
21 #define __OCIO_CAPI_H__
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 struct OCIO_GLSLDrawState;
28 
29 #define OCIO_DECLARE_HANDLE(name) \
30   typedef struct name##__ { \
31     int unused; \
32   } * name
33 
34 #define OCIO_ROLE_DATA "data"
35 #define OCIO_ROLE_SCENE_LINEAR "scene_linear"
36 #define OCIO_ROLE_COLOR_PICKING "color_picking"
37 #define OCIO_ROLE_TEXTURE_PAINT "texture_paint"
38 #define OCIO_ROLE_DEFAULT_BYTE "default_byte"
39 #define OCIO_ROLE_DEFAULT_FLOAT "default_float"
40 #define OCIO_ROLE_DEFAULT_SEQUENCER "default_sequencer"
41 
42 OCIO_DECLARE_HANDLE(OCIO_ConstConfigRcPtr);
43 OCIO_DECLARE_HANDLE(OCIO_ConstColorSpaceRcPtr);
44 OCIO_DECLARE_HANDLE(OCIO_ConstProcessorRcPtr);
45 OCIO_DECLARE_HANDLE(OCIO_ConstContextRcPtr);
46 OCIO_DECLARE_HANDLE(OCIO_PackedImageDesc);
47 OCIO_DECLARE_HANDLE(OCIO_DisplayTransformRcPtr);
48 OCIO_DECLARE_HANDLE(OCIO_ConstTransformRcPtr);
49 OCIO_DECLARE_HANDLE(OCIO_ColorSpaceTransformRcPtr);
50 OCIO_DECLARE_HANDLE(OCIO_ExponentTransformRcPtr);
51 OCIO_DECLARE_HANDLE(OCIO_MatrixTransformRcPtr);
52 OCIO_DECLARE_HANDLE(OCIO_GroupTransformRcPtr);
53 OCIO_DECLARE_HANDLE(OCIO_ConstLookRcPtr);
54 
55 /* Standard XYZ to linear sRGB transform, for fallback. */
56 static const float OCIO_XYZ_TO_LINEAR_SRGB[3][3] = {{3.2404542f, -0.9692660f, 0.0556434f},
57                                                     {-1.5371385f, 1.8760108f, -0.2040259f},
58                                                     {-0.4985314f, 0.0415560f, 1.0572252f}};
59 
60 /* This structure is used to pass curve mapping settings from
61  * blender's DNA structure stored in view transform settings
62  * to a generic OpenColorIO C-API.
63  */
64 typedef struct OCIO_CurveMappingSettings {
65   /* This is a LUT which contain values for all 4 curve mapping tables
66    * (combined, R, G and B).
67    *
68    * Element I for table T is stored at I * 4 + T element of this LUT.
69    *
70    * This array is usually returned by curvemapping_table_RGBA().
71    */
72   float *lut;
73 
74   /* Size of single curve mapping table, 1/4 size of lut array. */
75   int lut_size;
76 
77   /* Extend extrapolation flags for all the tables.
78    * if use_extend_extrapolate != 0 means extrapolation for
79    * curve.
80    */
81   int use_extend_extrapolate;
82 
83   /* Minimal X value of the curve mapping tables. */
84   float mintable[4];
85 
86   /* Per curve mapping table range. */
87   float range[4];
88 
89   /* Lower extension value, stored as per-component arrays. */
90   float ext_in_x[4], ext_in_y[4];
91 
92   /* Higher extension value, stored as per-component arrays. */
93   float ext_out_x[4], ext_out_y[4];
94 
95   /* First points of the tables, both X and Y values.
96    * Needed for easier and faster access when extrapolating.
97    */
98   float first_x[4], first_y[4];
99 
100   /* Last points of the tables, both X and Y values.
101    * Needed for easier and faster access when extrapolating.
102    */
103   float last_x[4], last_y[4];
104 
105   /* Premultiplication settings: black level and scale to match
106    * with white level.
107    */
108   float black[3], bwmul[3];
109 
110   /* Cache id of the original curve mapping, used to detect when
111    * upload of new settings to GPU is needed.
112    */
113   size_t cache_id;
114 } OCIO_CurveMappingSettings;
115 
116 void OCIO_init(void);
117 void OCIO_exit(void);
118 
119 OCIO_ConstConfigRcPtr *OCIO_getCurrentConfig(void);
120 void OCIO_setCurrentConfig(const OCIO_ConstConfigRcPtr *config);
121 
122 OCIO_ConstConfigRcPtr *OCIO_configCreateFromEnv(void);
123 OCIO_ConstConfigRcPtr *OCIO_configCreateFromFile(const char *filename);
124 OCIO_ConstConfigRcPtr *OCIO_configCreateFallback(void);
125 
126 void OCIO_configRelease(OCIO_ConstConfigRcPtr *config);
127 
128 int OCIO_configGetNumColorSpaces(OCIO_ConstConfigRcPtr *config);
129 const char *OCIO_configGetColorSpaceNameByIndex(OCIO_ConstConfigRcPtr *config, int index);
130 OCIO_ConstColorSpaceRcPtr *OCIO_configGetColorSpace(OCIO_ConstConfigRcPtr *config,
131                                                     const char *name);
132 int OCIO_configGetIndexForColorSpace(OCIO_ConstConfigRcPtr *config, const char *name);
133 
134 int OCIO_colorSpaceIsInvertible(OCIO_ConstColorSpaceRcPtr *cs);
135 int OCIO_colorSpaceIsData(OCIO_ConstColorSpaceRcPtr *cs);
136 void OCIO_colorSpaceIsBuiltin(OCIO_ConstConfigRcPtr *config,
137                               OCIO_ConstColorSpaceRcPtr *cs,
138                               bool *is_scene_linear,
139                               bool *is_srgb);
140 
141 void OCIO_colorSpaceRelease(OCIO_ConstColorSpaceRcPtr *cs);
142 
143 const char *OCIO_configGetDefaultDisplay(OCIO_ConstConfigRcPtr *config);
144 int OCIO_configGetNumDisplays(OCIO_ConstConfigRcPtr *config);
145 const char *OCIO_configGetDisplay(OCIO_ConstConfigRcPtr *config, int index);
146 const char *OCIO_configGetDefaultView(OCIO_ConstConfigRcPtr *config, const char *display);
147 int OCIO_configGetNumViews(OCIO_ConstConfigRcPtr *config, const char *display);
148 const char *OCIO_configGetView(OCIO_ConstConfigRcPtr *config, const char *display, int index);
149 const char *OCIO_configGetDisplayColorSpaceName(OCIO_ConstConfigRcPtr *config,
150                                                 const char *display,
151                                                 const char *view);
152 
153 void OCIO_configGetDefaultLumaCoefs(OCIO_ConstConfigRcPtr *config, float *rgb);
154 void OCIO_configGetXYZtoRGB(OCIO_ConstConfigRcPtr *config, float xyz_to_rgb[3][3]);
155 
156 int OCIO_configGetNumLooks(OCIO_ConstConfigRcPtr *config);
157 const char *OCIO_configGetLookNameByIndex(OCIO_ConstConfigRcPtr *config, int index);
158 OCIO_ConstLookRcPtr *OCIO_configGetLook(OCIO_ConstConfigRcPtr *config, const char *name);
159 
160 const char *OCIO_lookGetProcessSpace(OCIO_ConstLookRcPtr *look);
161 void OCIO_lookRelease(OCIO_ConstLookRcPtr *look);
162 
163 OCIO_ConstProcessorRcPtr *OCIO_configGetProcessorWithNames(OCIO_ConstConfigRcPtr *config,
164                                                            const char *srcName,
165                                                            const char *dstName);
166 OCIO_ConstProcessorRcPtr *OCIO_configGetProcessor(OCIO_ConstConfigRcPtr *config,
167                                                   OCIO_ConstTransformRcPtr *transform);
168 
169 void OCIO_processorApply(OCIO_ConstProcessorRcPtr *processor, OCIO_PackedImageDesc *img);
170 void OCIO_processorApply_predivide(OCIO_ConstProcessorRcPtr *processor, OCIO_PackedImageDesc *img);
171 void OCIO_processorApplyRGB(OCIO_ConstProcessorRcPtr *processor, float *pixel);
172 void OCIO_processorApplyRGBA(OCIO_ConstProcessorRcPtr *processor, float *pixel);
173 void OCIO_processorApplyRGBA_predivide(OCIO_ConstProcessorRcPtr *processor, float *pixel);
174 
175 void OCIO_processorRelease(OCIO_ConstProcessorRcPtr *p);
176 
177 const char *OCIO_colorSpaceGetName(OCIO_ConstColorSpaceRcPtr *cs);
178 const char *OCIO_colorSpaceGetDescription(OCIO_ConstColorSpaceRcPtr *cs);
179 const char *OCIO_colorSpaceGetFamily(OCIO_ConstColorSpaceRcPtr *cs);
180 
181 OCIO_DisplayTransformRcPtr *OCIO_createDisplayTransform(void);
182 void OCIO_displayTransformSetInputColorSpaceName(OCIO_DisplayTransformRcPtr *dt, const char *name);
183 void OCIO_displayTransformSetDisplay(OCIO_DisplayTransformRcPtr *dt, const char *name);
184 void OCIO_displayTransformSetView(OCIO_DisplayTransformRcPtr *dt, const char *name);
185 void OCIO_displayTransformSetDisplayCC(OCIO_DisplayTransformRcPtr *dt,
186                                        OCIO_ConstTransformRcPtr *et);
187 void OCIO_displayTransformSetLinearCC(OCIO_DisplayTransformRcPtr *dt,
188                                       OCIO_ConstTransformRcPtr *et);
189 void OCIO_displayTransformSetLooksOverride(OCIO_DisplayTransformRcPtr *dt, const char *looks);
190 void OCIO_displayTransformSetLooksOverrideEnabled(OCIO_DisplayTransformRcPtr *dt, bool enabled);
191 void OCIO_displayTransformRelease(OCIO_DisplayTransformRcPtr *dt);
192 
193 OCIO_PackedImageDesc *OCIO_createOCIO_PackedImageDesc(float *data,
194                                                       long width,
195                                                       long height,
196                                                       long numChannels,
197                                                       long chanStrideBytes,
198                                                       long xStrideBytes,
199                                                       long yStrideBytes);
200 
201 void OCIO_PackedImageDescRelease(OCIO_PackedImageDesc *p);
202 
203 OCIO_GroupTransformRcPtr *OCIO_createGroupTransform(void);
204 void OCIO_groupTransformSetDirection(OCIO_GroupTransformRcPtr *gt, const bool forward);
205 void OCIO_groupTransformPushBack(OCIO_GroupTransformRcPtr *gt, OCIO_ConstTransformRcPtr *tr);
206 void OCIO_groupTransformRelease(OCIO_GroupTransformRcPtr *gt);
207 
208 OCIO_ColorSpaceTransformRcPtr *OCIO_createColorSpaceTransform(void);
209 void OCIO_colorSpaceTransformSetSrc(OCIO_ColorSpaceTransformRcPtr *ct, const char *name);
210 void OCIO_colorSpaceTransformRelease(OCIO_ColorSpaceTransformRcPtr *ct);
211 
212 OCIO_ExponentTransformRcPtr *OCIO_createExponentTransform(void);
213 void OCIO_exponentTransformSetValue(OCIO_ExponentTransformRcPtr *et, const float *exponent);
214 void OCIO_exponentTransformRelease(OCIO_ExponentTransformRcPtr *et);
215 
216 OCIO_MatrixTransformRcPtr *OCIO_createMatrixTransform(void);
217 void OCIO_matrixTransformSetValue(OCIO_MatrixTransformRcPtr *mt,
218                                   const float *m44,
219                                   const float *offset4);
220 void OCIO_matrixTransformRelease(OCIO_MatrixTransformRcPtr *mt);
221 
222 void OCIO_matrixTransformScale(float *m44, float *offset4, const float *scale4);
223 
224 int OCIO_supportGLSLDraw(void);
225 int OCIO_setupGLSLDraw(struct OCIO_GLSLDrawState **state_r,
226                        OCIO_ConstProcessorRcPtr *ocio_processor_scene_to_ui,
227                        OCIO_ConstProcessorRcPtr *ocio_processor_ui_to_display,
228                        OCIO_CurveMappingSettings *curve_mapping_settings,
229                        float dither,
230                        bool predivide,
231                        bool overlay);
232 void OCIO_finishGLSLDraw(struct OCIO_GLSLDrawState *state);
233 void OCIO_freeOGLState(struct OCIO_GLSLDrawState *state);
234 
235 const char *OCIO_getVersionString(void);
236 int OCIO_getVersionHex(void);
237 
238 #ifdef __cplusplus
239 }
240 #endif
241 
242 #endif /* OCIO_CAPI_H */
243