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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 bool reallyHasAlpha() const { | 146 bool reallyHasAlpha() const { |
147 return this->onReallyHasAlpha(); | 147 return this->onReallyHasAlpha(); |
148 } | 148 } |
149 | 149 |
150 /** | 150 /** |
151 * Format of the encoded data. | 151 * Format of the encoded data. |
152 */ | 152 */ |
153 SkEncodedFormat getEncodedFormat() const { return this->onGetEncodedFormat()
; } | 153 SkEncodedFormat getEncodedFormat() const { return this->onGetEncodedFormat()
; } |
154 | 154 |
155 /** | 155 /** |
156 * returns true if the image must be scaled, in the y direction, after readi
ng, not during. | 156 * The order in which rows are output from the scanline decoder is not the |
157 * To scale afterwards, we first decode every line and then sample the lines
we want afterwards. | 157 * same for all variations of all image types. This explains the possible |
158 * An example is interlaced pngs, where calling getScanlines once (regardles
s of the count | 158 * output row orderings. |
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 */ | 159 */ |
163 bool requiresPostYSampling() { | 160 enum SkScanlineOrder { |
164 return this->onRequiresPostYSampling(); | 161 /* |
| 162 * By far the most common, this indicates that the image can be decoded |
| 163 * reliably using the scanline decoder, and that rows will be output in |
| 164 * the logical order. |
| 165 */ |
| 166 kTopDown_SkScanlineOrder, |
| 167 |
| 168 /* |
| 169 * This indicates that the scanline decoder reliably outputs rows, but |
| 170 * they will be returned in reverse order. If the scanline format is |
| 171 * kBottomUp, the getY() API can be used to determine the actual |
| 172 * y-coordinate of the next output row, but the client is not forced |
| 173 * to take advantage of this, given that it's not too tough to keep |
| 174 * track independently. |
| 175 * |
| 176 * For full image decodes, it is safe to get all of the scanlines at |
| 177 * once, since the decoder will handle inverting the rows as it |
| 178 * decodes. |
| 179 * |
| 180 * For subset decodes and sampling, it is simplest to get and skip |
| 181 * scanlines one at a time, using the getY() API. It is possible to |
| 182 * ask for larger chunks at a time, but this should be used with |
| 183 * caution. As with full image decodes, the decoder will handle |
| 184 * inverting the requested rows, but rows will still be delivered |
| 185 * starting from the bottom of the image. |
| 186 * |
| 187 * Upside down bmps are an example. |
| 188 */ |
| 189 kBottomUp_SkScanlineOrder, |
| 190 |
| 191 /* |
| 192 * This indicates that the scanline decoder reliably outputs rows, but |
| 193 * they will not be in logical order. If the scanline format is |
| 194 * kOutOfOrder, the getY() API should be used to determine the actual |
| 195 * y-coordinate of the next output row. |
| 196 * |
| 197 * For this scanline ordering, it is advisable to get and skip |
| 198 * scanlines one at a time. |
| 199 * |
| 200 * Interlaced gifs are an example. |
| 201 */ |
| 202 kOutOfOrder_SkScanlineOrder, |
| 203 |
| 204 /* |
| 205 * Indicates that the entire image must be decoded in order to output |
| 206 * any amount of scanlines. In this case, it is a REALLY BAD IDEA to |
| 207 * request scanlines 1-by-1 or in small chunks. The client should |
| 208 * determine which scanlines are needed and ask for all of them in |
| 209 * a single call to getScanlines(). |
| 210 * |
| 211 * Interlaced pngs are an example. |
| 212 */ |
| 213 kNone_SkScanlineOrder, |
| 214 }; |
| 215 |
| 216 /** |
| 217 * An enum representing the order in which scanlines will be returned by |
| 218 * the scanline decoder. |
| 219 */ |
| 220 SkScanlineOrder getScanlineOrder() const { return this->onGetScanlineOrder()
; } |
| 221 |
| 222 /** |
| 223 * Returns the y-coordinate of the next row to be returned by the scanline |
| 224 * decoder. This will be overridden in the case of |
| 225 * kOutOfOrder_SkScanlineOrder and should be unnecessary in the case of |
| 226 * kNone_SkScanlineOrder. |
| 227 */ |
| 228 int getY() const { |
| 229 SkASSERT(kNone_SkScanlineOrder != this->getScanlineOrder()); |
| 230 return this->onGetY(); |
165 } | 231 } |
166 | 232 |
167 protected: | 233 protected: |
168 SkScanlineDecoder(const SkImageInfo& srcInfo) | 234 SkScanlineDecoder(const SkImageInfo& srcInfo) |
169 : fSrcInfo(srcInfo) | 235 : fSrcInfo(srcInfo) |
170 , fDstInfo() | 236 , fDstInfo() |
| 237 , fOptions() |
171 , fCurrScanline(0) {} | 238 , fCurrScanline(0) {} |
172 | 239 |
173 virtual SkISize onGetScaledDimensions(float /* desiredScale */) { | 240 virtual SkISize onGetScaledDimensions(float /* desiredScale */) { |
174 // By default, scaling is not supported. | 241 // By default, scaling is not supported. |
175 return this->getInfo().dimensions(); | 242 return this->getInfo().dimensions(); |
176 } | 243 } |
177 | 244 |
178 virtual SkEncodedFormat onGetEncodedFormat() const = 0; | 245 virtual SkEncodedFormat onGetEncodedFormat() const = 0; |
179 | 246 |
180 virtual bool onReallyHasAlpha() const { return false; } | 247 virtual bool onReallyHasAlpha() const { return false; } |
181 | 248 |
182 /** | 249 /** |
183 * returns true if the image type is hard to sample and must be scaled after
reading, not during | 250 * Most images types will be kTopDown and will not need to override this fu
nction. |
184 * An example is interlaced pngs, where the entire image must be read for ea
ch decode | |
185 */ | 251 */ |
186 virtual bool onRequiresPostYSampling() { return false; } | 252 virtual SkScanlineOrder onGetScanlineOrder() const { return kTopDown_SkScanl
ineOrder; } |
| 253 |
| 254 /** |
| 255 * Most images will be kTopDown and will not need to override this function
. |
| 256 */ |
| 257 virtual int onGetY() const { return fCurrScanline; } |
187 | 258 |
188 const SkImageInfo& dstInfo() const { return fDstInfo; } | 259 const SkImageInfo& dstInfo() const { return fDstInfo; } |
189 | 260 |
| 261 const SkCodec::Options& options() const { return fOptions; } |
| 262 |
190 private: | 263 private: |
191 const SkImageInfo fSrcInfo; | 264 const SkImageInfo fSrcInfo; |
192 SkImageInfo fDstInfo; | 265 SkImageInfo fDstInfo; |
| 266 SkCodec::Options fOptions; |
193 int fCurrScanline; | 267 int fCurrScanline; |
194 | 268 |
195 virtual SkCodec::Result onStart(const SkImageInfo& dstInfo, | 269 virtual SkCodec::Result onStart(const SkImageInfo& dstInfo, |
196 const SkCodec::Options& options, | 270 const SkCodec::Options& options, |
197 SkPMColor ctable[], int* ctableCount) = 0; | 271 SkPMColor ctable[], int* ctableCount) = 0; |
198 | 272 |
199 // Naive default version just calls onGetScanlines on temp memory. | 273 // Naive default version just calls onGetScanlines on temp memory. |
200 virtual SkCodec::Result onSkipScanlines(int countLines) { | 274 virtual SkCodec::Result onSkipScanlines(int countLines) { |
201 SkAutoMalloc storage(fDstInfo.minRowBytes()); | 275 SkAutoMalloc storage(fDstInfo.minRowBytes()); |
202 // Note that we pass 0 to rowBytes so we continue to use the same memory
. | 276 // Note that we pass 0 to rowBytes so we continue to use the same memory
. |
203 // Also note that while getScanlines checks that rowBytes is big enough, | 277 // Also note that while getScanlines checks that rowBytes is big enough, |
204 // onGetScanlines bypasses that check. | 278 // onGetScanlines bypasses that check. |
205 // Calling the virtual method also means we do not double count | 279 // Calling the virtual method also means we do not double count |
206 // countLines. | 280 // countLines. |
207 return this->onGetScanlines(storage.get(), countLines, 0); | 281 return this->onGetScanlines(storage.get(), countLines, 0); |
208 } | 282 } |
209 | 283 |
210 virtual SkCodec::Result onGetScanlines(void* dst, int countLines, | 284 virtual SkCodec::Result onGetScanlines(void* dst, int countLines, |
211 size_t rowBytes) = 0; | 285 size_t rowBytes) = 0; |
212 | 286 |
213 }; | 287 }; |
214 #endif // SkScanlineDecoder_DEFINED | 288 #endif // SkScanlineDecoder_DEFINED |
OLD | NEW |