Index: src/codec/SkJpegCodec.cpp |
diff --git a/src/codec/SkJpegCodec.cpp b/src/codec/SkJpegCodec.cpp |
index 84e90d444249142d69a68cd52cab59cebb37c30a..ed58f65f50044a4b96c423db993210a1e8b7e0e1 100644 |
--- a/src/codec/SkJpegCodec.cpp |
+++ b/src/codec/SkJpegCodec.cpp |
@@ -11,6 +11,7 @@ |
#include "SkJpegUtility_codec.h" |
#include "SkCodecPriv.h" |
#include "SkColorPriv.h" |
+#include "SkScaledCodec.h" |
#include "SkScanlineDecoder.h" |
#include "SkStream.h" |
#include "SkTemplates.h" |
@@ -189,6 +190,41 @@ SkISize SkJpegCodec::onGetScaledDimensions(float desiredScale) const { |
return SkISize::Make(dinfo.output_width, dinfo.output_height); |
} |
+SkCodec::Result SkJpegCodec::initializeSwizzler(const SkImageInfo& requestedInfo, |
scroggo
2015/07/31 19:31:58
It looks like the swizzler is never used in getPix
emmaleer
2015/07/31 20:43:10
Acknowledged.
|
+ void* dst, size_t rowBytes, |
+ const Options& options, |
+ SkPMColor ctable[], |
+ int* ctableCount) { |
+ |
+ const SkColorType srcColorType = requestedInfo.colorType(); |
+ SkSwizzler::SrcConfig srcConfig; |
+ switch (srcColorType) { |
+ case kGray_8_SkColorType: |
+ srcConfig = SkSwizzler::kGray; |
+ break; |
+ case kRGBA_8888_SkColorType: |
+ srcConfig = SkSwizzler::kRGBX; |
+ break; |
+ case kBGRA_8888_SkColorType: |
+ srcConfig = SkSwizzler::kBGRX; |
+ break; |
+ case kRGB_565_SkColorType: |
+ srcConfig = SkSwizzler::kRGB_565; |
+ break; |
+ default: |
+ //would have exited before now if the colorType was supported by jpeg |
+ SkASSERT(false); |
+ } |
+ |
+ fSwizzler.reset(SkSwizzler::CreateSwizzler(srcConfig, NULL, requestedInfo, |
+ options.fZeroInitialized, this->getInfo().width())); |
+ if (!fSwizzler) { |
+ // FIXME: CreateSwizzler could fail for another reason. |
+ return kUnimplemented; |
+ } |
+ return kSuccess; |
+} |
+ |
/* |
* Handles rewinding the input stream if it is necessary |
*/ |
@@ -287,6 +323,9 @@ bool SkJpegCodec::scaleToDimensions(uint32_t dstWidth, uint32_t dstHeight) { |
if (1 == fDecoderMgr->dinfo()->scale_num || |
dstWidth > fDecoderMgr->dinfo()->output_width || |
dstHeight > fDecoderMgr->dinfo()->output_height) { |
+ // reset scale settings on failure |
scroggo
2015/07/31 19:31:58
Can you explain why? "because this may be supporte
emmaleer
2015/07/31 20:43:10
Acknowledged.
|
+ this->fDecoderMgr->dinfo()->scale_num = 8; |
+ turbo_jpeg_calc_output_dimensions(this->fDecoderMgr->dinfo()); |
return fDecoderMgr->returnFalse("could not scale to requested dimensions"); |
scroggo
2015/07/31 19:31:58
I wonder if this error message is necessary now th
emmaleer
2015/07/31 20:43:09
I removed the error. I think it's okay for the fun
scroggo
2015/07/31 21:11:57
Agreed for your case, although we should perhaps m
emmaleer
2015/08/03 14:29:41
If the function fails onGetPixels already returns:
scroggo
2015/08/03 17:02:55
Ok, great, so this is fine to remove.
|
} |
@@ -394,7 +433,12 @@ public: |
: INHERITED(dstInfo) |
, fCodec(codec) |
, fOpts(opts) |
- {} |
+ { |
+ if(fCodec->fSwizzler) { |
+ fStorage.reset(fCodec->getInfo().width() * dstInfo.minRowBytes()); |
+ fSrcRow = static_cast<uint8_t*>(fStorage.get()); |
+ } |
+ } |
virtual ~SkJpegScanlineDecoder() { |
if (setjmp(fCodec->fDecoderMgr->getJmpBuf())) { |
@@ -413,9 +457,16 @@ public: |
if (setjmp(fCodec->fDecoderMgr->getJmpBuf())) { |
return fCodec->fDecoderMgr->returnFailure("setjmp", SkCodec::kInvalidInput); |
} |
- |
// Read rows one at a time |
- JSAMPLE* dstRow = (JSAMPLE*) dst; |
+ JSAMPLE* dstRow; |
+ if (fCodec->fSwizzler) { |
+ // write data to storage row, then sample using swizzler |
+ dstRow = fSrcRow; |
+ } else { |
+ // write data directly to dst |
+ dstRow = (JSAMPLE*) dst; |
+ } |
+ |
for (int y = 0; y < count; y++) { |
// Read row of the image |
uint32_t rowsDecoded = |
@@ -435,10 +486,14 @@ public: |
convert_CMYK_to_RGBA(dstRow, this->dstInfo().width()); |
} |
- // Move to the next row |
- dstRow = SkTAddOffset<JSAMPLE>(dstRow, rowBytes); |
+ if(fCodec->fSwizzler) { |
+ // use swizzler to sample row |
+ fCodec->fSwizzler->swizzle(dst, dstRow); |
+ dst = SkTAddOffset<JSAMPLE>(dst, rowBytes); |
+ } else { |
+ dstRow = SkTAddOffset<JSAMPLE>(dstRow, rowBytes); |
+ } |
} |
- |
return SkCodec::kSuccess; |
} |
@@ -464,6 +519,8 @@ public: |
private: |
SkAutoTDelete<SkJpegCodec> fCodec; |
+ SkAutoMalloc fStorage; // Only used if sampling is needed |
+ uint8_t* fSrcRow; // Only used if sampling is needed |
const SkCodec::Options& fOpts; |
typedef SkScanlineDecoder INHERITED; |
@@ -501,8 +558,17 @@ SkScanlineDecoder* SkJpegCodec::onGetScanlineDecoder(const SkImageInfo& dstInfo, |
// Perform the necessary scaling |
if (!codec->scaleToDimensions(dstInfo.width(), dstInfo.height())) { |
- SkCodecPrintf("Cannot scale to output dimensions\n"); |
- return NULL; |
+ // native scaling to dstInfo dimensions not supported |
+ |
+ if (!SkScaledCodec::DimensionsSupportedForSampling(this->getInfo(), dstInfo)) { |
+ return NULL; |
+ } |
+ // create swizzler for sampling |
+ if (codec->initializeSwizzler(dstInfo, NULL, dstInfo.minRowBytes(), options, ctable, |
+ ctableCount) != kSuccess) { |
+ SkCodecPrintf("failed to initialize the swizzler.\n"); |
+ return NULL; |
+ } |
} |
// Now, given valid output dimensions, we can start the decompress |