| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 #ifndef SkScaledCodec_DEFINED | 7 #ifndef SkScaledCodec_DEFINED |
| 8 #define SkScaledCodec_DEFINED | 8 #define SkScaledCodec_DEFINED |
| 9 | 9 |
| 10 #include "SkCodec.h" | 10 #include "SkCodec.h" |
| 11 | 11 |
| 12 class SkStream; | 12 class SkStream; |
| 13 | 13 |
| 14 /** | 14 /** |
| 15 * This class implements scaling, by sampling scanlines in the y direction. | 15 * This class implements scaling, by sampling scanlines in the y direction. |
| 16 * x-wise sampling is implemented in the swizzler, when getScanlines() is called
. | 16 * x-wise sampling is implemented in the swizzler, when getScanlines() is called
. |
| 17 */ | 17 */ |
| 18 class SkScaledCodec : public SkCodec { | 18 class SkScaledCodec : public SkCodec { |
| 19 public: | 19 public: |
| 20 static SkCodec* NewFromStream(SkStream*); | 20 static SkCodec* NewFromStream(SkStream*); |
| 21 static SkCodec* NewFromData(SkData*); | 21 static SkCodec* NewFromData(SkData*); |
| 22 | 22 |
| 23 virtual ~SkScaledCodec(); | 23 virtual ~SkScaledCodec(); |
| 24 | 24 |
| 25 /** | 25 static void ComputeSampleSize(const SkISize& dstDim, const SkISize& srcDim, |
| 26 * returns whether a destination's dimensions are supported for down samplin
g | |
| 27 */ | |
| 28 static bool DimensionsSupportedForSampling(const SkImageInfo& srcInfo, | |
| 29 const SkImageInfo& dstInfo) { | |
| 30 // heights must be equal as no native y sampling is supported | |
| 31 if (dstInfo.height() != srcInfo.height()) { | |
| 32 return false; | |
| 33 } | |
| 34 // only support down sampling, dstWidth cannot be larger that srcWidth | |
| 35 if(dstInfo.width() > srcInfo.width()) { | |
| 36 return false; | |
| 37 } | |
| 38 return true; | |
| 39 } | |
| 40 | |
| 41 static void ComputeSampleSize(const SkImageInfo& dstInfo, const SkImageInfo&
srcInfo, | |
| 42 int* sampleSizeX, int* sampleSizeY); | 26 int* sampleSizeX, int* sampleSizeY); |
| 43 | 27 |
| 44 protected: | 28 protected: |
| 45 /** | 29 /** |
| 46 * Recommend a set of destination dimensions given a requested scale | 30 * Recommend a set of destination dimensions given a requested scale |
| 47 */ | 31 */ |
| 48 SkISize onGetScaledDimensions(float desiredScale) const override; | 32 SkISize onGetScaledDimensions(float desiredScale) const override; |
| 33 bool onDimensionsSupported(const SkISize&) override; |
| 49 | 34 |
| 50 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMCo
lor*, int*) | 35 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMCo
lor*, int*) |
| 51 override; | 36 override; |
| 52 SkEncodedFormat onGetEncodedFormat() const override { | 37 SkEncodedFormat onGetEncodedFormat() const override { |
| 53 return fCodec->getEncodedFormat(); | 38 return fCodec->getEncodedFormat(); |
| 54 } | 39 } |
| 55 | 40 |
| 56 bool onReallyHasAlpha() const override { | 41 bool onReallyHasAlpha() const override { |
| 57 return fCodec->reallyHasAlpha(); | 42 return fCodec->reallyHasAlpha(); |
| 58 } | 43 } |
| 59 | 44 |
| 60 private: | 45 private: |
| 61 | 46 |
| 62 SkAutoTDelete<SkCodec> fCodec; | 47 SkAutoTDelete<SkCodec> fCodec; |
| 63 | 48 |
| 64 explicit SkScaledCodec(SkCodec*); | 49 explicit SkScaledCodec(SkCodec*); |
| 65 | 50 |
| 66 typedef SkCodec INHERITED; | 51 typedef SkCodec INHERITED; |
| 67 }; | 52 }; |
| 68 #endif // SkScaledCodec_DEFINED | 53 #endif // SkScaledCodec_DEFINED |
| OLD | NEW |