Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2022 The Android Open Source Project |
| 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 <cmath> |
Harish Mahendrakar | 555a06b | 2022-12-14 09:37:27 -0800 | [diff] [blame] | 18 | #include <vector> |
Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 19 | #include <jpegrecoverymap/recoverymapmath.h> |
| 20 | |
Dichen Zhang | b2ed830 | 2023-02-10 23:05:04 +0000 | [diff] [blame] | 21 | namespace android::jpegrecoverymap { |
Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 22 | |
Harish Mahendrakar | 555a06b | 2022-12-14 09:37:27 -0800 | [diff] [blame] | 23 | static const std::vector<float> kPqOETF = [] { |
| 24 | std::vector<float> result; |
Nick Deakin | d19e576 | 2023-02-10 15:39:08 -0500 | [diff] [blame] | 25 | for (int idx = 0; idx < kPqOETFNumEntries; idx++) { |
| 26 | float value = static_cast<float>(idx) / static_cast<float>(kPqOETFNumEntries - 1); |
Harish Mahendrakar | 555a06b | 2022-12-14 09:37:27 -0800 | [diff] [blame] | 27 | result.push_back(pqOetf(value)); |
| 28 | } |
| 29 | return result; |
| 30 | }(); |
| 31 | |
Harish Mahendrakar | 555a06b | 2022-12-14 09:37:27 -0800 | [diff] [blame] | 32 | static const std::vector<float> kPqInvOETF = [] { |
| 33 | std::vector<float> result; |
Nick Deakin | d19e576 | 2023-02-10 15:39:08 -0500 | [diff] [blame] | 34 | for (int idx = 0; idx < kPqInvOETFNumEntries; idx++) { |
| 35 | float value = static_cast<float>(idx) / static_cast<float>(kPqInvOETFNumEntries - 1); |
Harish Mahendrakar | 555a06b | 2022-12-14 09:37:27 -0800 | [diff] [blame] | 36 | result.push_back(pqInvOetf(value)); |
| 37 | } |
| 38 | return result; |
| 39 | }(); |
| 40 | |
Harish Mahendrakar | 555a06b | 2022-12-14 09:37:27 -0800 | [diff] [blame] | 41 | static const std::vector<float> kHlgOETF = [] { |
| 42 | std::vector<float> result; |
Nick Deakin | d19e576 | 2023-02-10 15:39:08 -0500 | [diff] [blame] | 43 | for (int idx = 0; idx < kHlgOETFNumEntries; idx++) { |
| 44 | float value = static_cast<float>(idx) / static_cast<float>(kHlgOETFNumEntries - 1); |
Harish Mahendrakar | 555a06b | 2022-12-14 09:37:27 -0800 | [diff] [blame] | 45 | result.push_back(hlgOetf(value)); |
| 46 | } |
| 47 | return result; |
| 48 | }(); |
| 49 | |
Harish Mahendrakar | 555a06b | 2022-12-14 09:37:27 -0800 | [diff] [blame] | 50 | static const std::vector<float> kHlgInvOETF = [] { |
| 51 | std::vector<float> result; |
Nick Deakin | d19e576 | 2023-02-10 15:39:08 -0500 | [diff] [blame] | 52 | for (int idx = 0; idx < kHlgInvOETFNumEntries; idx++) { |
| 53 | float value = static_cast<float>(idx) / static_cast<float>(kHlgInvOETFNumEntries - 1); |
Harish Mahendrakar | 555a06b | 2022-12-14 09:37:27 -0800 | [diff] [blame] | 54 | result.push_back(hlgInvOetf(value)); |
| 55 | } |
| 56 | return result; |
| 57 | }(); |
| 58 | |
Nick Deakin | d19e576 | 2023-02-10 15:39:08 -0500 | [diff] [blame] | 59 | static const std::vector<float> kSrgbInvOETF = [] { |
Harish Mahendrakar | 555a06b | 2022-12-14 09:37:27 -0800 | [diff] [blame] | 60 | std::vector<float> result; |
Nick Deakin | d19e576 | 2023-02-10 15:39:08 -0500 | [diff] [blame] | 61 | for (int idx = 0; idx < kSrgbInvOETFNumEntries; idx++) { |
| 62 | float value = static_cast<float>(idx) / static_cast<float>(kSrgbInvOETFNumEntries - 1); |
Harish Mahendrakar | 555a06b | 2022-12-14 09:37:27 -0800 | [diff] [blame] | 63 | result.push_back(srgbInvOetf(value)); |
| 64 | } |
| 65 | return result; |
| 66 | }(); |
Ram Mohan | fe723d6 | 2022-12-15 00:59:11 +0530 | [diff] [blame] | 67 | |
| 68 | // Use Shepard's method for inverse distance weighting. For more information: |
| 69 | // en.wikipedia.org/wiki/Inverse_distance_weighting#Shepard's_method |
| 70 | |
| 71 | float ShepardsIDW::euclideanDistance(float x1, float x2, float y1, float y2) { |
| 72 | return sqrt(((y2 - y1) * (y2 - y1)) + (x2 - x1) * (x2 - x1)); |
| 73 | } |
| 74 | |
| 75 | void ShepardsIDW::fillShepardsIDW(float *weights, int incR, int incB) { |
| 76 | for (int y = 0; y < mMapScaleFactor; y++) { |
| 77 | for (int x = 0; x < mMapScaleFactor; x++) { |
| 78 | float pos_x = ((float)x) / mMapScaleFactor; |
| 79 | float pos_y = ((float)y) / mMapScaleFactor; |
| 80 | int curr_x = floor(pos_x); |
| 81 | int curr_y = floor(pos_y); |
| 82 | int next_x = curr_x + incR; |
| 83 | int next_y = curr_y + incB; |
| 84 | float e1_distance = euclideanDistance(pos_x, curr_x, pos_y, curr_y); |
| 85 | int index = y * mMapScaleFactor * 4 + x * 4; |
| 86 | if (e1_distance == 0) { |
| 87 | weights[index++] = 1.f; |
| 88 | weights[index++] = 0.f; |
| 89 | weights[index++] = 0.f; |
| 90 | weights[index++] = 0.f; |
| 91 | } else { |
| 92 | float e1_weight = 1.f / e1_distance; |
| 93 | |
| 94 | float e2_distance = euclideanDistance(pos_x, curr_x, pos_y, next_y); |
| 95 | float e2_weight = 1.f / e2_distance; |
| 96 | |
| 97 | float e3_distance = euclideanDistance(pos_x, next_x, pos_y, curr_y); |
| 98 | float e3_weight = 1.f / e3_distance; |
| 99 | |
| 100 | float e4_distance = euclideanDistance(pos_x, next_x, pos_y, next_y); |
| 101 | float e4_weight = 1.f / e4_distance; |
| 102 | |
| 103 | float total_weight = e1_weight + e2_weight + e3_weight + e4_weight; |
| 104 | |
| 105 | weights[index++] = e1_weight / total_weight; |
| 106 | weights[index++] = e2_weight / total_weight; |
| 107 | weights[index++] = e3_weight / total_weight; |
| 108 | weights[index++] = e4_weight / total_weight; |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | |
Nick Deakin | 594a4ca | 2022-11-16 20:57:42 -0500 | [diff] [blame] | 114 | //////////////////////////////////////////////////////////////////////////////// |
| 115 | // sRGB transformations |
Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 116 | |
Harish Mahendrakar | 1107ff3 | 2022-12-07 17:24:35 -0800 | [diff] [blame] | 117 | static const float kMaxPixelFloat = 1.0f; |
| 118 | static float clampPixelFloat(float value) { |
| 119 | return (value < 0.0f) ? 0.0f : (value > kMaxPixelFloat) ? kMaxPixelFloat : value; |
| 120 | } |
| 121 | |
Nick Deakin | 65f492a | 2022-11-29 22:47:40 -0500 | [diff] [blame] | 122 | // See IEC 61966-2-1, Equation F.7. |
| 123 | static const float kSrgbR = 0.2126f, kSrgbG = 0.7152f, kSrgbB = 0.0722f; |
Nick Deakin | 594a4ca | 2022-11-16 20:57:42 -0500 | [diff] [blame] | 124 | |
| 125 | float srgbLuminance(Color e) { |
| 126 | return kSrgbR * e.r + kSrgbG * e.g + kSrgbB * e.b; |
Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 127 | } |
| 128 | |
Nick Deakin | 65f492a | 2022-11-29 22:47:40 -0500 | [diff] [blame] | 129 | // See ECMA TR/98, Section 7. |
Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 130 | static const float kSrgbRCr = 1.402f, kSrgbGCb = 0.34414f, kSrgbGCr = 0.71414f, kSrgbBCb = 1.772f; |
| 131 | |
Nick Deakin | 594a4ca | 2022-11-16 20:57:42 -0500 | [diff] [blame] | 132 | Color srgbYuvToRgb(Color e_gamma) { |
Harish Mahendrakar | 1107ff3 | 2022-12-07 17:24:35 -0800 | [diff] [blame] | 133 | return {{{ clampPixelFloat(e_gamma.y + kSrgbRCr * e_gamma.v), |
| 134 | clampPixelFloat(e_gamma.y - kSrgbGCb * e_gamma.u - kSrgbGCr * e_gamma.v), |
| 135 | clampPixelFloat(e_gamma.y + kSrgbBCb * e_gamma.u) }}}; |
Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 136 | } |
| 137 | |
Nick Deakin | 65f492a | 2022-11-29 22:47:40 -0500 | [diff] [blame] | 138 | // See ECMA TR/98, Section 7. |
| 139 | static const float kSrgbYR = 0.299f, kSrgbYG = 0.587f, kSrgbYB = 0.114f; |
Nick Deakin | 594a4ca | 2022-11-16 20:57:42 -0500 | [diff] [blame] | 140 | static const float kSrgbUR = -0.1687f, kSrgbUG = -0.3313f, kSrgbUB = 0.5f; |
| 141 | static const float kSrgbVR = 0.5f, kSrgbVG = -0.4187f, kSrgbVB = -0.0813f; |
| 142 | |
| 143 | Color srgbRgbToYuv(Color e_gamma) { |
Nick Deakin | 65f492a | 2022-11-29 22:47:40 -0500 | [diff] [blame] | 144 | return {{{ kSrgbYR * e_gamma.r + kSrgbYG * e_gamma.g + kSrgbYB * e_gamma.b, |
Nick Deakin | 594a4ca | 2022-11-16 20:57:42 -0500 | [diff] [blame] | 145 | kSrgbUR * e_gamma.r + kSrgbUG * e_gamma.g + kSrgbUB * e_gamma.b, |
| 146 | kSrgbVR * e_gamma.r + kSrgbVG * e_gamma.g + kSrgbVB * e_gamma.b }}}; |
| 147 | } |
| 148 | |
Nick Deakin | 65f492a | 2022-11-29 22:47:40 -0500 | [diff] [blame] | 149 | // See IEC 61966-2-1, Equations F.5 and F.6. |
Nick Deakin | 594a4ca | 2022-11-16 20:57:42 -0500 | [diff] [blame] | 150 | float srgbInvOetf(float e_gamma) { |
| 151 | if (e_gamma <= 0.04045f) { |
| 152 | return e_gamma / 12.92f; |
Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 153 | } else { |
Nick Deakin | 594a4ca | 2022-11-16 20:57:42 -0500 | [diff] [blame] | 154 | return pow((e_gamma + 0.055f) / 1.055f, 2.4); |
Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 155 | } |
| 156 | } |
| 157 | |
Nick Deakin | 594a4ca | 2022-11-16 20:57:42 -0500 | [diff] [blame] | 158 | Color srgbInvOetf(Color e_gamma) { |
| 159 | return {{{ srgbInvOetf(e_gamma.r), |
| 160 | srgbInvOetf(e_gamma.g), |
| 161 | srgbInvOetf(e_gamma.b) }}}; |
| 162 | } |
| 163 | |
Harish Mahendrakar | 555a06b | 2022-12-14 09:37:27 -0800 | [diff] [blame] | 164 | // See IEC 61966-2-1, Equations F.5 and F.6. |
| 165 | float srgbInvOetfLUT(float e_gamma) { |
Nick Deakin | d19e576 | 2023-02-10 15:39:08 -0500 | [diff] [blame] | 166 | uint32_t value = static_cast<uint32_t>(e_gamma * kSrgbInvOETFNumEntries); |
Harish Mahendrakar | 555a06b | 2022-12-14 09:37:27 -0800 | [diff] [blame] | 167 | //TODO() : Remove once conversion modules have appropriate clamping in place |
Nick Deakin | d19e576 | 2023-02-10 15:39:08 -0500 | [diff] [blame] | 168 | value = CLIP3(value, 0, kSrgbInvOETFNumEntries - 1); |
| 169 | return kSrgbInvOETF[value]; |
Harish Mahendrakar | 555a06b | 2022-12-14 09:37:27 -0800 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | Color srgbInvOetfLUT(Color e_gamma) { |
| 173 | return {{{ srgbInvOetfLUT(e_gamma.r), |
| 174 | srgbInvOetfLUT(e_gamma.g), |
| 175 | srgbInvOetfLUT(e_gamma.b) }}}; |
| 176 | } |
Nick Deakin | 594a4ca | 2022-11-16 20:57:42 -0500 | [diff] [blame] | 177 | |
| 178 | //////////////////////////////////////////////////////////////////////////////// |
| 179 | // Display-P3 transformations |
| 180 | |
Nick Deakin | 65f492a | 2022-11-29 22:47:40 -0500 | [diff] [blame] | 181 | // See SMPTE EG 432-1, Table 7-2. |
| 182 | static const float kP3R = 0.20949f, kP3G = 0.72160f, kP3B = 0.06891f; |
Nick Deakin | 6bd9043 | 2022-11-20 16:26:37 -0500 | [diff] [blame] | 183 | |
| 184 | float p3Luminance(Color e) { |
| 185 | return kP3R * e.r + kP3G * e.g + kP3B * e.b; |
| 186 | } |
Nick Deakin | 594a4ca | 2022-11-16 20:57:42 -0500 | [diff] [blame] | 187 | |
| 188 | |
| 189 | //////////////////////////////////////////////////////////////////////////////// |
| 190 | // BT.2100 transformations - according to ITU-R BT.2100-2 |
| 191 | |
Nick Deakin | 65f492a | 2022-11-29 22:47:40 -0500 | [diff] [blame] | 192 | // See ITU-R BT.2100-2, Table 5, HLG Reference OOTF |
Nick Deakin | 594a4ca | 2022-11-16 20:57:42 -0500 | [diff] [blame] | 193 | static const float kBt2100R = 0.2627f, kBt2100G = 0.6780f, kBt2100B = 0.0593f; |
| 194 | |
| 195 | float bt2100Luminance(Color e) { |
| 196 | return kBt2100R * e.r + kBt2100G * e.g + kBt2100B * e.b; |
| 197 | } |
| 198 | |
Nick Deakin | 65f492a | 2022-11-29 22:47:40 -0500 | [diff] [blame] | 199 | // See ITU-R BT.2100-2, Table 6, Derivation of colour difference signals. |
Nick Deakin | 594a4ca | 2022-11-16 20:57:42 -0500 | [diff] [blame] | 200 | static const float kBt2100Cb = 1.8814f, kBt2100Cr = 1.4746f; |
| 201 | |
| 202 | Color bt2100RgbToYuv(Color e_gamma) { |
| 203 | float y_gamma = bt2100Luminance(e_gamma); |
| 204 | return {{{ y_gamma, |
| 205 | (e_gamma.b - y_gamma) / kBt2100Cb, |
| 206 | (e_gamma.r - y_gamma) / kBt2100Cr }}}; |
| 207 | } |
| 208 | |
Nick Deakin | 65f492a | 2022-11-29 22:47:40 -0500 | [diff] [blame] | 209 | // Derived by inversing bt2100RgbToYuv. The derivation for R and B are pretty |
| 210 | // straight forward; we just invert the formulas for U and V above. But deriving |
| 211 | // the formula for G is a bit more complicated: |
Nick Deakin | 594a4ca | 2022-11-16 20:57:42 -0500 | [diff] [blame] | 212 | // |
| 213 | // Start with equation for luminance: |
| 214 | // Y = kBt2100R * R + kBt2100G * G + kBt2100B * B |
| 215 | // Solve for G: |
| 216 | // G = (Y - kBt2100R * R - kBt2100B * B) / kBt2100B |
| 217 | // Substitute equations for R and B in terms YUV: |
| 218 | // G = (Y - kBt2100R * (Y + kBt2100Cr * V) - kBt2100B * (Y + kBt2100Cb * U)) / kBt2100B |
| 219 | // Simplify: |
| 220 | // G = Y * ((1 - kBt2100R - kBt2100B) / kBt2100G) |
| 221 | // + U * (kBt2100B * kBt2100Cb / kBt2100G) |
| 222 | // + V * (kBt2100R * kBt2100Cr / kBt2100G) |
| 223 | // |
| 224 | // We then get the following coeficients for calculating G from YUV: |
| 225 | // |
| 226 | // Coef for Y = (1 - kBt2100R - kBt2100B) / kBt2100G = 1 |
| 227 | // Coef for U = kBt2100B * kBt2100Cb / kBt2100G = kBt2100GCb = ~0.1645 |
| 228 | // Coef for V = kBt2100R * kBt2100Cr / kBt2100G = kBt2100GCr = ~0.5713 |
| 229 | |
| 230 | static const float kBt2100GCb = kBt2100B * kBt2100Cb / kBt2100G; |
| 231 | static const float kBt2100GCr = kBt2100R * kBt2100Cr / kBt2100G; |
| 232 | |
| 233 | Color bt2100YuvToRgb(Color e_gamma) { |
Harish Mahendrakar | 1107ff3 | 2022-12-07 17:24:35 -0800 | [diff] [blame] | 234 | return {{{ clampPixelFloat(e_gamma.y + kBt2100Cr * e_gamma.v), |
| 235 | clampPixelFloat(e_gamma.y - kBt2100GCb * e_gamma.u - kBt2100GCr * e_gamma.v), |
| 236 | clampPixelFloat(e_gamma.y + kBt2100Cb * e_gamma.u) }}}; |
Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 237 | } |
| 238 | |
Nick Deakin | 65f492a | 2022-11-29 22:47:40 -0500 | [diff] [blame] | 239 | // See ITU-R BT.2100-2, Table 5, HLG Reference OETF. |
Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 240 | static const float kHlgA = 0.17883277f, kHlgB = 0.28466892f, kHlgC = 0.55991073; |
| 241 | |
Nick Deakin | 65f492a | 2022-11-29 22:47:40 -0500 | [diff] [blame] | 242 | float hlgOetf(float e) { |
Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 243 | if (e <= 1.0f/12.0f) { |
| 244 | return sqrt(3.0f * e); |
| 245 | } else { |
| 246 | return kHlgA * log(12.0f * e - kHlgB) + kHlgC; |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | Color hlgOetf(Color e) { |
| 251 | return {{{ hlgOetf(e.r), hlgOetf(e.g), hlgOetf(e.b) }}}; |
| 252 | } |
| 253 | |
Harish Mahendrakar | 555a06b | 2022-12-14 09:37:27 -0800 | [diff] [blame] | 254 | float hlgOetfLUT(float e) { |
| 255 | uint32_t value = static_cast<uint32_t>(e * kHlgOETFNumEntries); |
| 256 | //TODO() : Remove once conversion modules have appropriate clamping in place |
| 257 | value = CLIP3(value, 0, kHlgOETFNumEntries - 1); |
| 258 | |
| 259 | return kHlgOETF[value]; |
| 260 | } |
| 261 | |
| 262 | Color hlgOetfLUT(Color e) { |
| 263 | return {{{ hlgOetfLUT(e.r), hlgOetfLUT(e.g), hlgOetfLUT(e.b) }}}; |
| 264 | } |
| 265 | |
Nick Deakin | 65f492a | 2022-11-29 22:47:40 -0500 | [diff] [blame] | 266 | // See ITU-R BT.2100-2, Table 5, HLG Reference EOTF. |
| 267 | float hlgInvOetf(float e_gamma) { |
Nick Deakin | 594a4ca | 2022-11-16 20:57:42 -0500 | [diff] [blame] | 268 | if (e_gamma <= 0.5f) { |
| 269 | return pow(e_gamma, 2.0f) / 3.0f; |
| 270 | } else { |
| 271 | return (exp((e_gamma - kHlgC) / kHlgA) + kHlgB) / 12.0f; |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | Color hlgInvOetf(Color e_gamma) { |
| 276 | return {{{ hlgInvOetf(e_gamma.r), |
| 277 | hlgInvOetf(e_gamma.g), |
| 278 | hlgInvOetf(e_gamma.b) }}}; |
| 279 | } |
| 280 | |
Harish Mahendrakar | 555a06b | 2022-12-14 09:37:27 -0800 | [diff] [blame] | 281 | float hlgInvOetfLUT(float e_gamma) { |
| 282 | uint32_t value = static_cast<uint32_t>(e_gamma * kHlgInvOETFNumEntries); |
| 283 | //TODO() : Remove once conversion modules have appropriate clamping in place |
| 284 | value = CLIP3(value, 0, kHlgInvOETFNumEntries - 1); |
| 285 | |
| 286 | return kHlgInvOETF[value]; |
| 287 | } |
| 288 | |
| 289 | Color hlgInvOetfLUT(Color e_gamma) { |
| 290 | return {{{ hlgInvOetfLUT(e_gamma.r), |
| 291 | hlgInvOetfLUT(e_gamma.g), |
| 292 | hlgInvOetfLUT(e_gamma.b) }}}; |
| 293 | } |
| 294 | |
Nick Deakin | 65f492a | 2022-11-29 22:47:40 -0500 | [diff] [blame] | 295 | // See ITU-R BT.2100-2, Table 4, Reference PQ OETF. |
Nick Deakin | 6bd9043 | 2022-11-20 16:26:37 -0500 | [diff] [blame] | 296 | static const float kPqM1 = 2610.0f / 16384.0f, kPqM2 = 2523.0f / 4096.0f * 128.0f; |
| 297 | static const float kPqC1 = 3424.0f / 4096.0f, kPqC2 = 2413.0f / 4096.0f * 32.0f, |
| 298 | kPqC3 = 2392.0f / 4096.0f * 32.0f; |
| 299 | |
Nick Deakin | 65f492a | 2022-11-29 22:47:40 -0500 | [diff] [blame] | 300 | float pqOetf(float e) { |
| 301 | if (e <= 0.0f) return 0.0f; |
| 302 | return pow((kPqC1 + kPqC2 * pow(e, kPqM1)) / (1 + kPqC3 * pow(e, kPqM1)), |
Nick Deakin | 6bd9043 | 2022-11-20 16:26:37 -0500 | [diff] [blame] | 303 | kPqM2); |
| 304 | } |
| 305 | |
| 306 | Color pqOetf(Color e) { |
| 307 | return {{{ pqOetf(e.r), pqOetf(e.g), pqOetf(e.b) }}}; |
| 308 | } |
| 309 | |
Harish Mahendrakar | 555a06b | 2022-12-14 09:37:27 -0800 | [diff] [blame] | 310 | float pqOetfLUT(float e) { |
| 311 | uint32_t value = static_cast<uint32_t>(e * kPqOETFNumEntries); |
| 312 | //TODO() : Remove once conversion modules have appropriate clamping in place |
| 313 | value = CLIP3(value, 0, kPqOETFNumEntries - 1); |
| 314 | |
| 315 | return kPqOETF[value]; |
| 316 | } |
| 317 | |
| 318 | Color pqOetfLUT(Color e) { |
| 319 | return {{{ pqOetfLUT(e.r), pqOetfLUT(e.g), pqOetfLUT(e.b) }}}; |
| 320 | } |
| 321 | |
Nick Deakin | 65f492a | 2022-11-29 22:47:40 -0500 | [diff] [blame] | 322 | // Derived from the inverse of the Reference PQ OETF. |
| 323 | static const float kPqInvA = 128.0f, kPqInvB = 107.0f, kPqInvC = 2413.0f, kPqInvD = 2392.0f, |
| 324 | kPqInvE = 6.2773946361f, kPqInvF = 0.0126833f; |
| 325 | |
| 326 | float pqInvOetf(float e_gamma) { |
| 327 | // This equation blows up if e_gamma is 0.0, and checking on <= 0.0 doesn't |
| 328 | // always catch 0.0. So, check on 0.0001, since anything this small will |
| 329 | // effectively be crushed to zero anyways. |
| 330 | if (e_gamma <= 0.0001f) return 0.0f; |
| 331 | return pow((kPqInvA * pow(e_gamma, kPqInvF) - kPqInvB) |
| 332 | / (kPqInvC - kPqInvD * pow(e_gamma, kPqInvF)), |
| 333 | kPqInvE); |
Nick Deakin | 6bd9043 | 2022-11-20 16:26:37 -0500 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | Color pqInvOetf(Color e_gamma) { |
| 337 | return {{{ pqInvOetf(e_gamma.r), |
| 338 | pqInvOetf(e_gamma.g), |
| 339 | pqInvOetf(e_gamma.b) }}}; |
| 340 | } |
| 341 | |
Harish Mahendrakar | 555a06b | 2022-12-14 09:37:27 -0800 | [diff] [blame] | 342 | float pqInvOetfLUT(float e_gamma) { |
| 343 | uint32_t value = static_cast<uint32_t>(e_gamma * kPqInvOETFNumEntries); |
| 344 | //TODO() : Remove once conversion modules have appropriate clamping in place |
| 345 | value = CLIP3(value, 0, kPqInvOETFNumEntries - 1); |
| 346 | |
| 347 | return kPqInvOETF[value]; |
| 348 | } |
| 349 | |
| 350 | Color pqInvOetfLUT(Color e_gamma) { |
| 351 | return {{{ pqInvOetfLUT(e_gamma.r), |
| 352 | pqInvOetfLUT(e_gamma.g), |
| 353 | pqInvOetfLUT(e_gamma.b) }}}; |
| 354 | } |
| 355 | |
Nick Deakin | 594a4ca | 2022-11-16 20:57:42 -0500 | [diff] [blame] | 356 | |
| 357 | //////////////////////////////////////////////////////////////////////////////// |
| 358 | // Color conversions |
| 359 | |
Nick Deakin | 6bd9043 | 2022-11-20 16:26:37 -0500 | [diff] [blame] | 360 | Color bt709ToP3(Color e) { |
| 361 | return {{{ 0.82254f * e.r + 0.17755f * e.g + 0.00006f * e.b, |
| 362 | 0.03312f * e.r + 0.96684f * e.g + -0.00001f * e.b, |
| 363 | 0.01706f * e.r + 0.07240f * e.g + 0.91049f * e.b }}}; |
| 364 | } |
| 365 | |
| 366 | Color bt709ToBt2100(Color e) { |
| 367 | return {{{ 0.62740f * e.r + 0.32930f * e.g + 0.04332f * e.b, |
| 368 | 0.06904f * e.r + 0.91958f * e.g + 0.01138f * e.b, |
| 369 | 0.01636f * e.r + 0.08799f * e.g + 0.89555f * e.b }}}; |
| 370 | } |
| 371 | |
| 372 | Color p3ToBt709(Color e) { |
| 373 | return {{{ 1.22482f * e.r + -0.22490f * e.g + -0.00007f * e.b, |
| 374 | -0.04196f * e.r + 1.04199f * e.g + 0.00001f * e.b, |
| 375 | -0.01961f * e.r + -0.07865f * e.g + 1.09831f * e.b }}}; |
| 376 | } |
| 377 | |
| 378 | Color p3ToBt2100(Color e) { |
| 379 | return {{{ 0.75378f * e.r + 0.19862f * e.g + 0.04754f * e.b, |
| 380 | 0.04576f * e.r + 0.94177f * e.g + 0.01250f * e.b, |
| 381 | -0.00121f * e.r + 0.01757f * e.g + 0.98359f * e.b }}}; |
| 382 | } |
| 383 | |
| 384 | Color bt2100ToBt709(Color e) { |
| 385 | return {{{ 1.66045f * e.r + -0.58764f * e.g + -0.07286f * e.b, |
| 386 | -0.12445f * e.r + 1.13282f * e.g + -0.00837f * e.b, |
| 387 | -0.01811f * e.r + -0.10057f * e.g + 1.11878f * e.b }}}; |
| 388 | } |
| 389 | |
| 390 | Color bt2100ToP3(Color e) { |
| 391 | return {{{ 1.34369f * e.r + -0.28223f * e.g + -0.06135f * e.b, |
| 392 | -0.06533f * e.r + 1.07580f * e.g + -0.01051f * e.b, |
| 393 | 0.00283f * e.r + -0.01957f * e.g + 1.01679f * e.b |
| 394 | }}}; |
| 395 | } |
| 396 | |
| 397 | // TODO: confirm we always want to convert like this before calculating |
| 398 | // luminance. |
| 399 | ColorTransformFn getHdrConversionFn(jpegr_color_gamut sdr_gamut, jpegr_color_gamut hdr_gamut) { |
Nick Deakin | 65f492a | 2022-11-29 22:47:40 -0500 | [diff] [blame] | 400 | switch (sdr_gamut) { |
Nick Deakin | 6bd9043 | 2022-11-20 16:26:37 -0500 | [diff] [blame] | 401 | case JPEGR_COLORGAMUT_BT709: |
| 402 | switch (hdr_gamut) { |
| 403 | case JPEGR_COLORGAMUT_BT709: |
| 404 | return identityConversion; |
| 405 | case JPEGR_COLORGAMUT_P3: |
| 406 | return p3ToBt709; |
| 407 | case JPEGR_COLORGAMUT_BT2100: |
| 408 | return bt2100ToBt709; |
| 409 | case JPEGR_COLORGAMUT_UNSPECIFIED: |
| 410 | return nullptr; |
| 411 | } |
| 412 | break; |
| 413 | case JPEGR_COLORGAMUT_P3: |
| 414 | switch (hdr_gamut) { |
| 415 | case JPEGR_COLORGAMUT_BT709: |
| 416 | return bt709ToP3; |
| 417 | case JPEGR_COLORGAMUT_P3: |
| 418 | return identityConversion; |
| 419 | case JPEGR_COLORGAMUT_BT2100: |
| 420 | return bt2100ToP3; |
| 421 | case JPEGR_COLORGAMUT_UNSPECIFIED: |
| 422 | return nullptr; |
| 423 | } |
| 424 | break; |
| 425 | case JPEGR_COLORGAMUT_BT2100: |
| 426 | switch (hdr_gamut) { |
| 427 | case JPEGR_COLORGAMUT_BT709: |
| 428 | return bt709ToBt2100; |
| 429 | case JPEGR_COLORGAMUT_P3: |
| 430 | return p3ToBt2100; |
| 431 | case JPEGR_COLORGAMUT_BT2100: |
| 432 | return identityConversion; |
| 433 | case JPEGR_COLORGAMUT_UNSPECIFIED: |
| 434 | return nullptr; |
| 435 | } |
| 436 | break; |
| 437 | case JPEGR_COLORGAMUT_UNSPECIFIED: |
| 438 | return nullptr; |
| 439 | } |
| 440 | } |
| 441 | |
Nick Deakin | 594a4ca | 2022-11-16 20:57:42 -0500 | [diff] [blame] | 442 | |
| 443 | //////////////////////////////////////////////////////////////////////////////// |
| 444 | // Recovery map calculations |
Nick Deakin | d19e576 | 2023-02-10 15:39:08 -0500 | [diff] [blame] | 445 | uint8_t encodeRecovery(float y_sdr, float y_hdr, jr_metadata_ptr metadata) { |
Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 446 | float gain = 1.0f; |
| 447 | if (y_sdr > 0.0f) { |
| 448 | gain = y_hdr / y_sdr; |
| 449 | } |
| 450 | |
Nick Deakin | d19e576 | 2023-02-10 15:39:08 -0500 | [diff] [blame] | 451 | if (gain < metadata->minContentBoost) gain = metadata->minContentBoost; |
| 452 | if (gain > metadata->maxContentBoost) gain = metadata->maxContentBoost; |
Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 453 | |
Nick Deakin | d19e576 | 2023-02-10 15:39:08 -0500 | [diff] [blame] | 454 | return static_cast<uint8_t>((log2(gain) - log2(metadata->minContentBoost)) |
| 455 | / (log2(metadata->maxContentBoost) - log2(metadata->minContentBoost)) |
| 456 | * 255.0f); |
Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 457 | } |
| 458 | |
Nick Deakin | d19e576 | 2023-02-10 15:39:08 -0500 | [diff] [blame] | 459 | Color applyRecovery(Color e, float recovery, jr_metadata_ptr metadata) { |
| 460 | float logBoost = log2(metadata->minContentBoost) * (1.0f - recovery) |
| 461 | + log2(metadata->maxContentBoost) * recovery; |
| 462 | float recoveryFactor = exp2(logBoost); |
Harish Mahendrakar | a5ddcc2 | 2022-12-13 12:45:23 -0800 | [diff] [blame] | 463 | return e * recoveryFactor; |
Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 464 | } |
| 465 | |
Dichen Zhang | c660570 | 2023-03-15 18:40:55 -0700 | [diff] [blame] | 466 | Color applyRecovery(Color e, float recovery, jr_metadata_ptr metadata, float displayBoost) { |
| 467 | float logBoost = log2(metadata->minContentBoost) * (1.0f - recovery) |
| 468 | + log2(metadata->maxContentBoost) * recovery; |
| 469 | float recoveryFactor = exp2(logBoost * displayBoost / metadata->maxContentBoost); |
| 470 | return e * recoveryFactor; |
| 471 | } |
| 472 | |
Harish Mahendrakar | f25991f | 2022-12-16 11:57:44 -0800 | [diff] [blame] | 473 | Color applyRecoveryLUT(Color e, float recovery, RecoveryLUT& recoveryLUT) { |
| 474 | float recoveryFactor = recoveryLUT.getRecoveryFactor(recovery); |
| 475 | return e * recoveryFactor; |
| 476 | } |
| 477 | |
Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 478 | Color getYuv420Pixel(jr_uncompressed_ptr image, size_t x, size_t y) { |
| 479 | size_t pixel_count = image->width * image->height; |
| 480 | |
| 481 | size_t pixel_y_idx = x + y * image->width; |
| 482 | size_t pixel_uv_idx = x / 2 + (y / 2) * (image->width / 2); |
| 483 | |
| 484 | uint8_t y_uint = reinterpret_cast<uint8_t*>(image->data)[pixel_y_idx]; |
| 485 | uint8_t u_uint = reinterpret_cast<uint8_t*>(image->data)[pixel_count + pixel_uv_idx]; |
| 486 | uint8_t v_uint = reinterpret_cast<uint8_t*>(image->data)[pixel_count * 5 / 4 + pixel_uv_idx]; |
| 487 | |
| 488 | // 128 bias for UV given we are using jpeglib; see: |
| 489 | // https://github.com/kornelski/libjpeg/blob/master/structure.doc |
| 490 | return {{{ static_cast<float>(y_uint) / 255.0f, |
| 491 | (static_cast<float>(u_uint) - 128.0f) / 255.0f, |
| 492 | (static_cast<float>(v_uint) - 128.0f) / 255.0f }}}; |
| 493 | } |
| 494 | |
Nick Deakin | 594a4ca | 2022-11-16 20:57:42 -0500 | [diff] [blame] | 495 | Color getP010Pixel(jr_uncompressed_ptr image, size_t x, size_t y) { |
| 496 | size_t pixel_count = image->width * image->height; |
Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 497 | |
Nick Deakin | 594a4ca | 2022-11-16 20:57:42 -0500 | [diff] [blame] | 498 | size_t pixel_y_idx = x + y * image->width; |
| 499 | size_t pixel_uv_idx = x / 2 + (y / 2) * (image->width / 2); |
| 500 | |
Nick Deakin | 86207ba | 2022-11-21 16:07:36 -0500 | [diff] [blame] | 501 | uint16_t y_uint = reinterpret_cast<uint16_t*>(image->data)[pixel_y_idx] |
| 502 | >> 6; |
| 503 | uint16_t u_uint = reinterpret_cast<uint16_t*>(image->data)[pixel_count + pixel_uv_idx * 2] |
| 504 | >> 6; |
| 505 | uint16_t v_uint = reinterpret_cast<uint16_t*>(image->data)[pixel_count + pixel_uv_idx * 2 + 1] |
| 506 | >> 6; |
Nick Deakin | 594a4ca | 2022-11-16 20:57:42 -0500 | [diff] [blame] | 507 | |
| 508 | // Conversions include taking narrow-range into account. |
Nick Deakin | 3812533 | 2022-12-12 15:48:24 -0500 | [diff] [blame] | 509 | return {{{ (static_cast<float>(y_uint) - 64.0f) / 876.0f, |
| 510 | (static_cast<float>(u_uint) - 64.0f) / 896.0f - 0.5f, |
| 511 | (static_cast<float>(v_uint) - 64.0f) / 896.0f - 0.5f }}}; |
Nick Deakin | 594a4ca | 2022-11-16 20:57:42 -0500 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | typedef Color (*getPixelFn)(jr_uncompressed_ptr, size_t, size_t); |
| 515 | |
| 516 | static Color samplePixels(jr_uncompressed_ptr image, size_t map_scale_factor, size_t x, size_t y, |
| 517 | getPixelFn get_pixel_fn) { |
| 518 | Color e = {{{ 0.0f, 0.0f, 0.0f }}}; |
Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 519 | for (size_t dy = 0; dy < map_scale_factor; ++dy) { |
| 520 | for (size_t dx = 0; dx < map_scale_factor; ++dx) { |
Nick Deakin | 594a4ca | 2022-11-16 20:57:42 -0500 | [diff] [blame] | 521 | e += get_pixel_fn(image, x * map_scale_factor + dx, y * map_scale_factor + dy); |
Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 522 | } |
| 523 | } |
| 524 | |
| 525 | return e / static_cast<float>(map_scale_factor * map_scale_factor); |
| 526 | } |
| 527 | |
Nick Deakin | 594a4ca | 2022-11-16 20:57:42 -0500 | [diff] [blame] | 528 | Color sampleYuv420(jr_uncompressed_ptr image, size_t map_scale_factor, size_t x, size_t y) { |
| 529 | return samplePixels(image, map_scale_factor, x, y, getYuv420Pixel); |
Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 530 | } |
| 531 | |
Nick Deakin | 594a4ca | 2022-11-16 20:57:42 -0500 | [diff] [blame] | 532 | Color sampleP010(jr_uncompressed_ptr image, size_t map_scale_factor, size_t x, size_t y) { |
| 533 | return samplePixels(image, map_scale_factor, x, y, getP010Pixel); |
Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 534 | } |
Nick Deakin | 5c20b9e | 2022-11-15 17:39:24 -0500 | [diff] [blame] | 535 | |
Nick Deakin | 65f492a | 2022-11-29 22:47:40 -0500 | [diff] [blame] | 536 | // TODO: do we need something more clever for filtering either the map or images |
| 537 | // to generate the map? |
| 538 | |
| 539 | static size_t clamp(const size_t& val, const size_t& low, const size_t& high) { |
| 540 | return val < low ? low : (high < val ? high : val); |
| 541 | } |
| 542 | |
| 543 | static float mapUintToFloat(uint8_t map_uint) { |
Nick Deakin | d19e576 | 2023-02-10 15:39:08 -0500 | [diff] [blame] | 544 | return static_cast<float>(map_uint) / 255.0f; |
Nick Deakin | 65f492a | 2022-11-29 22:47:40 -0500 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | static float pythDistance(float x_diff, float y_diff) { |
| 548 | return sqrt(pow(x_diff, 2.0f) + pow(y_diff, 2.0f)); |
| 549 | } |
| 550 | |
Ram Mohan | fe723d6 | 2022-12-15 00:59:11 +0530 | [diff] [blame] | 551 | // TODO: If map_scale_factor is guaranteed to be an integer, then remove the following. |
Nick Deakin | d19e576 | 2023-02-10 15:39:08 -0500 | [diff] [blame] | 552 | float sampleMap(jr_uncompressed_ptr map, float map_scale_factor, size_t x, size_t y) { |
| 553 | float x_map = static_cast<float>(x) / map_scale_factor; |
| 554 | float y_map = static_cast<float>(y) / map_scale_factor; |
Nick Deakin | 65f492a | 2022-11-29 22:47:40 -0500 | [diff] [blame] | 555 | |
| 556 | size_t x_lower = static_cast<size_t>(floor(x_map)); |
| 557 | size_t x_upper = x_lower + 1; |
| 558 | size_t y_lower = static_cast<size_t>(floor(y_map)); |
| 559 | size_t y_upper = y_lower + 1; |
| 560 | |
| 561 | x_lower = clamp(x_lower, 0, map->width - 1); |
| 562 | x_upper = clamp(x_upper, 0, map->width - 1); |
| 563 | y_lower = clamp(y_lower, 0, map->height - 1); |
| 564 | y_upper = clamp(y_upper, 0, map->height - 1); |
| 565 | |
| 566 | // Use Shepard's method for inverse distance weighting. For more information: |
| 567 | // en.wikipedia.org/wiki/Inverse_distance_weighting#Shepard's_method |
| 568 | |
| 569 | float e1 = mapUintToFloat(reinterpret_cast<uint8_t*>(map->data)[x_lower + y_lower * map->width]); |
| 570 | float e1_dist = pythDistance(x_map - static_cast<float>(x_lower), |
| 571 | y_map - static_cast<float>(y_lower)); |
| 572 | if (e1_dist == 0.0f) return e1; |
| 573 | |
| 574 | float e2 = mapUintToFloat(reinterpret_cast<uint8_t*>(map->data)[x_lower + y_upper * map->width]); |
| 575 | float e2_dist = pythDistance(x_map - static_cast<float>(x_lower), |
| 576 | y_map - static_cast<float>(y_upper)); |
| 577 | if (e2_dist == 0.0f) return e2; |
| 578 | |
| 579 | float e3 = mapUintToFloat(reinterpret_cast<uint8_t*>(map->data)[x_upper + y_lower * map->width]); |
| 580 | float e3_dist = pythDistance(x_map - static_cast<float>(x_upper), |
| 581 | y_map - static_cast<float>(y_lower)); |
| 582 | if (e3_dist == 0.0f) return e3; |
| 583 | |
| 584 | float e4 = mapUintToFloat(reinterpret_cast<uint8_t*>(map->data)[x_upper + y_upper * map->width]); |
| 585 | float e4_dist = pythDistance(x_map - static_cast<float>(x_upper), |
| 586 | y_map - static_cast<float>(y_upper)); |
| 587 | if (e4_dist == 0.0f) return e2; |
| 588 | |
| 589 | float e1_weight = 1.0f / e1_dist; |
| 590 | float e2_weight = 1.0f / e2_dist; |
| 591 | float e3_weight = 1.0f / e3_dist; |
| 592 | float e4_weight = 1.0f / e4_dist; |
| 593 | float total_weight = e1_weight + e2_weight + e3_weight + e4_weight; |
| 594 | |
| 595 | return e1 * (e1_weight / total_weight) |
| 596 | + e2 * (e2_weight / total_weight) |
| 597 | + e3 * (e3_weight / total_weight) |
| 598 | + e4 * (e4_weight / total_weight); |
| 599 | } |
| 600 | |
Ram Mohan | fe723d6 | 2022-12-15 00:59:11 +0530 | [diff] [blame] | 601 | float sampleMap(jr_uncompressed_ptr map, size_t map_scale_factor, size_t x, size_t y, |
| 602 | ShepardsIDW& weightTables) { |
| 603 | // TODO: If map_scale_factor is guaranteed to be an integer power of 2, then optimize the |
| 604 | // following by computing log2(map_scale_factor) once and then using >> log2(map_scale_factor) |
| 605 | int x_lower = x / map_scale_factor; |
| 606 | int x_upper = x_lower + 1; |
| 607 | int y_lower = y / map_scale_factor; |
| 608 | int y_upper = y_lower + 1; |
| 609 | |
| 610 | x_lower = std::min(x_lower, map->width - 1); |
| 611 | x_upper = std::min(x_upper, map->width - 1); |
| 612 | y_lower = std::min(y_lower, map->height - 1); |
| 613 | y_upper = std::min(y_upper, map->height - 1); |
| 614 | |
| 615 | float e1 = mapUintToFloat(reinterpret_cast<uint8_t*>(map->data)[x_lower + y_lower * map->width]); |
| 616 | float e2 = mapUintToFloat(reinterpret_cast<uint8_t*>(map->data)[x_lower + y_upper * map->width]); |
| 617 | float e3 = mapUintToFloat(reinterpret_cast<uint8_t*>(map->data)[x_upper + y_lower * map->width]); |
| 618 | float e4 = mapUintToFloat(reinterpret_cast<uint8_t*>(map->data)[x_upper + y_upper * map->width]); |
| 619 | |
| 620 | // TODO: If map_scale_factor is guaranteed to be an integer power of 2, then optimize the |
| 621 | // following by using & (map_scale_factor - 1) |
| 622 | int offset_x = x % map_scale_factor; |
| 623 | int offset_y = y % map_scale_factor; |
| 624 | |
| 625 | float* weights = weightTables.mWeights; |
| 626 | if (x_lower == x_upper && y_lower == y_upper) weights = weightTables.mWeightsC; |
| 627 | else if (x_lower == x_upper) weights = weightTables.mWeightsNR; |
| 628 | else if (y_lower == y_upper) weights = weightTables.mWeightsNB; |
| 629 | weights += offset_y * map_scale_factor * 4 + offset_x * 4; |
| 630 | |
| 631 | return e1 * weights[0] + e2 * weights[1] + e3 * weights[2] + e4 * weights[3]; |
| 632 | } |
| 633 | |
Nick Deakin | 6bd9043 | 2022-11-20 16:26:37 -0500 | [diff] [blame] | 634 | uint32_t colorToRgba1010102(Color e_gamma) { |
| 635 | return (0x3ff & static_cast<uint32_t>(e_gamma.r * 1023.0f)) |
| 636 | | ((0x3ff & static_cast<uint32_t>(e_gamma.g * 1023.0f)) << 10) |
| 637 | | ((0x3ff & static_cast<uint32_t>(e_gamma.b * 1023.0f)) << 20) |
| 638 | | (0x3 << 30); // Set alpha to 1.0 |
| 639 | } |
| 640 | |
Dichen Zhang | 3e5798c | 2023-03-01 22:30:43 +0000 | [diff] [blame] | 641 | uint64_t colorToRgbaF16(Color e_gamma) { |
| 642 | return (uint64_t) floatToHalf(e_gamma.r) |
| 643 | | (((uint64_t) floatToHalf(e_gamma.g)) << 16) |
| 644 | | (((uint64_t) floatToHalf(e_gamma.b)) << 32) |
| 645 | | (((uint64_t) floatToHalf(1.0f)) << 48); |
| 646 | } |
| 647 | |
Dichen Zhang | b2ed830 | 2023-02-10 23:05:04 +0000 | [diff] [blame] | 648 | } // namespace android::jpegrecoverymap |