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 * This does not need to be called and is not called when sampleFactor == 1. | |
48 */ | |
49 static int GetStartCoord(int sampleFactor) { return sampleFactor / 2 }; | |
msarett
2015/08/28 15:09:18
It occurs to me that maybe we don't want these imp
| |
50 | |
51 /* | |
52 * Given a coordinate in the original image, this returns the corresponding | |
53 * coordinate in the scaled image. This function is meaningless if | |
54 * IsCoordNecessary returns false. | |
55 * The output can be interpreted as an x-coordinate or a y-coordinate. | |
56 * | |
57 * This does not need to be called and is not called when sampleFactor == 1. | |
58 */ | |
59 static int GetDstCoord(int srcCoord, int sampleFactor) { return srcCoord / s ampleFactor; } | |
60 | |
61 /* | |
62 * When sampling, we will discard certain y-coordinates (rows) and | |
63 * x-coordinates (columns). This function returns true if we should keep th e | |
64 * coordinate and false otherwise. | |
65 * The inputs may be x-coordinates or y-coordinates. | |
66 * | |
67 * This does not need to be called and is not called when sampleFactor == 1. | |
68 */ | |
69 static bool IsCoordNecessary(int srcCoord, int sampleFactor, int scaledDim); | |
70 | |
43 static void ComputeSampleSize(const SkImageInfo& dstInfo, const SkImageInfo& srcInfo, | 71 static void ComputeSampleSize(const SkImageInfo& dstInfo, const SkImageInfo& srcInfo, |
44 int* sampleSizeX, int* sampleSizeY); | 72 int* sampleSizeX, int* sampleSizeY); |
45 | 73 |
46 protected: | 74 protected: |
47 /** | 75 /** |
48 * Recommend a set of destination dimensions given a requested scale | 76 * Recommend a set of destination dimensions given a requested scale |
49 */ | 77 */ |
50 SkISize onGetScaledDimensions(float desiredScale) const override; | 78 SkISize onGetScaledDimensions(float desiredScale) const override; |
51 | 79 |
52 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMCo lor*, int*) | 80 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMCo lor*, int*) |
53 override; | 81 override; |
54 SkEncodedFormat onGetEncodedFormat() const override { | 82 SkEncodedFormat onGetEncodedFormat() const override { |
55 return fScanlineDecoder->getEncodedFormat(); | 83 return fScanlineDecoder->getEncodedFormat(); |
56 } | 84 } |
57 | 85 |
58 bool onReallyHasAlpha() const override { | 86 bool onReallyHasAlpha() const override { |
59 return fScanlineDecoder->reallyHasAlpha(); | 87 return fScanlineDecoder->reallyHasAlpha(); |
60 } | 88 } |
61 | 89 |
62 private: | 90 private: |
63 | 91 |
64 SkAutoTDelete<SkScanlineDecoder> fScanlineDecoder; | 92 SkAutoTDelete<SkScanlineDecoder> fScanlineDecoder; |
65 | 93 |
66 explicit SkScaledCodec(SkScanlineDecoder*); | 94 explicit SkScaledCodec(SkScanlineDecoder*); |
67 | 95 |
68 typedef SkCodec INHERITED; | 96 typedef SkCodec INHERITED; |
69 }; | 97 }; |
70 #endif // SkScaledCodec_DEFINED | 98 #endif // SkScaledCodec_DEFINED |
OLD | NEW |