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

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

Issue 1372973002: Move all knowledge of X sampling into SkScaledCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@codecSDmerge
Patch Set: Attempt to fix RLE overflow Created 5 years, 2 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') | src/codec/SkWebpCodec.h » ('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 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 "SkScaledCodec.h" 10 #include "SkScaledCodec.h"
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 src += deltaSrc; 509 src += deltaSrc;
510 alphaMask &= alpha; 510 alphaMask &= alpha;
511 } 511 }
512 return alphaMask != 0xFF; 512 return alphaMask != 0xFF;
513 } 513 }
514 */ 514 */
515 515
516 SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, 516 SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc,
517 const SkPMColor* ctable, 517 const SkPMColor* ctable,
518 const SkImageInfo& dstInfo, 518 const SkImageInfo& dstInfo,
519 SkCodec::ZeroInitialized zeroInit, 519 SkCodec::ZeroInitialized zeroInit) {
520 const SkImageInfo& srcInfo) {
521 if (dstInfo.colorType() == kUnknown_SkColorType || kUnknown == sc) { 520 if (dstInfo.colorType() == kUnknown_SkColorType || kUnknown == sc) {
522 return nullptr; 521 return nullptr;
523 } 522 }
524 if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc) 523 if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc)
525 && nullptr == ctable) { 524 && nullptr == ctable) {
526 return nullptr; 525 return nullptr;
527 } 526 }
528 RowProc proc = nullptr; 527 RowProc proc = nullptr;
529 528
530 switch (sc) { 529 switch (sc) {
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 default: 680 default:
682 break; 681 break;
683 } 682 }
684 if (nullptr == proc) { 683 if (nullptr == proc) {
685 return nullptr; 684 return nullptr;
686 } 685 }
687 686
688 // Store deltaSrc in bytes if it is an even multiple, otherwise use bits 687 // Store deltaSrc in bytes if it is an even multiple, otherwise use bits
689 int deltaSrc = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : BitsPerPix el(sc); 688 int deltaSrc = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : BitsPerPix el(sc);
690 689
691 // get sampleX based on srcInfo and dstInfo dimensions 690 return new SkSwizzler(proc, ctable, deltaSrc, dstInfo.width());
692 int sampleX;
693 SkScaledCodec::ComputeSampleSize(dstInfo, srcInfo, &sampleX, nullptr);
694
695 return new SkSwizzler(proc, ctable, deltaSrc, dstInfo, sampleX);
696 } 691 }
697 692
698 SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable, 693 SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable,
699 int deltaSrc, const SkImageInfo& info, int sampleX) 694 int deltaSrc, int srcWidth)
700 : fRowProc(proc) 695 : fRowProc(proc)
701 , fColorTable(ctable) 696 , fColorTable(ctable)
702 , fDeltaSrc(deltaSrc) 697 , fDeltaSrc(deltaSrc)
703 , fDstInfo(info) 698 , fSrcWidth(srcWidth)
704 , fSampleX(sampleX) 699 , fDstWidth(srcWidth)
705 , fX0(get_start_coord(sampleX)) 700 , fSampleX(1)
706 { 701 , fX0(0)
702 {}
703
704 int SkSwizzler::onSetSampleX(int sampleX) {
705 SkASSERT(sampleX > 0); // Surely there is an upper limit? Should there be
706 // way to report failure?
707 fSampleX = sampleX;
708 fX0 = get_start_coord(sampleX);
709 fDstWidth = get_scaled_dimension(fSrcWidth, sampleX);
710
707 // check that fX0 is less than original width 711 // check that fX0 is less than original width
708 SkASSERT(fX0 >= 0 && fX0 < fDstInfo.width() * fSampleX); 712 SkASSERT(fX0 >= 0 && fX0 < fSrcWidth);
713 return fDstWidth;
709 } 714 }
710 715
711 SkSwizzler::ResultAlpha SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRIC T src) { 716 SkSwizzler::ResultAlpha SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRIC T src) {
712 SkASSERT(nullptr != dst && nullptr != src); 717 SkASSERT(nullptr != dst && nullptr != src);
713 return fRowProc(dst, src, fDstInfo.width(), fDeltaSrc, fSampleX * fDeltaSrc, 718 return fRowProc(dst, src, fDstWidth, fDeltaSrc, fSampleX * fDeltaSrc,
714 fX0 * fDeltaSrc, fColorTable); 719 fX0 * fDeltaSrc, fColorTable);
715 } 720 }
716 721
717 void SkSwizzler::Fill(void* dstStartRow, const SkImageInfo& dstInfo, size_t dstR owBytes, 722 void SkSwizzler::Fill(void* dstStartRow, const SkImageInfo& dstInfo, size_t dstR owBytes,
718 uint32_t numRows, uint32_t colorOrIndex, const SkPMColor* colorTable, 723 uint32_t numRows, uint32_t colorOrIndex, const SkPMColor* colorTable,
719 SkCodec::ZeroInitialized zeroInit) { 724 SkCodec::ZeroInitialized zeroInit) {
720 SkASSERT(dstStartRow != nullptr); 725 SkASSERT(dstStartRow != nullptr);
721 SkASSERT(numRows <= (uint32_t) dstInfo.height()); 726 SkASSERT(numRows <= (uint32_t) dstInfo.height());
722 727
723 // Calculate bytes to fill. We use getSafeSize since the last row may not b e padded. 728 // Calculate bytes to fill. We use getSafeSize since the last row may not b e padded.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 } 789 }
785 790
786 memset(dstStartRow, (uint8_t) colorOrIndex, bytesToFill); 791 memset(dstStartRow, (uint8_t) colorOrIndex, bytesToFill);
787 break; 792 break;
788 default: 793 default:
789 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n"); 794 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n");
790 SkASSERT(false); 795 SkASSERT(false);
791 break; 796 break;
792 } 797 }
793 } 798 }
OLDNEW
« no previous file with comments | « src/codec/SkSwizzler.h ('k') | src/codec/SkWebpCodec.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698