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 28 matching lines...) Expand all Loading... |
39 /** | 39 /** |
40 * Clean up after reading/skipping scanlines. | 40 * Clean up after reading/skipping scanlines. |
41 * | 41 * |
42 * It is possible that not all scanlines will have been read/skipped. In | 42 * It is possible that not all scanlines will have been read/skipped. In |
43 * fact, in the case of subset decodes, it is likely that there will be | 43 * fact, in the case of subset decodes, it is likely that there will be |
44 * scanlines at the bottom of the image that have been ignored. | 44 * scanlines at the bottom of the image that have been ignored. |
45 */ | 45 */ |
46 virtual ~SkScanlineDecoder() {} | 46 virtual ~SkScanlineDecoder() {} |
47 | 47 |
48 /** | 48 /** |
| 49 * Return a size that approximately supports the desired scale factor. |
| 50 * The codec may not be able to scale efficiently to the exact scale |
| 51 * factor requested, so return a size that approximates that scale. |
| 52 * The returned value is the codec's suggestion for the closest valid |
| 53 * scale that it can natively support |
| 54 * FIXME: share this with SkCodec |
| 55 */ |
| 56 SkISize getScaledDimensions(float desiredScale) { |
| 57 return this->onGetScaledDimensions(desiredScale); |
| 58 } |
| 59 |
| 60 /** |
49 * Returns the default info, corresponding to the encoded data. | 61 * Returns the default info, corresponding to the encoded data. |
50 */ | 62 */ |
51 const SkImageInfo& getInfo() { return fSrcInfo; } | 63 const SkImageInfo& getInfo() { return fSrcInfo; } |
52 | 64 |
53 /** | 65 /** |
54 * Initialize on the first scanline, with the specified options. | 66 * Initialize on the first scanline, with the specified options. |
55 * | 67 * |
56 * This must be called in order to call getScanlnies or skipScanlines. If | 68 * This must be called in order to call getScanlnies or skipScanlines. If |
57 * it has been called before, this will require rewinding the stream. | 69 * it has been called before, this will require rewinding the stream. |
58 * | 70 * |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 * of the encoded data, but then never use any colors which have alpha | 140 * of the encoded data, but then never use any colors which have alpha |
129 * less than 100%. This function can be called *after* decoding to | 141 * less than 100%. This function can be called *after* decoding to |
130 * determine if such an image truly had alpha. Calling it before decoding | 142 * determine if such an image truly had alpha. Calling it before decoding |
131 * is undefined. | 143 * is undefined. |
132 * FIXME: see skbug.com/3582. | 144 * FIXME: see skbug.com/3582. |
133 */ | 145 */ |
134 bool reallyHasAlpha() const { | 146 bool reallyHasAlpha() const { |
135 return this->onReallyHasAlpha(); | 147 return this->onReallyHasAlpha(); |
136 } | 148 } |
137 | 149 |
| 150 /** |
| 151 * Format of the encoded data. |
| 152 */ |
| 153 SkEncodedFormat getEncodedFormat() const { return this->onGetEncodedFormat()
; } |
| 154 |
| 155 /** |
| 156 * returns true if the image must be scaled, in the y direction, after readi
ng, not during. |
| 157 * To scale afterwards, we first decode every line and then sample the lines
we want afterwards. |
| 158 * An example is interlaced pngs, where calling getScanlines once (regardles
s of the count |
| 159 * used) needs to read the entire image, therefore it is inefficient to call |
| 160 * getScanlines more than once. Instead, it should only ever be called with
all the |
| 161 * rows needed. |
| 162 */ |
| 163 bool requiresPostYSampling() { |
| 164 return this->onRequiresPostYSampling(); |
| 165 } |
| 166 |
138 protected: | 167 protected: |
139 SkScanlineDecoder(const SkImageInfo& srcInfo) | 168 SkScanlineDecoder(const SkImageInfo& srcInfo) |
140 : fSrcInfo(srcInfo) | 169 : fSrcInfo(srcInfo) |
141 , fDstInfo() | 170 , fDstInfo() |
142 , fCurrScanline(0) {} | 171 , fCurrScanline(0) {} |
143 | 172 |
| 173 virtual SkISize onGetScaledDimensions(float /* desiredScale */) { |
| 174 // By default, scaling is not supported. |
| 175 return this->getInfo().dimensions(); |
| 176 } |
| 177 |
| 178 virtual SkEncodedFormat onGetEncodedFormat() const = 0; |
| 179 |
144 virtual bool onReallyHasAlpha() const { return false; } | 180 virtual bool onReallyHasAlpha() const { return false; } |
145 | 181 |
| 182 /** |
| 183 * returns true if the image type is hard to sample and must be scaled after
reading, not during |
| 184 * An example is interlaced pngs, where the entire image must be read for ea
ch decode |
| 185 */ |
| 186 virtual bool onRequiresPostYSampling() { return false; } |
| 187 |
146 const SkImageInfo& dstInfo() const { return fDstInfo; } | 188 const SkImageInfo& dstInfo() const { return fDstInfo; } |
147 | 189 |
148 private: | 190 private: |
149 const SkImageInfo fSrcInfo; | 191 const SkImageInfo fSrcInfo; |
150 SkImageInfo fDstInfo; | 192 SkImageInfo fDstInfo; |
151 int fCurrScanline; | 193 int fCurrScanline; |
152 | 194 |
153 virtual SkCodec::Result onStart(const SkImageInfo& dstInfo, | 195 virtual SkCodec::Result onStart(const SkImageInfo& dstInfo, |
154 const SkCodec::Options& options, | 196 const SkCodec::Options& options, |
155 SkPMColor ctable[], int* ctableCount) = 0; | 197 SkPMColor ctable[], int* ctableCount) = 0; |
156 | 198 |
157 // Naive default version just calls onGetScanlines on temp memory. | 199 // Naive default version just calls onGetScanlines on temp memory. |
158 virtual SkCodec::Result onSkipScanlines(int countLines) { | 200 virtual SkCodec::Result onSkipScanlines(int countLines) { |
159 SkAutoMalloc storage(fDstInfo.minRowBytes()); | 201 SkAutoMalloc storage(fDstInfo.minRowBytes()); |
160 // Note that we pass 0 to rowBytes so we continue to use the same memory
. | 202 // Note that we pass 0 to rowBytes so we continue to use the same memory
. |
161 // Also note that while getScanlines checks that rowBytes is big enough, | 203 // Also note that while getScanlines checks that rowBytes is big enough, |
162 // onGetScanlines bypasses that check. | 204 // onGetScanlines bypasses that check. |
163 // Calling the virtual method also means we do not double count | 205 // Calling the virtual method also means we do not double count |
164 // countLines. | 206 // countLines. |
165 return this->onGetScanlines(storage.get(), countLines, 0); | 207 return this->onGetScanlines(storage.get(), countLines, 0); |
166 } | 208 } |
167 | 209 |
168 virtual SkCodec::Result onGetScanlines(void* dst, int countLines, | 210 virtual SkCodec::Result onGetScanlines(void* dst, int countLines, |
169 size_t rowBytes) = 0; | 211 size_t rowBytes) = 0; |
170 | 212 |
171 }; | 213 }; |
172 #endif // SkScanlineDecoder_DEFINED | 214 #endif // SkScanlineDecoder_DEFINED |
OLD | NEW |