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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 Sk4f s4 = Sk4f::Load(src[i].fVec); | 257 Sk4f s4 = Sk4f::Load(src[i].fVec); |
262 Sk4f d4 = load_dst<D>(dst[i]); | 258 Sk4f d4 = load_dst<D>(dst[i]); |
263 Sk4f r4 = s4 + d4 * Sk4f(1 - get_alpha(s4)); | 259 Sk4f r4 = s4 + d4 * Sk4f(1 - get_alpha(s4)); |
264 dst[i] = store_dst<D>(r4); | 260 dst[i] = store_dst<D>(r4); |
265 } | 261 } |
266 } | 262 } |
267 } | 263 } |
268 | 264 |
269 static void srcover_linear_dst_1(const SkXfermode::PM4fState& state, uint32_t ds
t[], | 265 static void srcover_linear_dst_1(const SkXfermode::PM4fState& state, uint32_t ds
t[], |
270 const SkPM4f& src, int count, const SkAlpha aa[
]) { | 266 const SkPM4f& src, int count, const SkAlpha aa[
]) { |
271 Sk4f s4 = Sk4f::Load(src.fVec); | 267 const Sk4f s4 = Sk4f::Load(src.fVec); |
272 Sk4f dst_scale = Sk4f(1 - get_alpha(s4)); | 268 const Sk4f dst_scale = Sk4f(1 - get_alpha(s4)); |
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); |
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 const Sk4f s4_255 = s4 * Sk4f(255) + Sk4f(0.5f); // +0.5 to pre-bias f
or 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]); |
295 Sk4f d2 = to_4f(dst[2]); | 291 Sk4f d2 = to_4f(dst[2]); |
296 Sk4f d3 = to_4f(dst[3]); | 292 Sk4f d3 = to_4f(dst[3]); |
297 Sk4f_ToBytes((uint8_t*)dst, | 293 Sk4f_ToBytes((uint8_t*)dst, |
298 s4 + d0 * dst_scale, | 294 s4_255 + d0 * dst_scale, |
299 s4 + d1 * dst_scale, | 295 s4_255 + d1 * dst_scale, |
300 s4 + d2 * dst_scale, | 296 s4_255 + d2 * dst_scale, |
301 s4 + d3 * dst_scale); | 297 s4_255 + d3 * dst_scale); |
302 dst += 4; | 298 dst += 4; |
303 count -= 4; | 299 count -= 4; |
304 } | 300 } |
305 for (int i = 0; i < count; ++i) { | 301 for (int i = 0; i < count; ++i) { |
306 Sk4f d4 = to_4f(dst[i]); | 302 Sk4f d4 = to_4f(dst[i]); |
307 dst[i] = to_4b(s4 + d4 * dst_scale); | 303 dst[i] = to_4b(s4_255 + d4 * dst_scale); |
308 } | 304 } |
309 } | 305 } |
310 } | 306 } |
311 | 307 |
312 static void srcover_srgb_dst_1(const SkXfermode::PM4fState& state, uint32_t dst[
], | 308 static void srcover_srgb_dst_1(const SkXfermode::PM4fState& state, uint32_t dst[
], |
313 const SkPM4f& src, int count, const SkAlpha aa[])
{ | 309 const SkPM4f& src, int count, const SkAlpha aa[])
{ |
314 Sk4f s4 = Sk4f::Load(src.fVec); | 310 Sk4f s4 = Sk4f::Load(src.fVec); |
315 Sk4f dst_scale = Sk4f(1 - get_alpha(s4)); | 311 Sk4f dst_scale = Sk4f(1 - get_alpha(s4)); |
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 const 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 |