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

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

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