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 "SkPM4fPriv.h" | 8 #include "SkPM4fPriv.h" |
9 #include "SkUtils.h" | 9 #include "SkUtils.h" |
10 #include "SkXfermode.h" | 10 #include "SkXfermode.h" |
(...skipping 21 matching lines...) Expand all Loading... | |
32 } | 32 } |
33 | 33 |
34 static Sk4f srgb_4b_to_linear_unit(SkPMColor dstC) { | 34 static Sk4f srgb_4b_to_linear_unit(SkPMColor dstC) { |
35 return Sk4f_fromS32(dstC); | 35 return Sk4f_fromS32(dstC); |
36 } | 36 } |
37 | 37 |
38 template <DstType D> uint32_t store_dst(const Sk4f& x4) { | 38 template <DstType D> uint32_t store_dst(const Sk4f& x4) { |
39 return (D == kSRGB_Dst) ? Sk4f_toS32(x4) : Sk4f_toL32(x4); | 39 return (D == kSRGB_Dst) ? Sk4f_toS32(x4) : Sk4f_toL32(x4); |
40 } | 40 } |
41 | 41 |
42 static uint32_t linear_unit_to_srgb_32(const Sk4f& l4) { | |
43 return Sk4f_toL32(l4); | |
44 } | |
45 | |
46 static Sk4f linear_unit_to_srgb_255f(const Sk4f& l4) { | 42 static Sk4f linear_unit_to_srgb_255f(const Sk4f& l4) { |
47 return linear_to_srgb(l4) * Sk4f(255) + Sk4f(0.5f); | 43 return linear_to_srgb(l4) * Sk4f(255) + Sk4f(0.5f); |
48 } | 44 } |
49 | 45 |
50 //////////////////////////////////////////////////////////////////////////////// /////////////////// | 46 //////////////////////////////////////////////////////////////////////////////// /////////////////// |
51 | 47 |
52 static Sk4f scale_255_round(const SkPM4f& pm4) { | 48 static Sk4f scale_255_round(const SkPM4f& pm4) { |
53 return Sk4f::Load(pm4.fVec) * Sk4f(255) + Sk4f(0.5f); | 49 return Sk4f::Load(pm4.fVec) * Sk4f(255) + Sk4f(0.5f); |
54 } | 50 } |
55 | 51 |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
273 | 269 |
274 if (aa) { | 270 if (aa) { |
275 for (int i = 0; i < count; ++i) { | 271 for (int i = 0; i < count; ++i) { |
276 unsigned a = aa[i]; | 272 unsigned a = aa[i]; |
277 if (0 == a) { | 273 if (0 == a) { |
278 continue; | 274 continue; |
279 } | 275 } |
280 Sk4f d4 = Sk4f_fromL32(dst[i]); | 276 Sk4f d4 = Sk4f_fromL32(dst[i]); |
281 Sk4f r4; | 277 Sk4f r4; |
282 if (a != 0xFF) { | 278 if (a != 0xFF) { |
283 s4 = scale_by_coverage(s4, a); | 279 Sk4f s4_aa = scale_by_coverage(s4, a); |
mtklein
2016/02/03 01:32:55
Ah! Let's make s4 and dst_scale const?
I guarant
reed1
2016/02/03 03:19:49
ok
| |
284 r4 = s4 + d4 * Sk4f(1 - get_alpha(s4)); | 280 r4 = s4_aa + d4 * Sk4f(1 - get_alpha(s4_aa)); |
285 } else { | 281 } else { |
286 r4 = s4 + d4 * dst_scale; | 282 r4 = s4 + d4 * dst_scale; |
287 } | 283 } |
288 dst[i] = Sk4f_toL32(r4); | 284 dst[i] = Sk4f_toL32(r4); |
289 } | 285 } |
290 } else { | 286 } else { |
291 s4 = s4 * Sk4f(255) + Sk4f(0.5f); // +0.5 to pre-bias for rounding | 287 s4 = s4 * Sk4f(255) + Sk4f(0.5f); // +0.5 to pre-bias for rounding |
292 while (count >= 4) { | 288 while (count >= 4) { |
293 Sk4f d0 = to_4f(dst[0]); | 289 Sk4f d0 = to_4f(dst[0]); |
294 Sk4f d1 = to_4f(dst[1]); | 290 Sk4f d1 = to_4f(dst[1]); |
(...skipping 21 matching lines...) Expand all Loading... | |
316 | 312 |
317 if (aa) { | 313 if (aa) { |
318 for (int i = 0; i < count; ++i) { | 314 for (int i = 0; i < count; ++i) { |
319 unsigned a = aa[i]; | 315 unsigned a = aa[i]; |
320 if (0 == a) { | 316 if (0 == a) { |
321 continue; | 317 continue; |
322 } | 318 } |
323 Sk4f d4 = srgb_4b_to_linear_unit(dst[i]); | 319 Sk4f d4 = srgb_4b_to_linear_unit(dst[i]); |
324 Sk4f r4; | 320 Sk4f r4; |
325 if (a != 0xFF) { | 321 if (a != 0xFF) { |
326 s4 = scale_by_coverage(s4, a); | 322 Sk4f s4_aa = scale_by_coverage(s4, a); |
327 r4 = s4 + d4 * Sk4f(1 - get_alpha(s4)); | 323 r4 = s4_aa + d4 * Sk4f(1 - get_alpha(s4_aa)); |
328 } else { | 324 } else { |
329 r4 = s4 + d4 * dst_scale; | 325 r4 = s4 + d4 * dst_scale; |
330 } | 326 } |
331 dst[i] = linear_unit_to_srgb_32(r4); | 327 dst[i] = to_4b(linear_unit_to_srgb_255f(r4)); |
332 } | 328 } |
333 } else { | 329 } else { |
334 while (count >= 4) { | 330 while (count >= 4) { |
335 Sk4f d0 = srgb_4b_to_linear_unit(dst[0]); | 331 Sk4f d0 = srgb_4b_to_linear_unit(dst[0]); |
336 Sk4f d1 = srgb_4b_to_linear_unit(dst[1]); | 332 Sk4f d1 = srgb_4b_to_linear_unit(dst[1]); |
337 Sk4f d2 = srgb_4b_to_linear_unit(dst[2]); | 333 Sk4f d2 = srgb_4b_to_linear_unit(dst[2]); |
338 Sk4f d3 = srgb_4b_to_linear_unit(dst[3]); | 334 Sk4f d3 = srgb_4b_to_linear_unit(dst[3]); |
339 Sk4f_ToBytes((uint8_t*)dst, | 335 Sk4f_ToBytes((uint8_t*)dst, |
340 linear_unit_to_srgb_255f(s4 + d0 * dst_scale), | 336 linear_unit_to_srgb_255f(s4 + d0 * dst_scale), |
341 linear_unit_to_srgb_255f(s4 + d1 * dst_scale), | 337 linear_unit_to_srgb_255f(s4 + d1 * dst_scale), |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
385 | 381 |
386 SkXfermode::PM4fProc1 SkXfermode::getPM4fProc1(uint32_t flags) const { | 382 SkXfermode::PM4fProc1 SkXfermode::getPM4fProc1(uint32_t flags) const { |
387 Mode mode; | 383 Mode mode; |
388 return this->asMode(&mode) ? GetPM4fProc1(mode, flags) : xfer_pm4_proc_1; | 384 return this->asMode(&mode) ? GetPM4fProc1(mode, flags) : xfer_pm4_proc_1; |
389 } | 385 } |
390 | 386 |
391 SkXfermode::PM4fProcN SkXfermode::getPM4fProcN(uint32_t flags) const { | 387 SkXfermode::PM4fProcN SkXfermode::getPM4fProcN(uint32_t flags) const { |
392 Mode mode; | 388 Mode mode; |
393 return this->asMode(&mode) ? GetPM4fProcN(mode, flags) : xfer_pm4_proc_n; | 389 return this->asMode(&mode) ? GetPM4fProcN(mode, flags) : xfer_pm4_proc_n; |
394 } | 390 } |
OLD | NEW |