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 17 matching lines...) Expand all Loading... | |
28 } | 28 } |
29 | 29 |
30 template <DstType D> Sk4f load_dst(SkPMColor dstC) { | 30 template <DstType D> Sk4f load_dst(SkPMColor dstC) { |
31 return (D == kSRGB_Dst) ? Sk4f_fromS32(dstC) : Sk4f_fromL32(dstC); | 31 return (D == kSRGB_Dst) ? Sk4f_fromS32(dstC) : Sk4f_fromL32(dstC); |
32 } | 32 } |
33 | 33 |
34 template <DstType D> uint32_t store_dst(const Sk4f& x4) { | 34 template <DstType D> uint32_t store_dst(const Sk4f& x4) { |
35 return (D == kSRGB_Dst) ? Sk4f_toS32(x4) : Sk4f_toL32(x4); | 35 return (D == kSRGB_Dst) ? Sk4f_toS32(x4) : Sk4f_toL32(x4); |
36 } | 36 } |
37 | 37 |
38 template <DstType D> Sk4f linear_to_dst_255(const Sk4f& l4) { | |
mtklein
2016/02/01 21:55:32
Seems odd to template this on DstType if we're onl
reed1
2016/02/02 14:04:39
I had a bool, but it made reading profiles harder.
mtklein
2016/02/02 14:26:06
No no, I mean, it's weird to template at all. Onl
reed1
2016/02/02 14:45:58
Ah. It *was* being used more generically, until I
| |
39 Sk4f x4; | |
40 if (D == kSRGB_Dst) { | |
41 x4 = linear_to_srgb(l4); | |
42 } else { | |
43 x4 = l4; | |
44 } | |
45 return x4 * Sk4f(255) + Sk4f(0.5f); | |
46 } | |
47 | |
38 //////////////////////////////////////////////////////////////////////////////// /////////////////// | 48 //////////////////////////////////////////////////////////////////////////////// /////////////////// |
39 | 49 |
40 static Sk4f scale_255_round(const SkPM4f& pm4) { | 50 static Sk4f scale_255_round(const SkPM4f& pm4) { |
41 return Sk4f::Load(pm4.fVec) * Sk4f(255) + Sk4f(0.5f); | 51 return Sk4f::Load(pm4.fVec) * Sk4f(255) + Sk4f(0.5f); |
42 } | 52 } |
43 | 53 |
44 static void pm4f_to_linear_32(SkPMColor dst[], const SkPM4f src[], int count) { | 54 static void pm4f_to_linear_32(SkPMColor dst[], const SkPM4f src[], int count) { |
45 while (count >= 4) { | 55 while (count >= 4) { |
46 src[0].assertIsUnit(); | 56 src[0].assertIsUnit(); |
47 src[1].assertIsUnit(); | 57 src[1].assertIsUnit(); |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 Sk4f r4; | 279 Sk4f r4; |
270 if (a != 0xFF) { | 280 if (a != 0xFF) { |
271 s4 = scale_by_coverage(s4, a); | 281 s4 = scale_by_coverage(s4, a); |
272 r4 = s4 + d4 * Sk4f(1 - get_alpha(s4)); | 282 r4 = s4 + d4 * Sk4f(1 - get_alpha(s4)); |
273 } else { | 283 } else { |
274 r4 = s4 + d4 * scale; | 284 r4 = s4 + d4 * scale; |
275 } | 285 } |
276 dst[i] = store_dst<D>(r4); | 286 dst[i] = store_dst<D>(r4); |
277 } | 287 } |
278 } else { | 288 } else { |
289 if (D == kLinear_Dst) { | |
290 s4 = s4 * Sk4f(255) + Sk4f(0.5f); | |
mtklein
2016/02/01 21:55:32
I find it really confusing to mutate values condit
reed1
2016/02/02 14:04:39
Agreed. I will give them meaningful names
| |
291 scale = scale * Sk4f(255); | |
292 } | |
mtklein
2016/02/01 21:58:44
I'm also curious to see if this hoisting can be do
| |
293 while (count >= 4) { | |
294 Sk4f d0 = load_dst<D>(dst[0]); | |
295 Sk4f d1 = load_dst<D>(dst[1]); | |
296 Sk4f d2 = load_dst<D>(dst[2]); | |
297 Sk4f d3 = load_dst<D>(dst[3]); | |
298 if (D == kLinear_Dst) { | |
299 Sk4f_ToBytes((uint8_t*)dst, | |
300 s4 + d0 * scale, s4 + d1 * scale, s4 + d2 * scale, s4 + d3 * scale); | |
mtklein
2016/02/01 21:55:32
Might be nice to line-break after each comma here
reed1
2016/02/02 14:04:39
Agreed.
| |
301 } else { | |
302 Sk4f_ToBytes((uint8_t*)dst, | |
303 linear_to_dst_255<D>(s4 + d0 * scale), | |
304 linear_to_dst_255<D>(s4 + d1 * scale), | |
305 linear_to_dst_255<D>(s4 + d2 * scale), | |
306 linear_to_dst_255<D>(s4 + d3 * scale)); | |
307 } | |
308 dst += 4; | |
309 count -= 4; | |
310 } | |
279 for (int i = 0; i < count; ++i) { | 311 for (int i = 0; i < count; ++i) { |
280 Sk4f d4 = load_dst<D>(dst[i]); | 312 Sk4f r4 = s4 + load_dst<D>(dst[i]) * scale; |
281 Sk4f r4 = s4 + d4 * scale; | 313 if (D == kLinear_Dst) { |
282 dst[i] = store_dst<D>(r4); | 314 dst[i] = to_4b(r4); |
315 } else { | |
316 dst[i] = store_dst<D>(r4); | |
317 } | |
283 } | 318 } |
284 } | 319 } |
285 } | 320 } |
286 | 321 |
287 const XferProcPair gProcs_SrcOver[] = { | 322 const XferProcPair gProcs_SrcOver[] = { |
288 { srcover_1<kLinear_Dst>, srcover_n<kLinear_Dst> }, // linear alpha | 323 { srcover_1<kLinear_Dst>, srcover_n<kLinear_Dst> }, // linear alpha |
289 { src_1<kLinear_Dst>, src_n<kLinear_Dst> }, // linear opaque [ we are src-mode ] | 324 { src_1<kLinear_Dst>, src_n<kLinear_Dst> }, // linear opaque [ we are src-mode ] |
290 { srcover_1<kSRGB_Dst>, srcover_n<kSRGB_Dst> }, // srgb alpha | 325 { srcover_1<kSRGB_Dst>, srcover_n<kSRGB_Dst> }, // srgb alpha |
291 { src_1<kSRGB_Dst>, src_n<kSRGB_Dst> }, // srgb opaque [ we are src-mode ] | 326 { src_1<kSRGB_Dst>, src_n<kSRGB_Dst> }, // srgb opaque [ we are src-mode ] |
292 }; | 327 }; |
(...skipping 25 matching lines...) Expand all Loading... | |
318 | 353 |
319 SkXfermode::PM4fProc1 SkXfermode::getPM4fProc1(uint32_t flags) const { | 354 SkXfermode::PM4fProc1 SkXfermode::getPM4fProc1(uint32_t flags) const { |
320 Mode mode; | 355 Mode mode; |
321 return this->asMode(&mode) ? GetPM4fProc1(mode, flags) : xfer_pm4_proc_1; | 356 return this->asMode(&mode) ? GetPM4fProc1(mode, flags) : xfer_pm4_proc_1; |
322 } | 357 } |
323 | 358 |
324 SkXfermode::PM4fProcN SkXfermode::getPM4fProcN(uint32_t flags) const { | 359 SkXfermode::PM4fProcN SkXfermode::getPM4fProcN(uint32_t flags) const { |
325 Mode mode; | 360 Mode mode; |
326 return this->asMode(&mode) ? GetPM4fProcN(mode, flags) : xfer_pm4_proc_n; | 361 return this->asMode(&mode) ? GetPM4fProcN(mode, flags) : xfer_pm4_proc_n; |
327 } | 362 } |
OLD | NEW |