OpenImageIO
 All Classes Files Friends Macros Pages
color.h
1 /*
2  Copyright 2010 Larry Gritz and the other authors and contributors.
3  All Rights Reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are
7  met:
8  * Redistributions of source code must retain the above copyright
9  notice, this list of conditions and the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright
11  notice, this list of conditions and the following disclaimer in the
12  documentation and/or other materials provided with the distribution.
13  * Neither the name of the software's owners nor the names of its
14  contributors may be used to endorse or promote products derived from
15  this software without specific prior written permission.
16  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28  (This is the Modified BSD License)
29 */
30 
31 #ifndef OPENIMAGEIO_COLOR_H
32 #define OPENIMAGEIO_COLOR_H
33 
34 #include "export.h"
35 #include "version.h"
36 
37 OIIO_NAMESPACE_ENTER
38 {
39 
44 
45 class OIIO_API ColorProcessor;
46 
47 
48 
58 
59 class OIIO_API ColorConfig
60 {
61 public:
67  ColorConfig();
68 
74  ColorConfig(const char * filename);
75 
76  ~ColorConfig();
77 
80  bool error () const;
81 
85  std::string geterror ();
86 
88  int getNumColorSpaces() const;
89 
91  const char * getColorSpaceNameByIndex(int index) const;
92 
95  const char * getColorSpaceNameByRole (const char *role) const;
96 
98  int getNumLooks() const;
99 
101  const char * getLookNameByIndex(int index) const;
102 
116  ColorProcessor* createColorProcessor(const char * inputColorSpace,
117  const char * outputColorSpace) const;
118 
136  ColorProcessor* createLookTransform (const char * looks,
137  const char * inputColorSpace,
138  const char * outputColorSpace,
139  bool inverse=false,
140  const char *context_key=NULL,
141  const char *context_value=NULL) const;
142 
144  static void deleteColorProcessor(ColorProcessor * processor);
145 
147  static bool supportsOpenColorIO();
148 
149 private:
150  ColorConfig(const ColorConfig &);
151  ColorConfig& operator= (const ColorConfig &);
152 
153  class Impl;
154  friend class Impl;
155  Impl * m_impl;
156  Impl * getImpl() { return m_impl; }
157  const Impl * getImpl() const { return m_impl; }
158 };
159 
160 
161 
164 inline float sRGB_to_linear (float x)
165 {
166  return (x <= 0.04045f) ? (x / 12.92f)
167  : powf ((x + 0.055f) / 1.055f, 2.4f);
168 }
169 
171 inline float linear_to_sRGB (float x)
172 {
173  if (x < 0.0f)
174  return 0.0f;
175  return (x <= 0.0031308f) ? (12.92f * x)
176  : (1.055f * powf (x, 1.f/2.4f) - 0.055f);
177 }
178 
179 
182 inline float Rec709_to_linear (float x)
183 {
184  if (x < 0.081f)
185  return (x < 0.0f) ? 0.0f : x * (1.0f/4.5f);
186  else
187  return powf ((x + 0.099f) * (1.0f/1.099f), (1.0f/0.45f));
188 }
189 
191 inline float linear_to_Rec709 (float x)
192 {
193  if (x < 0.018f)
194  return (x < 0.0f)? 0.0f : x * 4.5f;
195  else
196  return 1.099f * powf(x, 0.45f) - 0.099f;
197 }
198 
199 
200 }
201 OIIO_NAMESPACE_EXIT
202 
203 #endif // OPENIMAGEIO_COLOR_H