Chromium Code Reviews| Index: include/codec/SkScaledCodec.h |
| diff --git a/include/codec/SkScaledCodec.h b/include/codec/SkScaledCodec.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ba91af4846acec871327e7ebc580362b3b952b3d |
| --- /dev/null |
| +++ b/include/codec/SkScaledCodec.h |
| @@ -0,0 +1,69 @@ |
| +/* |
| + * Copyright 2015 Google Inc. |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| +#ifndef SkScaledCodec_DEFINED |
| +#define SkScaledCodec_DEFINED |
| + |
| +#include "SkCodec.h" |
| +#include "SkScanlineDecoder.h" |
| + |
| +class SkScanlineDecoder; |
| +class SkStream; |
| + |
| +class SkScaledCodec : public SkCodec { |
|
djsollen
2015/08/03 13:13:59
comment as to the purpose of this class.
emmaleer
2015/08/03 14:29:41
Acknowledged.
|
| +public: |
| + static SkCodec* NewFromStream(SkStream*); |
| + static SkCodec* NewFromData(SkData*); |
| + |
| + virtual ~SkScaledCodec(); |
| + |
| + // returns a sample size based on the input src and dst dimensions |
| + // can only down sample, so dstDimension must be <= than srcDimension |
| + static int GetSampleSize(int srcDimension, int dstDimension) { |
|
djsollen
2015/08/03 13:13:59
make this a block comment in doxygen style.
emmaleer
2015/08/03 14:29:41
Acknowledged.
|
| + SkASSERT(dstDimension <= srcDimension); |
| + return srcDimension / dstDimension; |
| + } |
| + |
| + static bool DimensionsSupportedForSampling(const SkImageInfo& srcInfo, |
|
djsollen
2015/08/03 13:13:59
comment?
emmaleer
2015/08/03 14:29:41
Acknowledged.
|
| + const SkImageInfo& dstInfo) { |
| + // heights must be equal as no native y sampling is supported |
| + if (dstInfo.height() != srcInfo.height()) { |
| + return false; |
| + } |
| + // only support down sampling, dstWidth cannot be larger that srcWidth |
| + if(dstInfo.width() > srcInfo.width()) { |
| + return false; |
| + } |
| + return true; |
| + } |
| + |
| +protected: |
| + // Recommend a set of destination dimensions given a requested scale |
| + SkISize onGetScaledDimensions(float desiredScale) const override; |
| + |
| + Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMColor*, int*) |
| + override; |
| + SkEncodedFormat onGetEncodedFormat() const override{ |
|
djsollen
2015/08/03 13:13:59
"override {"
emmaleer
2015/08/03 14:29:41
Acknowledged.
|
| + return fCodec->getEncodedFormat(); |
| + } |
| + |
| + SkScanlineDecoder* onGetScanlineDecoder(const SkImageInfo& dstInfo, const Options& options, |
| + SkPMColor ctable[], int* ctableCount) override { |
| + return fCodec->getScanlineDecoder(dstInfo, &options, ctable, ctableCount); |
| + } |
| + |
| + bool onReallyHasAlpha() const override{ |
|
djsollen
2015/08/03 13:13:59
"override {"
emmaleer
2015/08/03 14:29:41
Acknowledged.
|
| + return fCodec->reallyHasAlpha(); |
| + } |
| + |
| +private: |
| + SkAutoTDelete<SkCodec> fCodec; |
|
djsollen
2015/08/03 13:13:59
spacing
emmaleer
2015/08/03 14:29:41
Acknowledged.
|
| + |
| + SkScaledCodec(SkCodec*); |
| + |
| + typedef SkCodec INHERITED; |
| +}; |
| +#endif // SkScaledCodec_DEFINED |