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

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

Issue 1671003004: Skip memcpy() swizzles in SkPngCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: First Approach Created 4 years, 10 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
« src/codec/SkPngCodec.cpp ('K') | « src/codec/SkPngCodec.cpp ('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 "SkOpts.h"
11 #include "SkSwizzler.h" 11 #include "SkSwizzler.h"
12 #include "SkTemplates.h" 12 #include "SkTemplates.h"
13 13
14 static void copy(void* dst, const uint8_t* src, int width, int bpp, int deltaSrc , int offset, 14 static void noop(void* dst, const uint8_t* src, int width, int bpp, int deltaSrc , int offset,
msarett 2016/02/05 20:48:18 This is broken as is. It works for PNG, but I woul
15 const SkPMColor ctable[]) { 15 const SkPMColor ctable[]) {
16 // This function must not be called if we are sampling. If we are not 16 // This function must not be called if we are sampling. If we are not
17 // sampling, deltaSrc should equal bpp. 17 // sampling, deltaSrc should equal bpp.
18 SkASSERT(deltaSrc == bpp); 18 SkASSERT(deltaSrc == bpp);
19
20 memcpy(dst, src + offset, width * bpp);
21 } 19 }
22 20
23 static void sample1(void* dst, const uint8_t* src, int width, int bpp, int delta Src, int offset, 21 static void sample1(void* dst, const uint8_t* src, int width, int bpp, int delta Src, int offset,
24 const SkPMColor ctable[]) { 22 const SkPMColor ctable[]) {
25 src += offset; 23 src += offset;
26 uint8_t* dst8 = (uint8_t*) dst; 24 uint8_t* dst8 = (uint8_t*) dst;
27 for (int x = 0; x < width; x++) { 25 for (int x = 0; x < width; x++) {
28 dst8[x] = *src; 26 dst8[x] = *src;
29 src += deltaSrc; 27 src += deltaSrc;
30 } 28 }
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off set, 391 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off set,
394 const SkPMColor ctable[]) { 392 const SkPMColor ctable[]) {
395 393
396 // This function must not be called if we are sampling. If we are not 394 // This function must not be called if we are sampling. If we are not
397 // sampling, deltaSrc should equal bpp. 395 // sampling, deltaSrc should equal bpp.
398 SkASSERT(deltaSrc == bpp); 396 SkASSERT(deltaSrc == bpp);
399 397
400 #ifdef SK_PMCOLOR_IS_RGBA 398 #ifdef SK_PMCOLOR_IS_RGBA
401 SkOpts::RGBA_to_BGRA((uint32_t*) dst, src + offset, width); 399 SkOpts::RGBA_to_BGRA((uint32_t*) dst, src + offset, width);
402 #else 400 #else
403 memcpy(dst, src + offset, width * bpp); 401 // Nothing needs to be done here.
404 #endif 402 #endif
405 } 403 }
406 404
407 static void swizzle_bgra_to_n32_premul( 405 static void swizzle_bgra_to_n32_premul(
408 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 406 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
409 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { 407 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
410 408
411 src += offset; 409 src += offset;
412 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow; 410 SkPMColor* SK_RESTRICT dst = (SkPMColor*)dstRow;
413 for (int x = 0; x < dstWidth; x++) { 411 for (int x = 0; x < dstWidth; x++) {
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 516
519 static void fast_swizzle_rgba_to_n32_unpremul( 517 static void fast_swizzle_rgba_to_n32_unpremul(
520 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off set, 518 void* dst, const uint8_t* src, int width, int bpp, int deltaSrc, int off set,
521 const SkPMColor ctable[]) { 519 const SkPMColor ctable[]) {
522 520
523 // This function must not be called if we are sampling. If we are not 521 // This function must not be called if we are sampling. If we are not
524 // sampling, deltaSrc should equal bpp. 522 // sampling, deltaSrc should equal bpp.
525 SkASSERT(deltaSrc == bpp); 523 SkASSERT(deltaSrc == bpp);
526 524
527 #ifdef SK_PMCOLOR_IS_RGBA 525 #ifdef SK_PMCOLOR_IS_RGBA
528 memcpy(dst, src + offset, width * bpp); 526 // Nothing needs to be done here.
529 #else 527 #else
530 SkOpts::RGBA_to_BGRA((uint32_t*) dst, src + offset, width); 528 SkOpts::RGBA_to_BGRA((uint32_t*) dst, src + offset, width);
531 #endif 529 #endif
532 } 530 }
533 531
534 // kCMYK 532 // kCMYK
535 // 533 //
536 // CMYK is stored as four bytes per pixel. 534 // CMYK is stored as four bytes per pixel.
537 // 535 //
538 // We will implement a crude conversion from CMYK -> RGB using formulas 536 // We will implement a crude conversion from CMYK -> RGB using formulas
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 } else { 705 } else {
708 proc = &swizzle_index_to_n32; 706 proc = &swizzle_index_to_n32;
709 break; 707 break;
710 } 708 }
711 break; 709 break;
712 case kRGB_565_SkColorType: 710 case kRGB_565_SkColorType:
713 proc = &swizzle_index_to_565; 711 proc = &swizzle_index_to_565;
714 break; 712 break;
715 case kIndex_8_SkColorType: 713 case kIndex_8_SkColorType:
716 proc = &sample1; 714 proc = &sample1;
717 fastProc = &copy; 715 fastProc = &noop;
718 break; 716 break;
719 default: 717 default:
720 break; 718 break;
721 } 719 }
722 break; 720 break;
723 case kGray: 721 case kGray:
724 switch (dstInfo.colorType()) { 722 switch (dstInfo.colorType()) {
725 case kN32_SkColorType: 723 case kN32_SkColorType:
726 proc = &swizzle_gray_to_n32; 724 proc = &swizzle_gray_to_n32;
727 fastProc = &fast_swizzle_gray_to_n32; 725 fastProc = &fast_swizzle_gray_to_n32;
728 break; 726 break;
729 case kGray_8_SkColorType: 727 case kGray_8_SkColorType:
730 proc = &sample1; 728 proc = &sample1;
731 fastProc = &copy; 729 fastProc = &noop;
732 break; 730 break;
733 case kRGB_565_SkColorType: 731 case kRGB_565_SkColorType:
734 proc = &swizzle_gray_to_565; 732 proc = &swizzle_gray_to_565;
735 break; 733 break;
736 default: 734 default:
737 break; 735 break;
738 } 736 }
739 break; 737 break;
740 case kGrayAlpha: 738 case kGrayAlpha:
741 switch (dstInfo.colorType()) { 739 switch (dstInfo.colorType()) {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 break; 845 break;
848 case kRGB_565_SkColorType: 846 case kRGB_565_SkColorType:
849 proc = &swizzle_cmyk_to_565; 847 proc = &swizzle_cmyk_to_565;
850 break; 848 break;
851 default: 849 default:
852 break; 850 break;
853 } 851 }
854 break; 852 break;
855 case kNoOp8: 853 case kNoOp8:
856 proc = &sample1; 854 proc = &sample1;
857 fastProc = &copy; 855 fastProc = &noop;
858 break; 856 break;
859 case kNoOp16: 857 case kNoOp16:
860 proc = sample2; 858 proc = sample2;
861 fastProc = &copy; 859 fastProc = &noop;
862 break; 860 break;
863 case kNoOp32: 861 case kNoOp32:
864 proc = &sample4; 862 proc = &sample4;
865 fastProc = &copy; 863 fastProc = &noop;
866 break; 864 break;
867 default: 865 default:
868 break; 866 break;
869 } 867 }
870 868
871 // Store bpp in bytes if it is an even multiple, otherwise use bits 869 // Store bpp in bytes if it is an even multiple, otherwise use bits
872 int srcBPP = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : BitsPerPixel (sc); 870 int srcBPP = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : BitsPerPixel (sc);
873 int dstBPP = SkColorTypeBytesPerPixel(dstInfo.colorType()); 871 int dstBPP = SkColorTypeBytesPerPixel(dstInfo.colorType());
874 872
875 int srcOffset = 0; 873 int srcOffset = 0;
876 int srcWidth = dstInfo.width(); 874 int srcWidth = dstInfo.width();
877 int dstOffset = 0; 875 int dstOffset = 0;
878 int dstWidth = srcWidth; 876 int dstWidth = srcWidth;
879 if (options.fSubset) { 877 if (options.fSubset) {
880 // We do not currently support subset decodes for image types that may h ave 878 // We do not currently support subset decodes for image types that may h ave
881 // frames (gif). 879 // frames (gif).
882 SkASSERT(!frame); 880 SkASSERT(!frame);
883 srcOffset = options.fSubset->left(); 881 srcOffset = options.fSubset->left();
884 srcWidth = options.fSubset->width(); 882 srcWidth = options.fSubset->width();
885 dstWidth = srcWidth; 883 dstWidth = srcWidth;
884 fastProc = nullptr;
msarett 2016/02/05 20:48:18 Problem: We need the swizzler to do a copy for us
886 } else if (frame) { 885 } else if (frame) {
887 dstOffset = frame->left(); 886 dstOffset = frame->left();
888 srcWidth = frame->width(); 887 srcWidth = frame->width();
889 } 888 }
890 889
891 return new SkSwizzler(fastProc, proc, ctable, srcOffset, srcWidth, dstOffset , dstWidth, 890 return new SkSwizzler(fastProc, proc, ctable, srcOffset, srcWidth, dstOffset , dstWidth,
892 srcBPP, dstBPP); 891 srcBPP, dstBPP);
893 } 892 }
894 893
895 SkSwizzler::SkSwizzler(RowProc fastProc, RowProc proc, const SkPMColor* ctable, int srcOffset, 894 SkSwizzler::SkSwizzler(RowProc fastProc, RowProc proc, const SkPMColor* ctable, int srcOffset,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 } 927 }
929 928
930 return fAllocatedWidth; 929 return fAllocatedWidth;
931 } 930 }
932 931
933 void SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) { 932 void SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRICT src) {
934 SkASSERT(nullptr != dst && nullptr != src); 933 SkASSERT(nullptr != dst && nullptr != src);
935 fActualProc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fS rcBPP, 934 fActualProc(SkTAddOffset<void>(dst, fDstOffsetBytes), src, fSwizzleWidth, fS rcBPP,
936 fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable); 935 fSampleX * fSrcBPP, fSrcOffsetUnits, fColorTable);
937 } 936 }
OLDNEW
« src/codec/SkPngCodec.cpp ('K') | « src/codec/SkPngCodec.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698