| 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" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 if (dstInfo.height() != srcInfo.height()) { | 33 if (dstInfo.height() != srcInfo.height()) { |
| 34 return false; | 34 return false; |
| 35 } | 35 } |
| 36 // only support down sampling, dstWidth cannot be larger that srcWidth | 36 // only support down sampling, dstWidth cannot be larger that srcWidth |
| 37 if(dstInfo.width() > srcInfo.width()) { | 37 if(dstInfo.width() > srcInfo.width()) { |
| 38 return false; | 38 return false; |
| 39 } | 39 } |
| 40 return true; | 40 return true; |
| 41 } | 41 } |
| 42 | 42 |
| 43 /* |
| 44 * Returns the first coordinate that we will keep during sampling. |
| 45 * The output can be interpreted as an x-coordinate or a y-coordinate. |
| 46 */ |
| 47 static inline int GetStartCoord(int sampleFactor); |
| 48 |
| 49 /* |
| 50 * Given a coordinate in the original image, this returns the corresponding |
| 51 * coordinate in the scaled image. This function is meaningless if |
| 52 * IsCoordNecessary returns false. |
| 53 * The output can be interpreted as an x-coordinate or a y-coordinate. |
| 54 */ |
| 55 static inline int GetDstCoord(int srcCoord, int sampleFactor); |
| 56 |
| 57 /* |
| 58 * When sampling, we will discard certain y-coordinates (rows) and |
| 59 * x-coordinates (columns). This function returns true if we should keep th
e |
| 60 * coordinate and false otherwise. |
| 61 * The inputs may be x-coordinates or y-coordinates. |
| 62 */ |
| 63 static bool IsCoordNecessary(int srcCoord, int sampleFactor, int scaledDim); |
| 64 |
| 43 static void ComputeSampleSize(const SkImageInfo& dstInfo, const SkImageInfo&
srcInfo, | 65 static void ComputeSampleSize(const SkImageInfo& dstInfo, const SkImageInfo&
srcInfo, |
| 44 int* sampleSizeX, int* sampleSizeY); | 66 int* sampleSizeX, int* sampleSizeY); |
| 45 | 67 |
| 46 protected: | 68 protected: |
| 47 /** | 69 /** |
| 48 * Recommend a set of destination dimensions given a requested scale | 70 * Recommend a set of destination dimensions given a requested scale |
| 49 */ | 71 */ |
| 50 SkISize onGetScaledDimensions(float desiredScale) const override; | 72 SkISize onGetScaledDimensions(float desiredScale) const override; |
| 51 | 73 |
| 52 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMCo
lor*, int*) | 74 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMCo
lor*, int*) |
| 53 override; | 75 override; |
| 54 SkEncodedFormat onGetEncodedFormat() const override { | 76 SkEncodedFormat onGetEncodedFormat() const override { |
| 55 return fScanlineDecoder->getEncodedFormat(); | 77 return fScanlineDecoder->getEncodedFormat(); |
| 56 } | 78 } |
| 57 | 79 |
| 58 bool onReallyHasAlpha() const override { | 80 bool onReallyHasAlpha() const override { |
| 59 return fScanlineDecoder->reallyHasAlpha(); | 81 return fScanlineDecoder->reallyHasAlpha(); |
| 60 } | 82 } |
| 61 | 83 |
| 62 private: | 84 private: |
| 63 | 85 |
| 64 SkAutoTDelete<SkScanlineDecoder> fScanlineDecoder; | 86 SkAutoTDelete<SkScanlineDecoder> fScanlineDecoder; |
| 65 | 87 |
| 66 explicit SkScaledCodec(SkScanlineDecoder*); | 88 explicit SkScaledCodec(SkScanlineDecoder*); |
| 67 | 89 |
| 68 typedef SkCodec INHERITED; | 90 typedef SkCodec INHERITED; |
| 69 }; | 91 }; |
| 70 #endif // SkScaledCodec_DEFINED | 92 #endif // SkScaledCodec_DEFINED |
| OLD | NEW |