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

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

Issue 1321433002: Add subsetting to SkScaledCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@gif-scan
Patch Set: Rebase - it compiles but I'm sure everything is broken 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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth, 223 void* SK_RESTRICT dstRow, const uint8_t* SK_RESTRICT src, int dstWidth,
224 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) { 224 int bpp, int deltaSrc, int offset, const SkPMColor ctable[]) {
225 225
226 src += offset; 226 src += offset;
227 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow; 227 uint8_t* SK_RESTRICT dst = (uint8_t*) dstRow;
228 INIT_RESULT_ALPHA; 228 INIT_RESULT_ALPHA;
229 // TODO (msarett): Should we skip the loop here and guess that the row is op aque/not opaque? 229 // TODO (msarett): Should we skip the loop here and guess that the row is op aque/not opaque?
230 // SkScaledBitmap sampler just guesses that it is opaque. T his is dangerous 230 // SkScaledBitmap sampler just guesses that it is opaque. T his is dangerous
231 // and probably wrong since gif and bmp (rarely) may have al pha. 231 // and probably wrong since gif and bmp (rarely) may have al pha.
232 if (1 == deltaSrc) { 232 if (1 == deltaSrc) {
233 // A non-zero offset is only used when sampling, meaning that deltaSrc w ill be
234 // greater than 1. The below loop relies on the fact that src remains un changed.
235 SkASSERT(0 == offset);
236 memcpy(dst, src, dstWidth); 233 memcpy(dst, src, dstWidth);
237 for (int x = 0; x < dstWidth; x++) { 234 for (int x = 0; x < dstWidth; x++) {
238 UPDATE_RESULT_ALPHA(ctable[src[x]] >> SK_A32_SHIFT); 235 UPDATE_RESULT_ALPHA(ctable[src[x]] >> SK_A32_SHIFT);
239 } 236 }
240 } else { 237 } else {
241 for (int x = 0; x < dstWidth; x++) { 238 for (int x = 0; x < dstWidth; x++) {
242 dst[x] = *src; 239 dst[x] = *src;
243 UPDATE_RESULT_ALPHA(ctable[*src] >> SK_A32_SHIFT); 240 UPDATE_RESULT_ALPHA(ctable[*src] >> SK_A32_SHIFT);
244 src += deltaSrc; 241 src += deltaSrc;
245 } 242 }
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 } 504 }
508 src += deltaSrc; 505 src += deltaSrc;
509 alphaMask &= alpha; 506 alphaMask &= alpha;
510 } 507 }
511 return alphaMask != 0xFF; 508 return alphaMask != 0xFF;
512 } 509 }
513 */ 510 */
514 511
515 SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc, 512 SkSwizzler* SkSwizzler::CreateSwizzler(SkSwizzler::SrcConfig sc,
516 const SkPMColor* ctable, 513 const SkPMColor* ctable,
517 const SkImageInfo& dstInfo, 514 const SkImageInfo& dstInfo,
518 SkCodec::ZeroInitialized zeroInit) { 515 SkCodec::ZeroInitialized zeroInit,
516 int subsetLeft, int subsetWidth) {
519 if (dstInfo.colorType() == kUnknown_SkColorType || kUnknown == sc) { 517 if (dstInfo.colorType() == kUnknown_SkColorType || kUnknown == sc) {
520 return nullptr; 518 return nullptr;
521 } 519 }
522 if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc) 520 if ((kIndex == sc || kIndex4 == sc || kIndex2 == sc || kIndex1 == sc)
523 && nullptr == ctable) { 521 && nullptr == ctable) {
524 return nullptr; 522 return nullptr;
525 } 523 }
526 RowProc proc = nullptr; 524 RowProc proc = nullptr;
527 525
528 switch (sc) { 526 switch (sc) {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 default: 674 default:
677 break; 675 break;
678 } 676 }
679 default: 677 default:
680 break; 678 break;
681 } 679 }
682 if (nullptr == proc) { 680 if (nullptr == proc) {
683 return nullptr; 681 return nullptr;
684 } 682 }
685 683
686 // Store deltaSrc in bytes if it is an even multiple, otherwise use bits 684 // Store bpp in bytes if it is an even multiple, otherwise use bits
687 int deltaSrc = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : BitsPerPix el(sc); 685 int bpp = SkIsAlign8(BitsPerPixel(sc)) ? BytesPerPixel(sc) : BitsPerPixel(sc );
688 686
689 return new SkSwizzler(proc, ctable, deltaSrc, dstInfo.width()); 687 return new SkSwizzler(proc, ctable, subsetLeft, subsetWidth, bpp);
690 } 688 }
691 689
692 SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable, 690 SkSwizzler::SkSwizzler(RowProc proc, const SkPMColor* ctable, int srcOffset, int srcWidth, int bpp)
693 int deltaSrc, int srcWidth)
694 : fRowProc(proc) 691 : fRowProc(proc)
695 , fColorTable(ctable) 692 , fColorTable(ctable)
696 , fDeltaSrc(deltaSrc) 693 , fSrcOffset(srcOffset)
694 , fX0(srcOffset)
697 , fSrcWidth(srcWidth) 695 , fSrcWidth(srcWidth)
698 , fDstWidth(srcWidth) 696 , fDstWidth(srcWidth)
697 , fBPP(bpp)
699 , fSampleX(1) 698 , fSampleX(1)
700 , fX0(0)
701 {} 699 {}
702 700
701 SkSwizzler::ResultAlpha SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRIC T src) {
702 SkASSERT(nullptr != dst && nullptr != src);
703 return fRowProc(dst, src, fDstWidth, fBPP, fSampleX * fBPP, fX0 * fBPP, fCol orTable);
704 }
705
703 int SkSwizzler::onSetSampleX(int sampleX) { 706 int SkSwizzler::onSetSampleX(int sampleX) {
704 SkASSERT(sampleX > 0); // Surely there is an upper limit? Should there be 707 SkASSERT(sampleX > 0); // Surely there is an upper limit? Should there be
705 // way to report failure? 708 // way to report failure?
706 fSampleX = sampleX; 709 fSampleX = sampleX;
707 fX0 = get_start_coord(sampleX); 710 fX0 = fSrcOffset + get_start_coord(sampleX);
708 fDstWidth = get_scaled_dimension(fSrcWidth, sampleX); 711 fDstWidth = get_scaled_dimension(fSrcWidth, sampleX);
709 712
710 // check that fX0 is less than original width 713 // check that fX0 is less than original width
711 SkASSERT(fX0 >= 0 && fX0 < fSrcWidth); 714 SkASSERT(fX0 >= 0 && fX0 < fSrcWidth);
712 return fDstWidth; 715 return fDstWidth;
713 } 716 }
714
715 SkSwizzler::ResultAlpha SkSwizzler::swizzle(void* dst, const uint8_t* SK_RESTRIC T src) {
716 SkASSERT(nullptr != dst && nullptr != src);
717 return fRowProc(dst, src, fDstWidth, fDeltaSrc, fSampleX * fDeltaSrc,
718 fX0 * fDeltaSrc, fColorTable);
719 }
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