Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: src/opts/SkRasterPipeline_opts.h

Issue 2449243003: Initial implementation of a SkColorSpace_A2B xform (Closed)
Patch Set: responding to comments Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkRasterPipeline.h ('k') | tests/ColorSpaceXformTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef SkRasterPipeline_opts_DEFINED 8 #ifndef SkRasterPipeline_opts_DEFINED
9 #define SkRasterPipeline_opts_DEFINED 9 #define SkRasterPipeline_opts_DEFINED
10 10
11 #include "SkColorPriv.h" 11 #include "SkColorPriv.h"
12 #include "SkColorSpace_Base.h"
12 #include "SkHalf.h" 13 #include "SkHalf.h"
14 #include "SkMatrix44.h"
mtklein_C 2016/11/11 21:20:57 This is probably no longer needed.
raftias 2016/11/11 21:42:37 Removed. SkColorSpace_Base isn't needed either aft
13 #include "SkPM4f.h" 15 #include "SkPM4f.h"
14 #include "SkPM4fPriv.h" 16 #include "SkPM4fPriv.h"
15 #include "SkRasterPipeline.h" 17 #include "SkRasterPipeline.h"
16 #include "SkSRGB.h" 18 #include "SkSRGB.h"
17 #include "SkUtils.h" 19 #include "SkUtils.h"
18 #include <utility> 20 #include <utility>
19 21
20 namespace { 22 namespace {
21 23
22 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_AVX2 24 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_AVX2
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 } 426 }
425 427
426 STAGE(store_srgb, false) { 428 STAGE(store_srgb, false) {
427 auto ptr = *(uint32_t**)ctx + x; 429 auto ptr = *(uint32_t**)ctx + x;
428 store<kIsTail>(tail, ( sk_linear_to_srgb(r) << SK_R32_SHIFT 430 store<kIsTail>(tail, ( sk_linear_to_srgb(r) << SK_R32_SHIFT
429 | sk_linear_to_srgb(g) << SK_G32_SHIFT 431 | sk_linear_to_srgb(g) << SK_G32_SHIFT
430 | sk_linear_to_srgb(b) << SK_B32_SHIFT 432 | sk_linear_to_srgb(b) << SK_B32_SHIFT
431 | SkNx_cast<int>(0.5f + 255.0f * a) << SK_A32_SHIFT), ( int*)ptr); 433 | SkNx_cast<int>(0.5f + 255.0f * a) << SK_A32_SHIFT), ( int*)ptr);
432 } 434 }
433 435
436 STAGE(load_s_8888, true) {
437 auto ptr = *(const uint32_t**)ctx + x;
438
439 auto px = load<kIsTail>(tail, ptr);
440 auto to_int = [](const SkNx<N, uint32_t>& v) { return SkNi::Load(&v); };
441 r = (1/255.0f)*SkNx_cast<float>(to_int((px >> 0) & 0xff));
442 g = (1/255.0f)*SkNx_cast<float>(to_int((px >> 8) & 0xff));
443 b = (1/255.0f)*SkNx_cast<float>(to_int((px >> 16) & 0xff));
444 a = (1/255.0f)*SkNx_cast<float>(to_int(px >> 24));
445 }
446
447 STAGE(store_8888, false) {
448 auto ptr = *(uint32_t**)ctx + x;
449 store<kIsTail>(tail, ( SkNx_cast<int>(255.0f * r + 0.5f) << 0
450 | SkNx_cast<int>(255.0f * g + 0.5f) << 8
451 | SkNx_cast<int>(255.0f * b + 0.5f) << 16
452 | SkNx_cast<int>(255.0f * a + 0.5f) << 24 ), (int*)ptr) ;
453 }
454
434 RGBA_XFERMODE(clear) { return 0.0f; } 455 RGBA_XFERMODE(clear) { return 0.0f; }
435 //RGBA_XFERMODE(src) { return s; } // This would be a no-op stage, so we just omit it. 456 //RGBA_XFERMODE(src) { return s; } // This would be a no-op stage, so we just omit it.
436 RGBA_XFERMODE(dst) { return d; } 457 RGBA_XFERMODE(dst) { return d; }
437 458
438 RGBA_XFERMODE(srcatop) { return s*da + d*inv(sa); } 459 RGBA_XFERMODE(srcatop) { return s*da + d*inv(sa); }
439 RGBA_XFERMODE(srcin) { return s * da; } 460 RGBA_XFERMODE(srcin) { return s * da; }
440 RGBA_XFERMODE(srcout) { return s * inv(da); } 461 RGBA_XFERMODE(srcout) { return s * inv(da); }
441 RGBA_XFERMODE(srcover) { return SkNx_fma(d, inv(sa), s); } 462 RGBA_XFERMODE(srcover) { return SkNx_fma(d, inv(sa), s); }
442 RGBA_XFERMODE(dstatop) { return srcatop_kernel(d,da,s,sa); } 463 RGBA_XFERMODE(dstatop) { return srcatop_kernel(d,da,s,sa); }
443 RGBA_XFERMODE(dstin) { return srcin_kernel (d,da,s,sa); } 464 RGBA_XFERMODE(dstin) { return srcin_kernel (d,da,s,sa); }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 liteDst = m.rsqrt().invert() - m, // Used in case 3. 504 liteDst = m.rsqrt().invert() - m, // Used in case 3.
484 liteSrc = d*sa + da*(s2 - sa) * (4.0f*d <= da).thenElse(darkDst, liteDs t); // 2 or 3? 505 liteSrc = d*sa + da*(s2 - sa) * (4.0f*d <= da).thenElse(darkDst, liteDs t); // 2 or 3?
485 return s*inv(da) + d*inv(sa) + (s2 <= sa).thenElse(darkSrc, liteSrc); // 1 or (2 or 3)? 506 return s*inv(da) + d*inv(sa) + (s2 <= sa).thenElse(darkSrc, liteSrc); // 1 or (2 or 3)?
486 } 507 }
487 508
488 STAGE(luminance_to_alpha, true) { 509 STAGE(luminance_to_alpha, true) {
489 a = SK_LUM_COEFF_R*r + SK_LUM_COEFF_G*g + SK_LUM_COEFF_B*b; 510 a = SK_LUM_COEFF_R*r + SK_LUM_COEFF_G*g + SK_LUM_COEFF_B*b;
490 r = g = b = 0; 511 r = g = b = 0;
491 } 512 }
492 513
514 STAGE(matrix_3x4, true) {
515 auto m = (const float*)ctx;
516
517 auto fma = [](const SkNf& f, const SkNf& m, const SkNf& a) { return SkNx_fma (f,m,a); };
518 auto R = fma(r,m[0], fma(g,m[3], fma(b,m[6], m[ 9]))),
519 G = fma(r,m[1], fma(g,m[4], fma(b,m[7], m[10]))),
520 B = fma(r,m[2], fma(g,m[5], fma(b,m[8], m[11])));
521 r = R;
522 g = G;
523 b = B;
524 }
525
493 STAGE(matrix_4x5, true) { 526 STAGE(matrix_4x5, true) {
494 auto m = (const float*)ctx; 527 auto m = (const float*)ctx;
495 528
496 auto fma = [](const SkNf& f, const SkNf& m, const SkNf& a) { return SkNx_fma (f,m,a); }; 529 auto fma = [](const SkNf& f, const SkNf& m, const SkNf& a) { return SkNx_fma (f,m,a); };
497 auto R = fma(r,m[0], fma(g,m[4], fma(b,m[ 8], fma(a,m[12], m[16])))), 530 auto R = fma(r,m[0], fma(g,m[4], fma(b,m[ 8], fma(a,m[12], m[16])))),
498 G = fma(r,m[1], fma(g,m[5], fma(b,m[ 9], fma(a,m[13], m[17])))), 531 G = fma(r,m[1], fma(g,m[5], fma(b,m[ 9], fma(a,m[13], m[17])))),
499 B = fma(r,m[2], fma(g,m[6], fma(b,m[10], fma(a,m[14], m[18])))), 532 B = fma(r,m[2], fma(g,m[6], fma(b,m[10], fma(a,m[14], m[18])))),
500 A = fma(r,m[3], fma(g,m[7], fma(b,m[11], fma(a,m[15], m[19])))); 533 A = fma(r,m[3], fma(g,m[7], fma(b,m[11], fma(a,m[15], m[19]))));
501 r = R; 534 r = R;
502 g = G; 535 g = G;
503 b = B; 536 b = B;
504 a = A; 537 a = A;
505 } 538 }
506 539
540 STAGE(fn_1_r, true) {
541 auto fn = (const std::function<float(float)>*)ctx;
542 float result[N];
543 for (int i = 0; i < N; ++i) {
544 result[i] = (*fn)(r[i]);
545 }
546 r = SkNf::Load(result);
547 }
548
549 STAGE(fn_1_g, true) {
550 auto fn = (const std::function<float(float)>*)ctx;
551 float result[N];
552 for (int i = 0; i < N; ++i) {
553 result[i] = (*fn)(g[i]);
554 }
555 g = SkNf::Load(result);
556 }
557
558 STAGE(fn_1_b, true) {
559 auto fn = (const std::function<float(float)>*)ctx;
560 float result[N];
561 for (int i = 0; i < N; ++i) {
562 result[i] = (*fn)(b[i]);
563 }
564 b = SkNf::Load(result);
565 }
566
567 STAGE(color_lookup_table, true) {
568 const SkColorLookUpTable* colorLUT = (const SkColorLookUpTable*)ctx;
569 float rgb[3];
570 float result[3][N];
571 for (int i = 0; i < N; ++i) {
572 rgb[0] = r[i];
573 rgb[1] = g[i];
574 rgb[2] = b[i];
575 colorLUT->interp3D(rgb, rgb);
576 result[0][i] = rgb[0];
577 result[1][i] = rgb[1];
578 result[2][i] = rgb[2];
579 }
580 r = SkNf::Load(result[0]);
581 g = SkNf::Load(result[1]);
582 b = SkNf::Load(result[2]);
583 }
584
585 STAGE(lab_to_xyz, true) {
586 const auto lab_l = r * 100.0f;
587 const auto lab_a = g * 255.0f - 128.0f;
588 const auto lab_b = b * 255.0f - 128.0f;
589 auto Y = (lab_l + 16.0f) * (1/116.0f);
590 auto X = lab_a * (1/500.0f) + Y;
591 auto Z = Y - (lab_b * (1/200.0f));
592
593 const auto X3 = X*X*X;
594 X = (X3 > 0.008856f).thenElse(X3, (X - (16/116.0f)) * (1/7.787f));
595 const auto Y3 = Y*Y*Y;
596 Y = (Y3 > 0.008856f).thenElse(Y3, (Y - (16/116.0f)) * (1/7.787f));
597 const auto Z3 = Z*Z*Z;
598 Z = (Z3 > 0.008856f).thenElse(Z3, (Z - (16/116.0f)) * (1/7.787f));
599
600 // adjust to D50 illuminant
601 X *= 0.96422f;
602 Y *= 1.00000f;
603 Z *= 0.82521f;
604
605 r = X;
606 g = Y;
607 b = Z;
608 }
609
610 STAGE(swap_rb, true) {
611 SkTSwap(r, b);
612 }
613
507 template <typename Fn> 614 template <typename Fn>
508 SI Fn enum_to_Fn(SkRasterPipeline::StockStage st) { 615 SI Fn enum_to_Fn(SkRasterPipeline::StockStage st) {
509 switch (st) { 616 switch (st) {
510 #define M(stage) case SkRasterPipeline::stage: return stage; 617 #define M(stage) case SkRasterPipeline::stage: return stage;
511 SK_RASTER_PIPELINE_STAGES(M) 618 SK_RASTER_PIPELINE_STAGES(M)
512 #undef M 619 #undef M
513 } 620 }
514 SkASSERT(false); 621 SkASSERT(false);
515 return just_return; 622 return just_return;
516 } 623 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 } 704 }
598 705
599 } // namespace SK_OPTS_NS 706 } // namespace SK_OPTS_NS
600 707
601 #undef SI 708 #undef SI
602 #undef STAGE 709 #undef STAGE
603 #undef RGBA_XFERMODE 710 #undef RGBA_XFERMODE
604 #undef RGB_XFERMODE 711 #undef RGB_XFERMODE
605 712
606 #endif//SkRasterPipeline_opts_DEFINED 713 #endif//SkRasterPipeline_opts_DEFINED
OLDNEW
« no previous file with comments | « src/core/SkRasterPipeline.h ('k') | tests/ColorSpaceXformTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698