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 by Blender Foundation.
17  * All rights reserved.
18  */
19 
20 #pragma once
21 
22 /** \file
23  * \ingroup imbuf
24  */
25 
26 #include "BLI_sys_types.h"
27 #include "DNA_listBase.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 struct ImBuf;
34 struct OCIO_ConstProcessorRcPtr;
35 
36 extern float imbuf_luma_coefficients[3];
37 extern float imbuf_xyz_to_rgb[3][3];
38 extern float imbuf_rgb_to_xyz[3][3];
39 
40 #define MAX_COLORSPACE_NAME 64
41 #define MAX_COLORSPACE_DESCRIPTION 512
42 
43 typedef struct ColorSpace {
44   struct ColorSpace *next, *prev;
45   int index;
46   char name[MAX_COLORSPACE_NAME];
47   char description[MAX_COLORSPACE_DESCRIPTION];
48 
49   struct OCIO_ConstProcessorRcPtr *to_scene_linear;
50   struct OCIO_ConstProcessorRcPtr *from_scene_linear;
51 
52   bool is_invertible;
53   bool is_data;
54 
55   /* Additional info computed only when needed since it's not cheap. */
56   struct {
57     bool cached;
58     bool is_srgb;
59     bool is_scene_linear;
60   } info;
61 } ColorSpace;
62 
63 typedef struct ColorManagedDisplay {
64   struct ColorManagedDisplay *next, *prev;
65   int index;
66   char name[MAX_COLORSPACE_NAME];
67   ListBase views; /* LinkData.data -> ColorManagedView */
68 
69   struct OCIO_ConstProcessorRcPtr *to_scene_linear;
70   struct OCIO_ConstProcessorRcPtr *from_scene_linear;
71 } ColorManagedDisplay;
72 
73 typedef struct ColorManagedView {
74   struct ColorManagedView *next, *prev;
75   int index;
76   char name[MAX_COLORSPACE_NAME];
77 } ColorManagedView;
78 
79 typedef struct ColorManagedLook {
80   struct ColorManagedLook *next, *prev;
81   int index;
82   char name[MAX_COLORSPACE_NAME];
83   char ui_name[MAX_COLORSPACE_NAME];
84   char view[MAX_COLORSPACE_NAME];
85   char process_space[MAX_COLORSPACE_NAME];
86   bool is_noop;
87 } ColorManagedLook;
88 
89 /* ** Initialization / De-initialization ** */
90 
91 void colormanagement_init(void);
92 void colormanagement_exit(void);
93 
94 void colormanage_cache_free(struct ImBuf *ibuf);
95 
96 const char *colormanage_display_get_default_name(void);
97 struct ColorManagedDisplay *colormanage_display_get_default(void);
98 struct ColorManagedDisplay *colormanage_display_add(const char *name);
99 struct ColorManagedDisplay *colormanage_display_get_named(const char *name);
100 struct ColorManagedDisplay *colormanage_display_get_indexed(int index);
101 
102 const char *colormanage_view_get_default_name(const ColorManagedDisplay *display);
103 struct ColorManagedView *colormanage_view_get_default(const ColorManagedDisplay *display);
104 struct ColorManagedView *colormanage_view_add(const char *name);
105 struct ColorManagedView *colormanage_view_get_indexed(int index);
106 struct ColorManagedView *colormanage_view_get_named(const char *name);
107 struct ColorManagedView *colormanage_view_get_named_for_display(const char *display_name,
108                                                                 const char *name);
109 
110 struct ColorSpace *colormanage_colorspace_add(const char *name,
111                                               const char *description,
112                                               bool is_invertible,
113                                               bool is_data);
114 struct ColorSpace *colormanage_colorspace_get_named(const char *name);
115 struct ColorSpace *colormanage_colorspace_get_roled(int role);
116 struct ColorSpace *colormanage_colorspace_get_indexed(int index);
117 
118 struct ColorManagedLook *colormanage_look_add(const char *name,
119                                               const char *process_space,
120                                               bool is_noop);
121 struct ColorManagedLook *colormanage_look_get_named(const char *name);
122 struct ColorManagedLook *colormanage_look_get_indexed(int index);
123 
124 void colorspace_set_default_role(char *colorspace, int size, int role);
125 
126 void colormanage_imbuf_set_default_spaces(struct ImBuf *ibuf);
127 void colormanage_imbuf_make_linear(struct ImBuf *ibuf, const char *from_colorspace);
128 
129 #ifdef __cplusplus
130 }
131 #endif
132