diff options
author | 2015-07-27 15:13:17 -0700 | |
---|---|---|
committer | 2015-07-27 15:13:17 -0700 | |
commit | 614aa072cbb055a29f37fa25a657313bccc5d666 (patch) | |
tree | 4dc42e8af7be7f4ef0a5952a5a5d5283d8bcb38c /src/codec/SkCodec_libpng.cpp | |
parent | a3a9ebcfb043b263d42c7d532ef487b99b9279fa (diff) |
Pass the destination pointer to next() in SkSwizzler
Per our discussion, we can make the swizzler simpler and more usable
for SkCodec and SkScanlineDecoder by only having a single version of
next() which takes a pointer to the srcRow and a pointer to the
dstRow.
BUG=skia:
Review URL: https://codereview.chromium.org/1256373002
Diffstat (limited to 'src/codec/SkCodec_libpng.cpp')
-rw-r--r-- | src/codec/SkCodec_libpng.cpp | 46 |
1 files changed, 22 insertions, 24 deletions
diff --git a/src/codec/SkCodec_libpng.cpp b/src/codec/SkCodec_libpng.cpp index 553233de12..9f9c110cc6 100644 --- a/src/codec/SkCodec_libpng.cpp +++ b/src/codec/SkCodec_libpng.cpp @@ -425,7 +425,6 @@ static bool conversion_possible(const SkImageInfo& dst, const SkImageInfo& src) } SkCodec::Result SkPngCodec::initializeSwizzler(const SkImageInfo& requestedInfo, - void* dst, size_t rowBytes, const Options& options, SkPMColor ctable[], int* ctableCount) { @@ -474,7 +473,7 @@ SkCodec::Result SkPngCodec::initializeSwizzler(const SkImageInfo& requestedInfo, // Create the swizzler. SkPngCodec retains ownership of the color table. const SkPMColor* colors = fColorTable ? fColorTable->readColors() : NULL; fSwizzler.reset(SkSwizzler::CreateSwizzler(fSrcConfig, colors, requestedInfo, - dst, rowBytes, options.fZeroInitialized)); + options.fZeroInitialized)); if (!fSwizzler) { // FIXME: CreateSwizzler could fail for another reason. return kUnimplemented; @@ -512,7 +511,7 @@ bool SkPngCodec::handleRewind() { } SkCodec::Result SkPngCodec::onGetPixels(const SkImageInfo& requestedInfo, void* dst, - size_t rowBytes, const Options& options, + size_t dstRowBytes, const Options& options, SkPMColor ctable[], int* ctableCount) { if (!conversion_possible(requestedInfo, this->getInfo())) { return kInvalidConversion; @@ -529,8 +528,8 @@ SkCodec::Result SkPngCodec::onGetPixels(const SkImageInfo& requestedInfo, void* } // Note that ctable and ctableCount may be modified if there is a color table - const Result result = this->initializeSwizzler(requestedInfo, dst, rowBytes, - options, ctable, ctableCount); + const Result result = this->initializeSwizzler(requestedInfo, options, + ctable, ctableCount); if (result != kSuccess) { return result; } @@ -543,36 +542,39 @@ SkCodec::Result SkPngCodec::onGetPixels(const SkImageInfo& requestedInfo, void* SkASSERT(fNumberPasses != INVALID_NUMBER_PASSES); SkAutoMalloc storage; + void* dstRow = dst; if (fNumberPasses > 1) { const int width = requestedInfo.width(); const int height = requestedInfo.height(); const int bpp = SkSwizzler::BytesPerPixel(fSrcConfig); - const size_t rowBytes = width * bpp; + const size_t srcRowBytes = width * bpp; storage.reset(width * height * bpp); uint8_t* const base = static_cast<uint8_t*>(storage.get()); for (int i = 0; i < fNumberPasses; i++) { - uint8_t* row = base; + uint8_t* srcRow = base; for (int y = 0; y < height; y++) { - uint8_t* bmRow = row; + uint8_t* bmRow = srcRow; png_read_rows(fPng_ptr, &bmRow, png_bytepp_NULL, 1); - row += rowBytes; + srcRow += srcRowBytes; } } // Now swizzle it. - uint8_t* row = base; + uint8_t* srcRow = base; for (int y = 0; y < height; y++) { - fReallyHasAlpha |= !SkSwizzler::IsOpaque(fSwizzler->next(row)); - row += rowBytes; + fReallyHasAlpha |= !SkSwizzler::IsOpaque(fSwizzler->swizzle(dstRow, srcRow)); + dstRow = SkTAddOffset<void>(dstRow, dstRowBytes); + srcRow += srcRowBytes; } } else { storage.reset(requestedInfo.width() * SkSwizzler::BytesPerPixel(fSrcConfig)); uint8_t* srcRow = static_cast<uint8_t*>(storage.get()); for (int y = 0; y < requestedInfo.height(); y++) { png_read_rows(fPng_ptr, &srcRow, png_bytepp_NULL, 1); - fReallyHasAlpha |= !SkSwizzler::IsOpaque(fSwizzler->next(srcRow)); + fReallyHasAlpha |= !SkSwizzler::IsOpaque(fSwizzler->swizzle(dstRow, srcRow)); + dstRow = SkTAddOffset<void>(dstRow, dstRowBytes); } } @@ -607,11 +609,11 @@ public: return SkCodec::kInvalidInput; } + void* dstRow = dst; for (int i = 0; i < count; i++) { png_read_rows(fCodec->fPng_ptr, &fSrcRow, png_bytepp_NULL, 1); - fCodec->fSwizzler->setDstRow(dst); - fHasAlpha |= !SkSwizzler::IsOpaque(fCodec->fSwizzler->next(fSrcRow)); - dst = SkTAddOffset<void>(dst, rowBytes); + fHasAlpha |= !SkSwizzler::IsOpaque(fCodec->fSwizzler->swizzle(dstRow, fSrcRow)); + dstRow = SkTAddOffset<void>(dstRow, rowBytes); } return SkCodec::kSuccess; } @@ -690,10 +692,10 @@ public: } //swizzle the rows we care about srcRow = storagePtr; + void* dstRow = dst; for (int y = 0; y < count; y++) { - fCodec->fSwizzler->setDstRow(dst); - fHasAlpha |= !SkSwizzler::IsOpaque(fCodec->fSwizzler->next(srcRow)); - dst = SkTAddOffset<void>(dst, dstRowBytes); + fHasAlpha |= !SkSwizzler::IsOpaque(fCodec->fSwizzler->swizzle(dstRow, srcRow)); + dstRow = SkTAddOffset<void>(dstRow, dstRowBytes); srcRow += fSrcRowBytes; } fCurrentRow += count; @@ -741,11 +743,7 @@ SkScanlineDecoder* SkPngCodec::onGetScanlineDecoder(const SkImageInfo& dstInfo, return NULL; } - // Note: We set dst to NULL since we do not know it yet. rowBytes is not needed, - // since we'll be manually updating the dstRow, but the SkSwizzler requires it to - // be at least dstInfo.minRowBytes. - if (codec->initializeSwizzler(dstInfo, NULL, dstInfo.minRowBytes(), options, ctable, - ctableCount) != kSuccess) { + if (codec->initializeSwizzler(dstInfo, options, ctable, ctableCount) != kSuccess) { SkCodecPrintf("failed to initialize the swizzler.\n"); return NULL; } |