Chromium Code Reviews| Index: src/codec/SkCodec_libpng.cpp |
| diff --git a/src/codec/SkCodec_libpng.cpp b/src/codec/SkCodec_libpng.cpp |
| index 250d815f6bf2aecd3204d9eb3dbc070db19166aa..3dcc6108d85ba7cfa260d3ec94bdae99e055de62 100644 |
| --- a/src/codec/SkCodec_libpng.cpp |
| +++ b/src/codec/SkCodec_libpng.cpp |
| @@ -429,6 +429,7 @@ 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) { |
| // FIXME: Could we use the return value of setjmp to specify the type of |
| // error? |
| @@ -464,7 +465,17 @@ SkCodec::Result SkPngCodec::initializeSwizzler(const SkImageInfo& requestedInfo, |
| } else { |
| fSrcConfig = SkSwizzler::kRGBA; |
| } |
| + |
| + // Copy the color table to the client if they request kIndex8 mode |
| const SkPMColor* colors = fColorTable ? fColorTable->readColors() : NULL; |
| + if (kIndex_8_SkColorType == requestedInfo.colorType()) { |
|
scroggo
2015/04/21 21:43:05
I think these same 5 lines are copied elsewhere. F
msarett
2015/04/22 14:32:52
Done.
|
| + SkASSERT(NULL != ctable); |
| + SkASSERT(NULL != ctableCount); |
| + SkASSERT(NULL != fColorTable); |
| + sk_memcpy32(ctable, colors, *ctableCount); |
| + } |
| + |
| + // Create the swizzler, SkPngCodec retains ownership of the color table |
|
scroggo
2015/04/21 21:43:05
nit: this seems like it should be two sentences.
msarett
2015/04/22 14:32:52
Done.
|
| fSwizzler.reset(SkSwizzler::CreateSwizzler(fSrcConfig, colors, requestedInfo, |
| dst, rowBytes, options.fZeroInitialized)); |
| if (!fSwizzler) { |
| @@ -520,17 +531,9 @@ SkCodec::Result SkPngCodec::onGetPixels(const SkImageInfo& requestedInfo, void* |
| return kInvalidConversion; |
| } |
| - // Note that ctableCount will be modified if there is a color table |
| + // Note that ctable and ctableCount may be modified if there is a color table |
| const Result result = this->initializeSwizzler(requestedInfo, dst, rowBytes, |
| - options, ctableCount); |
| - |
| - // Copy the color table to the client if necessary |
| - if (kIndex_8_SkColorType == requestedInfo.colorType()) { |
| - SkASSERT(NULL != ctable); |
| - SkASSERT(NULL != ctableCount); |
| - SkASSERT(NULL != fColorTable.get()); |
| - sk_memcpy32(ctable, fColorTable->readColors(), *ctableCount); |
| - } |
| + options, ctable, ctableCount); |
| if (result != kSuccess) { |
| return result; |
| @@ -648,7 +651,8 @@ private: |
| typedef SkScanlineDecoder INHERITED; |
| }; |
| -SkScanlineDecoder* SkPngCodec::onGetScanlineDecoder(const SkImageInfo& dstInfo) { |
| +SkScanlineDecoder* SkPngCodec::onGetScanlineDecoder(const SkImageInfo& dstInfo, |
| + const Options& options, SkPMColor ctable[], int* ctableCount) { |
| if (!this->handleRewind()) { |
| return NULL; |
| } |
| @@ -666,12 +670,8 @@ SkScanlineDecoder* SkPngCodec::onGetScanlineDecoder(const SkImageInfo& dstInfo) |
| // 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. |
| - Options opts; |
| - // FIXME: Pass this in to getScanlineDecoder? |
| - opts.fZeroInitialized = kNo_ZeroInitialized; |
| - // FIXME: onGetScanlineDecoder does not currently have a way to get color table information |
| - // for a kIndex8 decoder. |
| - if (this->initializeSwizzler(dstInfo, NULL, dstInfo.minRowBytes(), opts, NULL) != kSuccess) { |
| + if (this->initializeSwizzler(dstInfo, NULL, dstInfo.minRowBytes(), options, ctable, |
| + ctableCount) != kSuccess) { |
| SkCodecPrintf("failed to initialize the swizzler.\n"); |
| return NULL; |
| } |