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 | 7 |
8 #ifndef SkScanlineDecoder_DEFINED | 8 #ifndef SkScanlineDecoder_DEFINED |
9 #define SkScanlineDecoder_DEFINED | 9 #define SkScanlineDecoder_DEFINED |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... | |
28 * Write the next countLines scanlines into dst. | 28 * Write the next countLines scanlines into dst. |
29 * | 29 * |
30 * @param dst Must be non-null, and large enough to hold countLines | 30 * @param dst Must be non-null, and large enough to hold countLines |
31 * scanlines of size rowBytes. | 31 * scanlines of size rowBytes. |
32 * @param countLines Number of lines to write. | 32 * @param countLines Number of lines to write. |
33 * @param rowBytes Number of bytes per row. Must be large enough to hold | 33 * @param rowBytes Number of bytes per row. Must be large enough to hold |
34 * a scanline based on the SkImageInfo used to create this object. | 34 * a scanline based on the SkImageInfo used to create this object. |
35 */ | 35 */ |
36 SkCodec::Result getScanlines(void* dst, int countLines, size_t rowBytes) { | 36 SkCodec::Result getScanlines(void* dst, int countLines, size_t rowBytes) { |
37 if ((rowBytes < fDstInfo.minRowBytes() && countLines > 1 ) || countLines <= 0 | 37 if ((rowBytes < fDstInfo.minRowBytes() && countLines > 1 ) || countLines <= 0 |
38 || fCurrScanline + countLines > fDstInfo.height()) { | 38 || fCurrScanline + countLines > fSrcInfo.height()) { |
39 return SkCodec::kInvalidParameters; | 39 return SkCodec::kInvalidParameters; |
40 } | 40 } |
41 const SkCodec::Result result = this->onGetScanlines(dst, countLines, row Bytes); | 41 const SkCodec::Result result = this->onGetScanlines(dst, countLines, row Bytes); |
42 fCurrScanline += countLines; | 42 fCurrScanline += countLines; |
43 return result; | 43 return result; |
44 } | 44 } |
45 | 45 |
46 /** | 46 /** |
47 * Skip count scanlines. | 47 * Skip count scanlines. |
48 * | 48 * |
49 * The default version just calls onGetScanlines and discards the dst. | 49 * The default version just calls onGetScanlines and discards the dst. |
50 * NOTE: If skipped lines are the only lines with alpha, this default | 50 * NOTE: If skipped lines are the only lines with alpha, this default |
51 * will make reallyHasAlpha return true, when it could have returned | 51 * will make reallyHasAlpha return true, when it could have returned |
52 * false. | 52 * false. |
53 */ | 53 */ |
54 SkCodec::Result skipScanlines(int countLines) { | 54 SkCodec::Result skipScanlines(int countLines) { |
55 if (fCurrScanline + countLines > fDstInfo.height()) { | 55 if (fCurrScanline + countLines > fSrcInfo.height()) { |
56 // Arguably, we could just skip the scanlines which are remaining, | 56 // Arguably, we could just skip the scanlines which are remaining, |
57 // and return kSuccess. We choose to return invalid so the client | 57 // and return kSuccess. We choose to return invalid so the client |
58 // can catch their bug. | 58 // can catch their bug. |
59 return SkCodec::kInvalidParameters; | 59 return SkCodec::kInvalidParameters; |
60 } | 60 } |
61 const SkCodec::Result result = this->onSkipScanlines(countLines); | 61 const SkCodec::Result result = this->onSkipScanlines(countLines); |
62 fCurrScanline += countLines; | 62 fCurrScanline += countLines; |
63 return result; | 63 return result; |
64 } | 64 } |
65 | 65 |
66 /** | 66 /** |
67 * Some images may initially report that they have alpha due to the format | 67 * Some images may initially report that they have alpha due to the format |
68 * of the encoded data, but then never use any colors which have alpha | 68 * of the encoded data, but then never use any colors which have alpha |
69 * less than 100%. This function can be called *after* decoding to | 69 * less than 100%. This function can be called *after* decoding to |
70 * determine if such an image truly had alpha. Calling it before decoding | 70 * determine if such an image truly had alpha. Calling it before decoding |
71 * is undefined. | 71 * is undefined. |
72 * FIXME: see skbug.com/3582. | 72 * FIXME: see skbug.com/3582. |
73 */ | 73 */ |
74 bool reallyHasAlpha() const { | 74 bool reallyHasAlpha() const { |
75 return this->onReallyHasAlpha(); | 75 return this->onReallyHasAlpha(); |
76 } | 76 } |
77 | 77 |
78 /** | |
79 * set the sample size in the x direction | |
80 * returns true if successful | |
scroggo
2015/07/27 19:29:57
Returns whether sampleX is supported.
| |
81 * returns false if failed | |
82 */ | |
83 bool setSampleX(int sampleX) { | |
84 return this->onSetSampleX(sampleX); | |
85 } | |
86 | |
78 protected: | 87 protected: |
79 SkScanlineDecoder(const SkImageInfo& requested) | 88 SkScanlineDecoder(const SkImageInfo& requested, const SkImageInfo& src) |
80 : fDstInfo(requested) | 89 : fDstInfo(requested) |
81 , fCurrScanline(0) {} | 90 , fCurrScanline(0) |
91 , fSrcInfo(src) {} | |
82 | 92 |
83 virtual bool onReallyHasAlpha() const { return false; } | 93 virtual bool onReallyHasAlpha() const { return false; } |
84 | 94 |
95 virtual bool onSetSampleX(int SampleX){ return false; } | |
96 | |
85 const SkImageInfo& dstInfo() const { return fDstInfo; } | 97 const SkImageInfo& dstInfo() const { return fDstInfo; } |
86 | 98 |
87 private: | 99 private: |
88 const SkImageInfo fDstInfo; | 100 const SkImageInfo fDstInfo; |
89 int fCurrScanline; | 101 int fCurrScanline; |
102 const SkImageInfo fSrcInfo; | |
90 | 103 |
91 // Naive default version just calls onGetScanlines on temp memory. | 104 // Naive default version just calls onGetScanlines on temp memory. |
92 virtual SkCodec::Result onSkipScanlines(int countLines) { | 105 virtual SkCodec::Result onSkipScanlines(int countLines) { |
93 SkAutoMalloc storage(fDstInfo.minRowBytes()); | 106 SkAutoMalloc storage(fDstInfo.minRowBytes()); |
94 // Note that we pass 0 to rowBytes so we continue to use the same memory . | 107 // Note that we pass 0 to rowBytes so we continue to use the same memory . |
95 // Also note that while getScanlines checks that rowBytes is big enough, | 108 // Also note that while getScanlines checks that rowBytes is big enough, |
96 // onGetScanlines bypasses that check. | 109 // onGetScanlines bypasses that check. |
97 // Calling the virtual method also means we do not double count | 110 // Calling the virtual method also means we do not double count |
98 // countLines. | 111 // countLines. |
99 return this->onGetScanlines(storage.get(), countLines, 0); | 112 return this->onGetScanlines(storage.get(), countLines, 0); |
100 } | 113 } |
101 | 114 |
102 virtual SkCodec::Result onGetScanlines(void* dst, int countLines, | 115 virtual SkCodec::Result onGetScanlines(void* dst, int countLines, |
103 size_t rowBytes) = 0; | 116 size_t rowBytes) = 0; |
104 | 117 |
105 }; | 118 }; |
106 #endif // SkScanlineDecoder_DEFINED | 119 #endif // SkScanlineDecoder_DEFINED |
OLD | NEW |