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

Side by Side Diff: src/codec/SkSwizzler.cpp

Issue 1563393002: Use SkOpts routines in SkSwizzler (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Response to comments Created 4 years, 11 months 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/codec/SkSwizzler.h ('k') | no next file » | 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 2015 Google Inc. 2 * Copyright 2015 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 "SkCodecPriv.h" 8 #include "SkCodecPriv.h"
9 #include "SkColorPriv.h" 9 #include "SkColorPriv.h"
10 #include "SkOpts.h"
10 #include "SkSwizzler.h" 11 #include "SkSwizzler.h"
11 #include "SkTemplates.h" 12 #include "SkTemplates.h"
12 13
13 // samples the row. Does not do anything else but sampling 14 // samples the row. Does not do anything else but sampling
14 static void sample565(void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, 15 static void sample565(void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src,
15 int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[]){ 16 int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[]){
16 17
17 src += offset; 18 src += offset;
18 uint16_t* SK_RESTRICT dst = (uint16_t*) dstRow; 19 uint16_t* SK_RESTRICT dst = (uint16_t*) dstRow;
19 for (int x = 0; x < width; x++) { 20 for (int x = 0; x < width; x++) {
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) { 361 int bytesPerPixel, int deltaSrc, int offset, const SkPMColor ctable[]) {
361 362
362 src += offset; 363 src += offset;
363 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow; 364 uint16_t* SK_RESTRICT dst = (uint16_t*)dstRow;
364 for (int x = 0; x < dstWidth; x++) { 365 for (int x = 0; x < dstWidth; x++) {
365 dst[x] = SkPack888ToRGB16(src[0], src[1], src[2]); 366 dst[x] = SkPack888ToRGB16(src[0], src[1], src[2]);
366 src += deltaSrc; 367 src += deltaSrc;
367 } 368 }
368 } 369 }
369 370
370
371 // kRGBA 371 // kRGBA
372 static void swizzle_rgba_to_n32_premul( 372 static void swizzle_rgba_to_n32_premul(
373 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 373 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
374 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { 374 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
375 375
376 src += offset; 376 src += offset;
377 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 377 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
378 for (int x = 0; x < dstWidth; x++) { 378 for (int x = 0; x < dstWidth; x++) {
379 unsigned alpha = src[3]; 379 unsigned alpha = src[3];
380 dst[x] = SkPremultiplyARGBInline(alpha, src[0], src[1], src[2]); 380 dst[x] = SkPremultiplyARGBInline(alpha, src[0], src[1], src[2]);
381 src += deltaSrc; 381 src += deltaSrc;
382 } 382 }
383 } 383 }
384 384
385 static void fast_swizzle_rgba_to_n32_premul(
386 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc,
387 int offset, const SkPMColor ctable[]) {
388
389 // This function must not be called if we are sampling. If we are not
390 // sampling, deltaSrc should equal bpp.
391 SkASSERT(deltaSrc == bpp);
392
393 #ifdef SK_PMCOLOR_IS_RGBA
394 SkOpts::premul_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset), width );
395 #else
396 SkOpts::premul_swaprb_xxxa((uint32_t*) dst, (const uint32_t*) (src + offset) , width);
397 #endif
398 }
399
385 static void swizzle_rgba_to_n32_unpremul( 400 static void swizzle_rgba_to_n32_unpremul(
386 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 401 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
387 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { 402 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
388 403
389 src += offset; 404 src += offset;
390 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow); 405 uint32_t* SK_RESTRICT dst = reinterpret_cast<uint32_t*>(dstRow);
391 for (int x = 0; x < dstWidth; x++) { 406 for (int x = 0; x < dstWidth; x++) {
392 unsigned alpha = src[3]; 407 unsigned alpha = src[3];
393 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]); 408 dst[x] = SkPackARGB32NoCheck(alpha, src[0], src[1], src[2]);
394 src += deltaSrc; 409 src += deltaSrc;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 const SkImageInfo& dstInfo, 535 const SkImageInfo& dstInfo,
521 const SkCodec::Options& options, 536 const SkCodec::Options& options,
522 const SkIRect* frame) { 537 const SkIRect* frame) {
523 if (dstInfo.colorType() == kUnknown_SkColorType || kUnknown == sc) { 538 if (dstInfo.colorType() == kUnknown_SkColorType || kUnknown == sc) {
524 return nullptr; 539 return nullptr;
525 } 540 }
526 if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc) 541 if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc)
527 && nullptr == ctable) { 542 && nullptr == ctable) {
528 return nullptr; 543 return nullptr;
529 } 544 }
545 RowProc fastProc = nullptr;
530 RowProc proc = nullptr; 546 RowProc proc = nullptr;
531 SkCodec::ZeroInitialized zeroInit = options.fZeroInitialized; 547 SkCodec::ZeroInitialized zeroInit = options.fZeroInitialized;
532 switch (sc) { 548 switch (sc) {
533 case kBit: 549 case kBit:
534 switch (dstInfo.colorType()) { 550 switch (dstInfo.colorType()) {
535 case kN32_SkColorType: 551 case kN32_SkColorType:
536 proc = &swizzle_bit_to_n32; 552 proc = &swizzle_bit_to_n32;
537 break; 553 break;
538 case kIndex_8_SkColorType: 554 case kIndex_8_SkColorType:
539 proc = &swizzle_bit_to_index; 555 proc = &swizzle_bit_to_index;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 break; 643 break;
628 default: 644 default:
629 break; 645 break;
630 } 646 }
631 break; 647 break;
632 default: 648 default:
633 break; 649 break;
634 } 650 }
635 break; 651 break;
636 case kRGBX: 652 case kRGBX:
637 // TODO: Support other swizzles.
638 switch (dstInfo.colorType()) { 653 switch (dstInfo.colorType()) {
639 case kN32_SkColorType: 654 case kN32_SkColorType:
640 proc = &swizzle_rgbx_to_n32; 655 proc = &swizzle_rgbx_to_n32;
641 break; 656 break;
642 case kRGB_565_SkColorType: 657 case kRGB_565_SkColorType:
643 proc = &swizzle_rgbx_to_565; 658 proc = &swizzle_rgbx_to_565;
644 default: 659 default:
645 break; 660 break;
646 } 661 }
647 break; 662 break;
648 case kRGBA: 663 case kRGBA:
649 switch (dstInfo.colorType()) { 664 switch (dstInfo.colorType()) {
650 case kN32_SkColorType: 665 case kN32_SkColorType:
651 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) { 666 if (dstInfo.alphaType() == kUnpremul_SkAlphaType) {
652 // Respect zeroInit? 667 // Respect zeroInit?
653 proc = &swizzle_rgba_to_n32_unpremul; 668 proc = &swizzle_rgba_to_n32_unpremul;
654 } else { 669 } else {
670 fastProc = &fast_swizzle_rgba_to_n32_premul;
655 if (SkCodec::kYes_ZeroInitialized == zeroInit) { 671 if (SkCodec::kYes_ZeroInitialized == zeroInit) {
656 proc = &swizzle_rgba_to_n32_premul_skipZ; 672 proc = &swizzle_rgba_to_n32_premul_skipZ;
657 } else { 673 } else {
658 proc = &swizzle_rgba_to_n32_premul; 674 proc = &swizzle_rgba_to_n32_premul;
659 } 675 }
660 } 676 }
661 break; 677 break;
662 default: 678 default:
663 break; 679 break;
664 } 680 }
(...skipping 24 matching lines...) Expand all
689 case kRGB_565_SkColorType: 705 case kRGB_565_SkColorType:
690 proc = &swizzle_cmyk_to_565; 706 proc = &swizzle_cmyk_to_565;
691 break; 707 break;
692 default: 708 default:
693 break; 709 break;
694 } 710 }
695 break; 711 break;
696 default: 712 default:
697 break; 713 break;
698 } 714 }
699 if (nullptr == proc) {
700 return nullptr;
701 }
702 715
703 // Store bpp in bytes if it is an even multiple, otherwise use bits 716 // Store bpp in bytes if it is an even multiple, otherwise use bits
704 int srcBPP = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : BitsPerPixel (sc); 717 int srcBPP = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : BitsPerPixel (sc);
705 int dstBPP = SkColorTypeBytesPerPixel(dstInfo.colorType()); 718 int dstBPP = SkColorTypeBytesPerPixel(dstInfo.colorType());
706 719
707 int srcOffset = 0; 720 int srcOffset = 0;
708 int srcWidth = dstInfo.width(); 721 int srcWidth = dstInfo.width();
709 int dstOffset = 0; 722 int dstOffset = 0;
710 int dstWidth = srcWidth; 723 int dstWidth = srcWidth;
711 if (options.fSubset) { 724 if (options.fSubset) {
712 // We do not currently support subset decodes for image types that may h ave 725 // We do not currently support subset decodes for image types that may h ave
713 // frames (gif). 726 // frames (gif).
714 SkASSERT(!frame); 727 SkASSERT(!frame);
715 srcOffset = options.fSubset->left(); 728 srcOffset = options.fSubset->left();
716 srcWidth = options.fSubset->width(); 729 srcWidth = options.fSubset->width();
717 dstWidth = srcWidth; 730 dstWidth = srcWidth;
718 } else if (frame) { 731 } else if (frame) {
719 dstOffset = frame->left(); 732 dstOffset = frame->left();
720 srcWidth = frame->width(); 733 srcWidth = frame->width();
721 } 734 }
722 735
723 return new SkSwizzler(proc, ctable, srcOffset, srcWidth, dstOffset, dstWidth , srcBPP, dstBPP); 736 return new SkSwizzler(fastProc, proc, ctable, srcOffset, srcWidth, dstOffset , dstWidth,
737 srcBPP, dstBPP);
724 } 738 }
725 739
726 SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable, int srcOffset, int srcWidth, 740 SkSwizzler::SkSwizzler(RowProc fastProc, RowProc proc, const SkPMColor* ctable, int srcOffset,
727 int dstOffset, int dstWidth, int srcBPP, int dstBPP) 741 int srcWidth, int dstOffset, int dstWidth, int srcBPP, int dstBPP)
728 : fRowProc(proc) 742 : fFastProc(fastProc)
743 , fProc(proc)
729 , fColorTable(ctable) 744 , fColorTable(ctable)
730 , fSrcOffset(srcOffset) 745 , fSrcOffset(srcOffset)
731 , fDstOffset(dstOffset) 746 , fDstOffset(dstOffset)
732 , fSrcOffsetUnits(srcOffset * srcBPP) 747 , fSrcOffsetUnits(srcOffset * srcBPP)
733 , fDstOffsetBytes(dstOffset * dstBPP) 748 , fDstOffsetBytes(dstOffset * dstBPP)
734 , fSrcWidth(srcWidth) 749 , fSrcWidth(srcWidth)
735 , fDstWidth(dstWidth) 750 , fDstWidth(dstWidth)
736 , fSwizzleWidth(srcWidth) 751 , fSwizzleWidth(srcWidth)
737 , fAllocatedWidth(dstWidth) 752 , fAllocatedWidth(dstWidth)
738 , fSampleX(1) 753 , fSampleX(1)
739 , fSrcBPP(srcBPP) 754 , fSrcBPP(srcBPP)
740 , fDstBPP(dstBPP) 755 , fDstBPP(dstBPP)
741 {} 756 {}
742 757
743 int SkSwizzler::onSetSampleX(int sampleX) { 758 int SkSwizzler::onSetSampleX(int sampleX) {
744 SkASSERT(sampleX > 0); // Surely there is an upper limit? Should there be 759 SkASSERT(sampleX > 0); // Surely there is an upper limit? Should there be
745 // way to report failure? 760 // way to report failure?
746 fSampleX = sampleX; 761 fSampleX = sampleX;
747 fSrcOffsetUnits = (get_start_coord(sampleX) + fSrcOffset) * fSrcBPP; 762 fSrcOffsetUnits = (get_start_coord(sampleX) + fSrcOffset) * fSrcBPP;
748 fDstOffsetBytes = (fDstOffset / sampleX) * fDstBPP; 763 fDstOffsetBytes = (fDstOffset / sampleX) * fDstBPP;
749 fSwizzleWidth = get_scaled_dimension(fSrcWidth, sampleX); 764 fSwizzleWidth = get_scaled_dimension(fSrcWidth, sampleX);
750 fAllocatedWidth = get_scaled_dimension(fDstWidth, sampleX); 765 fAllocatedWidth = get_scaled_dimension(fDstWidth, sampleX);
751 766
767 // The optimized swizzler routines do not (yet) support sampling.
768 fFastProc = nullptr;
769
752 return fAllocatedWidth; 770 return fAllocatedWidth;
753 } 771 }
754 772
755 void SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) { 773 void SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) {
756 SkASSERT(nullptr != dst && nullptr != src); 774 SkASSERT(nullptr != dst && nullptr != src);
757 fRowProc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fSrcB PP, 775 if (fFastProc) {
mtklein 2016/01/11 21:07:21 You might do RowProc proc = fFastProc ? fFastProc
msarett 2016/01/12 14:35:51 Done.
758 fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable); 776 fFastProc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fSrcBPP,
777 fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable);
778 } else {
779 fProc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fSrc BPP,
780 fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable);;
781 }
759 } 782 }
OLDNEW
« no previous file with comments | « src/codec/SkSwizzler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698