8f4ba76742
This class does scaling by using a scanlineDecoder. getScanlines and skipScanlines are used for y sampling, the swizzler is used for x sampling this class is currently only working for png and jpeg images I will update other Codec types to work soon For SkJpegCodec to implement width wise swizzling it now uses a swizzler. I ran performance tests on this change. Here are the performance test results: https://docs.google.com/a/google.com/spreadsheets/d/1D7-Q_GXD_dI68LZO005NNvb8Wq2Ee0wEBEPG72671yw/edit?usp=sharing BUG=skia: Committed: https://skia.googlesource.com/skia/+/0944100ac89f797714eeae0cf2875e2335ff52ee Committed: https://skia.googlesource.com/skia/+/d518ea7927f9f4e0ed5b4134d1b4f48243855a47 Committed: https://skia.googlesource.com/skia/+/b157917507d4f7d2651f0aeb566d31603cc02240 Review URL: https://codereview.chromium.org/1260673002
71 lines
2.0 KiB
C++
71 lines
2.0 KiB
C++
/*
|
|
* 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;
|
|
|
|
/**
|
|
* This class implements scaling, by sampling scanlines in the y direction.
|
|
* x-wise sampling is implemented in the swizzler, when getScanlines() is called.
|
|
*/
|
|
class SkScaledCodec : public SkCodec {
|
|
public:
|
|
static SkCodec* NewFromStream(SkStream*);
|
|
static SkCodec* NewFromData(SkData*);
|
|
|
|
virtual ~SkScaledCodec();
|
|
|
|
/**
|
|
* returns whether a destination's dimensions are supported for down sampling
|
|
*/
|
|
static bool DimensionsSupportedForSampling(const SkImageInfo& srcInfo,
|
|
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;
|
|
}
|
|
|
|
static void ComputeSampleSize(const SkImageInfo& dstInfo, const SkImageInfo& srcInfo,
|
|
int* sampleSizeX, int* sampleSizeY);
|
|
|
|
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 {
|
|
return fScanlineDecoder->getEncodedFormat();
|
|
}
|
|
|
|
bool onReallyHasAlpha() const override {
|
|
return fScanlineDecoder->reallyHasAlpha();
|
|
}
|
|
|
|
private:
|
|
|
|
SkAutoTDelete<SkScanlineDecoder> fScanlineDecoder;
|
|
|
|
explicit SkScaledCodec(SkScanlineDecoder*);
|
|
|
|
typedef SkCodec INHERITED;
|
|
};
|
|
#endif // SkScaledCodec_DEFINED
|