Debian Codegraph @

third_party/etc2comp/EtcLib/Etc/EtcColor.h

raw
1 /*
2 * Copyright 2015 The Etc2Comp Authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #pragma once
18
19 #include <math.h>
20
21 namespace Etc
22 {
23
24 inline float LogToLinear(float a_fLog)
25 {
26 static const float ALPHA = 0.055f;
27 static const float ONE_PLUS_ALPHA = 1.0f + ALPHA;
28
29 if (a_fLog <= 0.04045f)
30 {
31 return a_fLog / 12.92f;
32 }
33 else
34 {
35 return powf((a_fLog + ALPHA) / ONE_PLUS_ALPHA, 2.4f);
36 }
37 }
38
39 inline float LinearToLog(float &a_fLinear)
40 {
41 static const float ALPHA = 0.055f;
42 static const float ONE_PLUS_ALPHA = 1.0f + ALPHA;
43
44 if (a_fLinear <= 0.0031308f)
45 {
46 return 12.92f * a_fLinear;
47 }
48 else
49 {
50 return ONE_PLUS_ALPHA * powf(a_fLinear, (1.0f/2.4f)) - ALPHA;
51 }
52 }
53
54 class ColorR8G8B8A8
55 {
56 public:
57
58 unsigned char ucR;
59 unsigned char ucG;
60 unsigned char ucB;
61 unsigned char ucA;
62
63 };
64 }