| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkColorPriv.h" | 8 #include "SkColorPriv.h" |
| 9 #include "SkColorSpace_Base.h" | 9 #include "SkColorSpace_Base.h" |
| 10 #include "SkColorSpaceXform.h" | 10 #include "SkColorSpaceXform.h" |
| 11 #include "SkOpts.h" | 11 #include "SkColorSpaceXformOpts.h" |
| 12 #include "SkSRGB.h" | 12 #include "SkSRGB.h" |
| 13 | 13 |
| 14 static constexpr float sk_linear_from_2dot2[256] = { | 14 static constexpr float sk_linear_from_2dot2[256] = { |
| 15 0.000000000000000000f, 0.000005077051900662f, 0.000023328004666099f, 0.0
00056921765712193f, | 15 0.000000000000000000f, 0.000005077051900662f, 0.000023328004666099f, 0.0
00056921765712193f, |
| 16 0.000107187362341244f, 0.000175123977503027f, 0.000261543754548491f, 0.0
00367136269815943f, | 16 0.000107187362341244f, 0.000175123977503027f, 0.000261543754548491f, 0.0
00367136269815943f, |
| 17 0.000492503787191433f, 0.000638182842167022f, 0.000804658499513058f, 0.0
00992374304074325f, | 17 0.000492503787191433f, 0.000638182842167022f, 0.000804658499513058f, 0.0
00992374304074325f, |
| 18 0.001201739522438400f, 0.001433134589671860f, 0.001686915316789280f, 0.0
01963416213396470f, | 18 0.001201739522438400f, 0.001433134589671860f, 0.001686915316789280f, 0.0
01963416213396470f, |
| 19 0.002262953160706430f, 0.002585825596234170f, 0.002932318323938360f, 0.0
03302703032003640f, | 19 0.002262953160706430f, 0.002585825596234170f, 0.002932318323938360f, 0.0
03302703032003640f, |
| 20 0.003697239578900130f, 0.004116177093282750f, 0.004559754922526020f, 0.0
05028203456855540f, | 20 0.003697239578900130f, 0.004116177093282750f, 0.004559754922526020f, 0.0
05028203456855540f, |
| 21 0.005521744850239660f, 0.006040593654849810f, 0.006584957382581690f, 0.0
07155037004573030f, | 21 0.005521744850239660f, 0.006040593654849810f, 0.006584957382581690f, 0.0
07155037004573030f, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 0.751895080583051000f, 0.759299550695091000f, 0.766743616862161000f, 0.7
74227314218442000f, | 71 0.751895080583051000f, 0.759299550695091000f, 0.766743616862161000f, 0.7
74227314218442000f, |
| 72 0.781750677773962000f, 0.789313742415586000f, 0.796916542907978000f, 0.8
04559113894567000f, | 72 0.781750677773962000f, 0.789313742415586000f, 0.796916542907978000f, 0.8
04559113894567000f, |
| 73 0.812241489898490000f, 0.819963705323528000f, 0.827725794455034000f, 0.8
35527791460841000f, | 73 0.812241489898490000f, 0.819963705323528000f, 0.827725794455034000f, 0.8
35527791460841000f, |
| 74 0.843369730392169000f, 0.851251645184515000f, 0.859173569658532000f, 0.8
67135537520905000f, | 74 0.843369730392169000f, 0.851251645184515000f, 0.859173569658532000f, 0.8
67135537520905000f, |
| 75 0.875137582365205000f, 0.883179737672745000f, 0.891262036813419000f, 0.8
99384513046529000f, | 75 0.875137582365205000f, 0.883179737672745000f, 0.891262036813419000f, 0.8
99384513046529000f, |
| 76 0.907547199521614000f, 0.915750129279253000f, 0.923993335251873000f, 0.9
32276850264543000f, | 76 0.907547199521614000f, 0.915750129279253000f, 0.923993335251873000f, 0.9
32276850264543000f, |
| 77 0.940600707035753000f, 0.948964938178195000f, 0.957369576199527000f, 0.9
65814653503130000f, | 77 0.940600707035753000f, 0.948964938178195000f, 0.957369576199527000f, 0.9
65814653503130000f, |
| 78 0.974300202388861000f, 0.982826255053791000f, 0.991392843592940000f, 1.0
00000000000000000f, | 78 0.974300202388861000f, 0.982826255053791000f, 0.991392843592940000f, 1.0
00000000000000000f, |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 static void build_table_linear_from_gamma(float* outTable, float exponent) { | |
| 82 for (float x = 0.0f; x <= 1.0f; x += (1.0f/255.0f)) { | |
| 83 *outTable++ = powf(x, exponent); | |
| 84 } | |
| 85 } | |
| 86 | |
| 87 // Interpolating lookup in a variably sized table. | |
| 88 static float interp_lut(float input, const float* table, int tableSize) { | |
| 89 float index = input * (tableSize - 1); | |
| 90 float diff = index - sk_float_floor2int(index); | |
| 91 return table[(int) sk_float_floor2int(index)] * (1.0f - diff) + | |
| 92 table[(int) sk_float_ceil2int(index)] * diff; | |
| 93 } | |
| 94 | |
| 95 // outTable is always 256 entries, inTable may be larger or smaller. | |
| 96 static void build_table_linear_from_gamma(float* outTable, const float* inTable, | |
| 97 int inTableSize) { | |
| 98 if (256 == inTableSize) { | |
| 99 memcpy(outTable, inTable, sizeof(float) * 256); | |
| 100 return; | |
| 101 } | |
| 102 | |
| 103 for (float x = 0.0f; x <= 1.0f; x += (1.0f/255.0f)) { | |
| 104 *outTable++ = interp_lut(x, inTable, inTableSize); | |
| 105 } | |
| 106 } | |
| 107 | |
| 108 static void build_table_linear_from_gamma(float* outTable, float g, float a, flo
at b, float c, | |
| 109 float d, float e, float f) { | |
| 110 // Y = (aX + b)^g + c for X >= d | |
| 111 // Y = eX + f otherwise | |
| 112 for (float x = 0.0f; x <= 1.0f; x += (1.0f/255.0f)) { | |
| 113 if (x >= d) { | |
| 114 *outTable++ = powf(a * x + b, g) + c; | |
| 115 } else { | |
| 116 *outTable++ = e * x + f; | |
| 117 } | |
| 118 } | |
| 119 } | |
| 120 | |
| 121 static inline bool compute_gamut_xform(SkMatrix44* srcToDst, const SkMatrix44& s
rcToXYZ, | |
| 122 const SkMatrix44& dstToXYZ) { | |
| 123 if (!dstToXYZ.invert(srcToDst)) { | |
| 124 return false; | |
| 125 } | |
| 126 | |
| 127 srcToDst->postConcat(srcToXYZ); | |
| 128 return true; | |
| 129 } | |
| 130 | |
| 131 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 81 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 132 | 82 |
| 133 static constexpr uint8_t linear_to_srgb[1024] = { | 83 static constexpr uint8_t linear_to_srgb[1024] = { |
| 134 0, 3, 6, 10, 13, 15, 18, 20, 22, 23, 25, 27, 28, 30, 3
1, 32, 34, 35, | 84 0, 3, 6, 10, 13, 15, 18, 20, 22, 23, 25, 27, 28, 30, 3
1, 32, 34, 35, |
| 135 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 4
9, 50, 51, 52, | 85 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 4
9, 50, 51, 52, |
| 136 53, 53, 54, 55, 56, 56, 57, 58, 58, 59, 60, 61, 61, 62, 6
2, 63, 64, 64, | 86 53, 53, 54, 55, 56, 56, 57, 58, 58, 59, 60, 61, 61, 62, 6
2, 63, 64, 64, |
| 137 65, 66, 66, 67, 67, 68, 68, 69, 70, 70, 71, 71, 72, 72, 7
3, 73, 74, 74, | 87 65, 66, 66, 67, 67, 68, 68, 69, 70, 70, 71, 71, 72, 72, 7
3, 73, 74, 74, |
| 138 75, 76, 76, 77, 77, 78, 78, 79, 79, 79, 80, 80, 81, 81, 8
2, 82, 83, 83, | 88 75, 76, 76, 77, 77, 78, 78, 79, 79, 79, 80, 80, 81, 81, 8
2, 82, 83, 83, |
| 139 84, 84, 85, 85, 85, 86, 86, 87, 87, 88, 88, 88, 89, 89, 9
0, 90, 91, 91, | 89 84, 84, 85, 85, 85, 86, 86, 87, 87, 88, 88, 88, 89, 89, 9
0, 90, 91, 91, |
| 140 91, 92, 92, 93, 93, 93, 94, 94, 95, 95, 95, 96, 96, 97, 9
7, 97, 98, 98, | 90 91, 92, 92, 93, 93, 93, 94, 94, 95, 95, 95, 96, 96, 97, 9
7, 97, 98, 98, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 239, 239, 239, 239, 239, 239, 240, 240, 240, 240, 240, 240, 240, 240, 24
1, 241, 241, 241, | 133 239, 239, 239, 239, 239, 239, 240, 240, 240, 240, 240, 240, 240, 240, 24
1, 241, 241, 241, |
| 184 241, 241, 241, 241, 241, 242, 242, 242, 242, 242, 242, 242, 242, 243, 24
3, 243, 243, 243, | 134 241, 241, 241, 241, 241, 242, 242, 242, 242, 242, 242, 242, 242, 243, 24
3, 243, 243, 243, |
| 185 243, 243, 243, 243, 244, 244, 244, 244, 244, 244, 244, 244, 245, 245, 24
5, 245, 245, 245, | 135 243, 243, 243, 243, 244, 244, 244, 244, 244, 244, 244, 244, 245, 245, 24
5, 245, 245, 245, |
| 186 245, 245, 245, 246, 246, 246, 246, 246, 246, 246, 246, 246, 247, 247, 24
7, 247, 247, 247, | 136 245, 245, 245, 246, 246, 246, 246, 246, 246, 246, 246, 246, 247, 247, 24
7, 247, 247, 247, |
| 187 247, 247, 248, 248, 248, 248, 248, 248, 248, 248, 248, 249, 249, 249, 24
9, 249, 249, 249, | 137 247, 247, 248, 248, 248, 248, 248, 248, 248, 248, 248, 249, 249, 249, 24
9, 249, 249, 249, |
| 188 249, 249, 250, 250, 250, 250, 250, 250, 250, 250, 250, 251, 251, 251, 25
1, 251, 251, 251, | 138 249, 249, 250, 250, 250, 250, 250, 250, 250, 250, 250, 251, 251, 251, 25
1, 251, 251, 251, |
| 189 251, 251, 252, 252, 252, 252, 252, 252, 252, 252, 252, 253, 253, 253, 25
3, 253, 253, 253, | 139 251, 251, 252, 252, 252, 252, 252, 252, 252, 252, 252, 253, 253, 253, 25
3, 253, 253, 253, |
| 190 253, 253, 254, 254, 254, 254, 254, 254, 254, 254, 254, 255, 255, 255, 25
5, 255 | 140 253, 253, 254, 254, 254, 254, 254, 254, 254, 254, 254, 255, 255, 255, 25
5, 255 |
| 191 }; | 141 }; |
| 192 | 142 |
| 193 static constexpr uint8_t linear_to_2dot2[1024] = { | 143 static constexpr uint8_t linear_to_2dot2_table[1024] = { |
| 194 0, 11, 15, 18, 21, 23, 25, 26, 28, 30, 31, 32, 34, 35, 3
6, 37, 39, 40, | 144 0, 11, 15, 18, 21, 23, 25, 26, 28, 30, 31, 32, 34, 35, 3
6, 37, 39, 40, |
| 195 41, 42, 43, 44, 45, 45, 46, 47, 48, 49, 50, 50, 51, 52, 5
3, 54, 54, 55, | 145 41, 42, 43, 44, 45, 45, 46, 47, 48, 49, 50, 50, 51, 52, 5
3, 54, 54, 55, |
| 196 56, 56, 57, 58, 58, 59, 60, 60, 61, 62, 62, 63, 63, 64, 6
5, 65, 66, 66, | 146 56, 56, 57, 58, 58, 59, 60, 60, 61, 62, 62, 63, 63, 64, 6
5, 65, 66, 66, |
| 197 67, 68, 68, 69, 69, 70, 70, 71, 71, 72, 72, 73, 73, 74, 7
4, 75, 75, 76, | 147 67, 68, 68, 69, 69, 70, 70, 71, 71, 72, 72, 73, 73, 74, 7
4, 75, 75, 76, |
| 198 76, 77, 77, 78, 78, 79, 79, 80, 80, 81, 81, 81, 82, 82, 8
3, 83, 84, 84, | 148 76, 77, 77, 78, 78, 79, 79, 80, 80, 81, 81, 81, 82, 82, 8
3, 83, 84, 84, |
| 199 84, 85, 85, 86, 86, 87, 87, 87, 88, 88, 89, 89, 89, 90, 9
0, 91, 91, 91, | 149 84, 85, 85, 86, 86, 87, 87, 87, 88, 88, 89, 89, 89, 90, 9
0, 91, 91, 91, |
| 200 92, 92, 93, 93, 93, 94, 94, 94, 95, 95, 96, 96, 96, 97, 9
7, 97, 98, 98, | 150 92, 92, 93, 93, 93, 94, 94, 94, 95, 95, 96, 96, 96, 97, 9
7, 97, 98, 98, |
| 201 98, 99, 99, 99, 100, 100, 101, 101, 101, 102, 102, 102, 103, 103, 10
3, 104, 104, 104, | 151 98, 99, 99, 99, 100, 100, 101, 101, 101, 102, 102, 102, 103, 103, 10
3, 104, 104, 104, |
| 202 105, 105, 105, 106, 106, 106, 107, 107, 107, 108, 108, 108, 108, 109, 10
9, 109, 110, 110, | 152 105, 105, 105, 106, 106, 106, 107, 107, 107, 108, 108, 108, 108, 109, 10
9, 109, 110, 110, |
| 203 110, 111, 111, 111, 112, 112, 112, 112, 113, 113, 113, 114, 114, 114, 11
5, 115, 115, 115, | 153 110, 111, 111, 111, 112, 112, 112, 112, 113, 113, 113, 114, 114, 114, 11
5, 115, 115, 115, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 238, 238, 239, 239, 239, 239, 239, 239, 239, 239, 240, 240, 240, 240, 24
0, 240, 240, 240, | 193 238, 238, 239, 239, 239, 239, 239, 239, 239, 239, 240, 240, 240, 240, 24
0, 240, 240, 240, |
| 244 241, 241, 241, 241, 241, 241, 241, 241, 242, 242, 242, 242, 242, 242, 24
2, 242, 243, 243, | 194 241, 241, 241, 241, 241, 241, 241, 241, 242, 242, 242, 242, 242, 242, 24
2, 242, 243, 243, |
| 245 243, 243, 243, 243, 243, 243, 243, 244, 244, 244, 244, 244, 244, 244, 24
4, 245, 245, 245, | 195 243, 243, 243, 243, 243, 243, 243, 244, 244, 244, 244, 244, 244, 244, 24
4, 245, 245, 245, |
| 246 245, 245, 245, 245, 245, 245, 246, 246, 246, 246, 246, 246, 246, 246, 24
7, 247, 247, 247, | 196 245, 245, 245, 245, 245, 245, 246, 246, 246, 246, 246, 246, 246, 246, 24
7, 247, 247, 247, |
| 247 247, 247, 247, 247, 248, 248, 248, 248, 248, 248, 248, 248, 248, 249, 24
9, 249, 249, 249, | 197 247, 247, 247, 247, 248, 248, 248, 248, 248, 248, 248, 248, 248, 249, 24
9, 249, 249, 249, |
| 248 249, 249, 249, 249, 250, 250, 250, 250, 250, 250, 250, 250, 251, 251, 25
1, 251, 251, 251, | 198 249, 249, 249, 249, 250, 250, 250, 250, 250, 250, 250, 250, 251, 251, 25
1, 251, 251, 251, |
| 249 251, 251, 251, 252, 252, 252, 252, 252, 252, 252, 252, 252, 253, 253, 25
3, 253, 253, 253, | 199 251, 251, 251, 252, 252, 252, 252, 252, 252, 252, 252, 252, 253, 253, 25
3, 253, 253, 253, |
| 250 253, 253, 254, 254, 254, 254, 254, 254, 254, 254, 254, 255, 255, 255, 25
5, 255, | 200 253, 253, 254, 254, 254, 254, 254, 254, 254, 254, 254, 255, 255, 255, 25
5, 255, |
| 251 }; | 201 }; |
| 252 | 202 |
| 203 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 204 |
| 205 static void build_table_linear_from_gamma(float* outTable, float exponent) { |
| 206 for (float x = 0.0f; x <= 1.0f; x += (1.0f/255.0f)) { |
| 207 *outTable++ = powf(x, exponent); |
| 208 } |
| 209 } |
| 210 |
| 211 // Interpolating lookup in a variably sized table. |
| 212 static float interp_lut(float input, const float* table, int tableSize) { |
| 213 float index = input * (tableSize - 1); |
| 214 float diff = index - sk_float_floor2int(index); |
| 215 return table[(int) sk_float_floor2int(index)] * (1.0f - diff) + |
| 216 table[(int) sk_float_ceil2int(index)] * diff; |
| 217 } |
| 218 |
| 219 // outTable is always 256 entries, inTable may be larger or smaller. |
| 220 static void build_table_linear_from_gamma(float* outTable, const float* inTable, |
| 221 int inTableSize) { |
| 222 if (256 == inTableSize) { |
| 223 memcpy(outTable, inTable, sizeof(float) * 256); |
| 224 return; |
| 225 } |
| 226 |
| 227 for (float x = 0.0f; x <= 1.0f; x += (1.0f/255.0f)) { |
| 228 *outTable++ = interp_lut(x, inTable, inTableSize); |
| 229 } |
| 230 } |
| 231 |
| 232 static void build_table_linear_from_gamma(float* outTable, float g, float a, flo
at b, float c, |
| 233 float d, float e, float f) { |
| 234 // Y = (aX + b)^g + c for X >= d |
| 235 // Y = eX + f otherwise |
| 236 for (float x = 0.0f; x <= 1.0f; x += (1.0f/255.0f)) { |
| 237 if (x >= d) { |
| 238 *outTable++ = powf(a * x + b, g) + c; |
| 239 } else { |
| 240 *outTable++ = e * x + f; |
| 241 } |
| 242 } |
| 243 } |
| 244 |
| 245 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 246 |
| 253 // Expand range from 0-1 to 0-255, then convert. | 247 // Expand range from 0-1 to 0-255, then convert. |
| 254 static uint8_t clamp_normalized_float_to_byte(float v) { | 248 static uint8_t clamp_normalized_float_to_byte(float v) { |
| 255 // The ordering of the logic is a little strange here in order | 249 // The ordering of the logic is a little strange here in order |
| 256 // to make sure we convert NaNs to 0. | 250 // to make sure we convert NaNs to 0. |
| 257 v = v * 255.0f; | 251 v = v * 255.0f; |
| 258 if (v >= 254.5f) { | 252 if (v >= 254.5f) { |
| 259 return 255; | 253 return 255; |
| 260 } else if (v >= 0.5f) { | 254 } else if (v >= 0.5f) { |
| 261 return (uint8_t) (v + 0.5f); | 255 return (uint8_t) (v + 0.5f); |
| 262 } else { | 256 } else { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 static const GammaFns<float> kToLinear { | 360 static const GammaFns<float> kToLinear { |
| 367 sk_linear_from_srgb, | 361 sk_linear_from_srgb, |
| 368 sk_linear_from_2dot2, | 362 sk_linear_from_2dot2, |
| 369 &build_table_linear_from_gamma, | 363 &build_table_linear_from_gamma, |
| 370 &build_table_linear_from_gamma, | 364 &build_table_linear_from_gamma, |
| 371 &build_table_linear_from_gamma, | 365 &build_table_linear_from_gamma, |
| 372 }; | 366 }; |
| 373 | 367 |
| 374 static const GammaFns<uint8_t> kFromLinear { | 368 static const GammaFns<uint8_t> kFromLinear { |
| 375 linear_to_srgb, | 369 linear_to_srgb, |
| 376 linear_to_2dot2, | 370 linear_to_2dot2_table, |
| 377 &build_table_linear_to_gamma, | 371 &build_table_linear_to_gamma, |
| 378 &build_table_linear_to_gamma, | 372 &build_table_linear_to_gamma, |
| 379 &build_table_linear_to_gamma, | 373 &build_table_linear_to_gamma, |
| 380 }; | 374 }; |
| 381 | 375 |
| 382 // Build tables to transform src gamma to linear. | 376 // Build tables to transform src gamma to linear. |
| 383 template <typename T> | 377 template <typename T> |
| 384 static void build_gamma_tables(const T* outGammaTables[3], T* gammaTableStorage,
int gammaTableSize, | 378 static void build_gamma_tables(const T* outGammaTables[3], T* gammaTableStorage,
int gammaTableSize, |
| 385 const sk_sp<SkColorSpace>& space, const GammaFns<
T>& fns) { | 379 const sk_sp<SkColorSpace>& space, const GammaFns<
T>& fns) { |
| 386 switch (space->gammaNamed()) { | 380 switch (space->gammaNamed()) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 params.fF); | 436 params.fF); |
| 443 outGammaTables[i] = &gammaTableStorage[i * gammaTableSize]; | 437 outGammaTables[i] = &gammaTableStorage[i * gammaTableSize]; |
| 444 } | 438 } |
| 445 } | 439 } |
| 446 } | 440 } |
| 447 } | 441 } |
| 448 } | 442 } |
| 449 | 443 |
| 450 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 444 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 451 | 445 |
| 446 static inline bool compute_gamut_xform(SkMatrix44* srcToDst, const SkMatrix44& s
rcToXYZ, |
| 447 const SkMatrix44& dstToXYZ) { |
| 448 if (!dstToXYZ.invert(srcToDst)) { |
| 449 return false; |
| 450 } |
| 451 |
| 452 srcToDst->postConcat(srcToXYZ); |
| 453 return true; |
| 454 } |
| 455 |
| 456 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 457 |
| 452 std::unique_ptr<SkColorSpaceXform> SkColorSpaceXform::New(const sk_sp<SkColorSpa
ce>& srcSpace, | 458 std::unique_ptr<SkColorSpaceXform> SkColorSpaceXform::New(const sk_sp<SkColorSpa
ce>& srcSpace, |
| 453 const sk_sp<SkColorSpa
ce>& dstSpace) { | 459 const sk_sp<SkColorSpa
ce>& dstSpace) { |
| 454 if (!srcSpace || !dstSpace) { | 460 if (!srcSpace || !dstSpace) { |
| 455 // Invalid input | 461 // Invalid input |
| 456 return nullptr; | 462 return nullptr; |
| 457 } | 463 } |
| 458 | 464 |
| 459 if (as_CSB(dstSpace)->colorLUT()) { | 465 if (as_CSB(dstSpace)->colorLUT()) { |
| 460 // It would be really weird for a dst profile to have a color LUT. I do
n't think | 466 // It would be really weird for a dst profile to have a color LUT. I do
n't think |
| 461 // we need to support this. | 467 // we need to support this. |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 b = sk_float_round2int(255.0f * clamp_normalized_float(out[2])); | 614 b = sk_float_round2int(255.0f * clamp_normalized_float(out[2])); |
| 609 *dst = SkPackARGB_as_RGBA(0xFF, r, g, b); | 615 *dst = SkPackARGB_as_RGBA(0xFF, r, g, b); |
| 610 | 616 |
| 611 src++; | 617 src++; |
| 612 dst++; | 618 dst++; |
| 613 } | 619 } |
| 614 } | 620 } |
| 615 | 621 |
| 616 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 622 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 617 | 623 |
| 618 template <SkColorSpace::GammaNamed Dst> | 624 template <SkColorSpace::GammaNamed kDst> |
| 619 SkColorSpaceXform_Base<Dst>::SkColorSpaceXform_Base(const sk_sp<SkColorSpace>& s
rcSpace, | 625 SkColorSpaceXform_Base<kDst>::SkColorSpaceXform_Base(const sk_sp<SkColorSpace>&
srcSpace, |
| 620 const SkMatrix44& srcToDst, | 626 const SkMatrix44& srcToDst, |
| 621 const sk_sp<SkColorSpace>& d
stSpace) | 627 const sk_sp<SkColorSpace>& d
stSpace) |
| 622 : fColorLUT(sk_ref_sp((SkColorLookUpTable*) as_CSB(srcSpace)->colorLUT())) | 628 : fColorLUT(sk_ref_sp((SkColorLookUpTable*) as_CSB(srcSpace)->colorLUT())) |
| 623 { | 629 { |
| 624 srcToDst.asRowMajorf(fSrcToDst); | 630 srcToDst.asRowMajorf(fSrcToDst); |
| 625 build_gamma_tables(fSrcGammaTables, fSrcGammaTableStorage, 256, srcSpace, kT
oLinear); | 631 build_gamma_tables(fSrcGammaTables, fSrcGammaTableStorage, 256, srcSpace, kT
oLinear); |
| 626 build_gamma_tables(fDstGammaTables, fDstGammaTableStorage, kDstGammaTableSiz
e, | 632 build_gamma_tables(fDstGammaTables, fDstGammaTableStorage, kDstGammaTableSiz
e, |
| 627 dstSpace, kFromLinear); | 633 dstSpace, kFromLinear); |
| 628 } | 634 } |
| 629 | 635 |
| 630 template <> | 636 template <> |
| 631 void SkColorSpaceXform_Base<SkColorSpace::kSRGB_GammaNamed> | 637 void SkColorSpaceXform_Base<SkColorSpace::kSRGB_GammaNamed> |
| 632 ::applyToRGBA(RGBA32* dst, const RGBA32* src, int len) const | 638 ::applyToRGBA(RGBA32* dst, const RGBA32* src, int len) const |
| 633 { | 639 { |
| 634 if (fColorLUT) { | 640 if (fColorLUT) { |
| 635 handle_color_lut(dst, src, len, fColorLUT.get()); | 641 handle_color_lut(dst, src, len, fColorLUT.get()); |
| 636 src = dst; | 642 src = dst; |
| 637 } | 643 } |
| 638 | 644 |
| 639 SkOpts::color_xform_RGB1_to_srgb(dst, src, len, fSrcGammaTables, fSrcToDst); | 645 color_xform_RGBA<SkColorSpace::kSRGB_GammaNamed, false, false> |
| 646 (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables); |
| 640 } | 647 } |
| 641 | 648 |
| 642 template <> | 649 template <> |
| 643 void SkColorSpaceXform_Base<SkColorSpace::k2Dot2Curve_GammaNamed> | 650 void SkColorSpaceXform_Base<SkColorSpace::k2Dot2Curve_GammaNamed> |
| 644 ::applyToRGBA(RGBA32* dst, const RGBA32* src, int len) const | 651 ::applyToRGBA(RGBA32* dst, const RGBA32* src, int len) const |
| 645 { | 652 { |
| 646 if (fColorLUT) { | 653 if (fColorLUT) { |
| 647 handle_color_lut(dst, src, len, fColorLUT.get()); | 654 handle_color_lut(dst, src, len, fColorLUT.get()); |
| 648 src = dst; | 655 src = dst; |
| 649 } | 656 } |
| 650 | 657 |
| 651 SkOpts::color_xform_RGB1_to_2dot2(dst, src, len, fSrcGammaTables, fSrcToDst)
; | 658 color_xform_RGBA<SkColorSpace::k2Dot2Curve_GammaNamed, false, false> |
| 659 (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables); |
| 652 } | 660 } |
| 653 | 661 |
| 654 template <> | 662 template <> |
| 655 void SkColorSpaceXform_Base<SkColorSpace::kNonStandard_GammaNamed> | 663 void SkColorSpaceXform_Base<SkColorSpace::kNonStandard_GammaNamed> |
| 656 ::applyToRGBA(RGBA32* dst, const RGBA32* src, int len) const | 664 ::applyToRGBA(RGBA32* dst, const RGBA32* src, int len) const |
| 657 { | 665 { |
| 658 if (fColorLUT) { | 666 if (fColorLUT) { |
| 659 handle_color_lut(dst, src, len, fColorLUT.get()); | 667 handle_color_lut(dst, src, len, fColorLUT.get()); |
| 660 src = dst; | 668 src = dst; |
| 661 } | 669 } |
| 662 | 670 |
| 663 SkOpts::color_xform_RGB1_to_table(dst, src, len, fSrcGammaTables, fSrcToDst,
fDstGammaTables); | 671 color_xform_RGBA<SkColorSpace::kNonStandard_GammaNamed, false, false> |
| 672 (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables); |
| 664 } | 673 } |
| 665 | 674 |
| 666 template <> | 675 template <> |
| 667 void SkColorSpaceXform_Base<SkColorSpace::kSRGB_GammaNamed> | 676 void SkColorSpaceXform_Base<SkColorSpace::kSRGB_GammaNamed> |
| 668 ::applyToBGRA(BGRA32* dst, const RGBA32* src, int len) const | 677 ::applyToBGRA(BGRA32* dst, const RGBA32* src, int len) const |
| 669 { | 678 { |
| 670 if (fColorLUT) { | 679 if (fColorLUT) { |
| 671 handle_color_lut(dst, src, len, fColorLUT.get()); | 680 handle_color_lut(dst, src, len, fColorLUT.get()); |
| 672 src = dst; | 681 src = dst; |
| 673 } | 682 } |
| 674 | 683 |
| 675 SkOpts::color_xform_RGB1_to_srgb_swaprb(dst, src, len, fSrcGammaTables, fSrc
ToDst); | 684 color_xform_RGBA<SkColorSpace::kSRGB_GammaNamed, false, true> |
| 685 (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables); |
| 676 } | 686 } |
| 677 | 687 |
| 678 template <> | 688 template <> |
| 679 void SkColorSpaceXform_Base<SkColorSpace::k2Dot2Curve_GammaNamed> | 689 void SkColorSpaceXform_Base<SkColorSpace::k2Dot2Curve_GammaNamed> |
| 680 ::applyToBGRA(BGRA32* dst, const RGBA32* src, int len) const | 690 ::applyToBGRA(BGRA32* dst, const RGBA32* src, int len) const |
| 681 { | 691 { |
| 682 if (fColorLUT) { | 692 if (fColorLUT) { |
| 683 handle_color_lut(dst, src, len, fColorLUT.get()); | 693 handle_color_lut(dst, src, len, fColorLUT.get()); |
| 684 src = dst; | 694 src = dst; |
| 685 } | 695 } |
| 686 | 696 |
| 687 SkOpts::color_xform_RGB1_to_2dot2_swaprb(dst, src, len, fSrcGammaTables, fSr
cToDst); | 697 color_xform_RGBA<SkColorSpace::k2Dot2Curve_GammaNamed, false, true> |
| 698 (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables); |
| 688 } | 699 } |
| 689 | 700 |
| 690 template <> | 701 template <> |
| 691 void SkColorSpaceXform_Base<SkColorSpace::kNonStandard_GammaNamed> | 702 void SkColorSpaceXform_Base<SkColorSpace::kNonStandard_GammaNamed> |
| 692 ::applyToBGRA(BGRA32* dst, const RGBA32* src, int len) const | 703 ::applyToBGRA(BGRA32* dst, const RGBA32* src, int len) const |
| 693 { | 704 { |
| 694 if (fColorLUT) { | 705 if (fColorLUT) { |
| 695 handle_color_lut(dst, src, len, fColorLUT.get()); | 706 handle_color_lut(dst, src, len, fColorLUT.get()); |
| 696 src = dst; | 707 src = dst; |
| 697 } | 708 } |
| 698 | 709 |
| 699 SkOpts::color_xform_RGB1_to_table_swaprb(dst, src, len, fSrcGammaTables, fSr
cToDst, | 710 color_xform_RGBA<SkColorSpace::kNonStandard_GammaNamed, false, true> |
| 700 fDstGammaTables); | 711 (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables); |
| 701 } | 712 } |
| 702 | 713 |
| 703 template <SkColorSpace::GammaNamed T> | 714 template <SkColorSpace::GammaNamed T> |
| 704 void SkColorSpaceXform_Base<T> | 715 void SkColorSpaceXform_Base<T> |
| 705 ::applyToF16(RGBAF16* dst, const RGBA32* src, int len) const | 716 ::applyToF16(RGBAF16* dst, const RGBA32* src, int len) const |
| 706 { | 717 { |
| 707 if (fColorLUT) { | 718 if (fColorLUT) { |
| 708 size_t storageBytes = len * sizeof(RGBA32); | 719 size_t storageBytes = len * sizeof(RGBA32); |
| 709 #if defined(GOOGLE3) | 720 #if defined(GOOGLE3) |
| 710 // Stack frame size is limited in GOOGLE3. | 721 // Stack frame size is limited in GOOGLE3. |
| 711 SkAutoSMalloc<256 * sizeof(RGBA32)> storage(storageBytes); | 722 SkAutoSMalloc<256 * sizeof(RGBA32)> storage(storageBytes); |
| 712 #else | 723 #else |
| 713 SkAutoSMalloc<1024 * sizeof(RGBA32)> storage(storageBytes); | 724 SkAutoSMalloc<1024 * sizeof(RGBA32)> storage(storageBytes); |
| 714 #endif | 725 #endif |
| 715 | 726 |
| 716 handle_color_lut((RGBA32*) storage.get(), src, len, fColorLUT.get()); | 727 handle_color_lut((RGBA32*) storage.get(), src, len, fColorLUT.get()); |
| 717 src = (const RGBA32*) storage.get(); | 728 src = (const RGBA32*) storage.get(); |
| 718 } | 729 } |
| 719 | 730 |
| 720 SkOpts::color_xform_RGB1_to_linear(dst, src, len, fSrcGammaTables, fSrcToDst
); | 731 color_xform_RGBA<SkColorSpace::kLinear_GammaNamed, false, false> |
| 732 (dst, src, len, fSrcGammaTables, fSrcToDst, fDstGammaTables); |
| 721 } | 733 } |
| OLD | NEW |