/src/guetzli/guetzli/gamma_correct.cc
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2016 Google Inc. |
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 | | #include "guetzli/gamma_correct.h" |
18 | | |
19 | | #include <cmath> |
20 | | |
21 | | namespace guetzli { |
22 | | |
23 | 1 | const double* NewSrgb8ToLinearTable() { |
24 | 1 | double* table = new double[256]; |
25 | 1 | int i = 0; |
26 | 12 | for (; i < 11; ++i) { |
27 | 11 | table[i] = i / 12.92; |
28 | 11 | } |
29 | 246 | for (; i < 256; ++i) { |
30 | 245 | table[i] = 255.0 * std::pow(((i / 255.0) + 0.055) / 1.055, 2.4); |
31 | 245 | } |
32 | 1 | return table; |
33 | 1 | } |
34 | | |
35 | 6.50M | const double* Srgb8ToLinearTable() { |
36 | 6.50M | static const double* const kSrgb8ToLinearTable = NewSrgb8ToLinearTable(); |
37 | 6.50M | return kSrgb8ToLinearTable; |
38 | 6.50M | } |
39 | | |
40 | | } // namespace guetzli |