1
+ /*
2
+ * MIT License
3
+ *
4
+ * Copyright (c) 2024 Radzivon Bartoshyk
5
+ * avif-coder [https://github.com/awxkee/avif-coder]
6
+ *
7
+ * Created by Radzivon Bartoshyk on 10/11/2024
8
+ *
9
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ * of this software and associated documentation files (the "Software"), to deal
11
+ * in the Software without restriction, including without limitation the rights
12
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ * copies of the Software, and to permit persons to whom the Software is
14
+ * furnished to do so, subject to the following conditions:
15
+ *
16
+ * The above copyright notice and this permission notice shall be included in all
17
+ * copies or substantial portions of the Software.
18
+ *
19
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ * SOFTWARE.
26
+ *
27
+ */
28
+
29
+
30
+ #include " FilmicToneMapper.h"
31
+ #include " Oklab.hpp"
32
+
33
+ void FilmicToneMapper::transferTone (float *inPlace, uint32_t width) {
34
+ float *targetPlace = inPlace;
35
+
36
+ for (uint32_t x = 0 ; x < width; ++x) {
37
+ float r = targetPlace[0 ];
38
+ float g = targetPlace[1 ];
39
+ float b = targetPlace[2 ];
40
+ coder::Oklab oklab = coder::Oklab::fromLinearRGB (r, g, b);
41
+ if (oklab.L == 0 ) {
42
+ continue ;
43
+ }
44
+ float shScale = this ->uncharted2_filmic (oklab.L ) / oklab.L ;
45
+ oklab.L = oklab.L * shScale;
46
+ coder::Rgb linearRgb = oklab.toLinearRGB ();
47
+ targetPlace[0 ] = std::min (linearRgb.r , 1 .f );
48
+ targetPlace[1 ] = std::min (linearRgb.g , 1 .f );
49
+ targetPlace[2 ] = std::min (linearRgb.b , 1 .f );
50
+ targetPlace += 3 ;
51
+ }
52
+ }
0 commit comments