OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
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 SkImageDecoder_DEFINED | 8 #ifndef SkImageDecoder_DEFINED |
9 #define SkImageDecoder_DEFINED | 9 #define SkImageDecoder_DEFINED |
10 | 10 |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 an existing bitmap's memory. | 230 an existing bitmap's memory. |
231 | 231 |
232 If a Peeker is installed via setPeeker, it may be used to peek into | 232 If a Peeker is installed via setPeeker, it may be used to peek into |
233 meta data during the decode. | 233 meta data during the decode. |
234 */ | 234 */ |
235 Result decode(SkStream*, SkBitmap* bitmap, SkColorType pref, Mode); | 235 Result decode(SkStream*, SkBitmap* bitmap, SkColorType pref, Mode); |
236 Result decode(SkStream* stream, SkBitmap* bitmap, Mode mode) { | 236 Result decode(SkStream* stream, SkBitmap* bitmap, Mode mode) { |
237 return this->decode(stream, bitmap, kUnknown_SkColorType, mode); | 237 return this->decode(stream, bitmap, kUnknown_SkColorType, mode); |
238 } | 238 } |
239 | 239 |
240 /** | |
241 * Given a stream, build an index for doing tile-based decode. | |
242 * The built index will be saved in the decoder, and the image size will | |
243 * be returned in width and height. | |
244 * | |
245 * Takes ownership of the SkStreamRewindable, on success or failure. | |
246 * | |
247 * Return true for success or false on failure. | |
248 */ | |
249 bool buildTileIndex(SkStreamRewindable*, int *width, int *height); | |
250 | |
251 /** | |
252 * Decode a rectangle subset in the image. | |
253 * The method can only be called after buildTileIndex(). | |
254 * | |
255 * Return true for success. | |
256 * Return false if the index is never built or failing in decoding. | |
257 */ | |
258 bool decodeSubset(SkBitmap* bm, const SkIRect& subset, SkColorType pref); | |
259 | |
260 /** Given a stream, this will try to find an appropriate decoder object. | 240 /** Given a stream, this will try to find an appropriate decoder object. |
261 If none is found, the method returns NULL. | 241 If none is found, the method returns NULL. |
262 */ | 242 */ |
263 static SkImageDecoder* Factory(SkStreamRewindable*); | 243 static SkImageDecoder* Factory(SkStreamRewindable*); |
264 | 244 |
265 /** Decode the image stored in the specified file, and store the result | 245 /** Decode the image stored in the specified file, and store the result |
266 in bitmap. Return true for success or false on failure. | 246 in bitmap. Return true for success or false on failure. |
267 | 247 |
268 @param pref Prefer this colortype. | 248 @param pref Prefer this colortype. |
269 | 249 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 static bool DecodeStream(SkStreamRewindable* stream, SkBitmap* bitmap, SkCol
orType pref, Mode, | 281 static bool DecodeStream(SkStreamRewindable* stream, SkBitmap* bitmap, SkCol
orType pref, Mode, |
302 Format* format = NULL); | 282 Format* format = NULL); |
303 static bool DecodeStream(SkStreamRewindable* stream, SkBitmap* bitmap) { | 283 static bool DecodeStream(SkStreamRewindable* stream, SkBitmap* bitmap) { |
304 return DecodeStream(stream, bitmap, kUnknown_SkColorType, kDecodePixels_
Mode, NULL); | 284 return DecodeStream(stream, bitmap, kUnknown_SkColorType, kDecodePixels_
Mode, NULL); |
305 } | 285 } |
306 | 286 |
307 protected: | 287 protected: |
308 // must be overridden in subclasses. This guy is called by decode(...) | 288 // must be overridden in subclasses. This guy is called by decode(...) |
309 virtual Result onDecode(SkStream*, SkBitmap* bitmap, Mode) = 0; | 289 virtual Result onDecode(SkStream*, SkBitmap* bitmap, Mode) = 0; |
310 | 290 |
311 // If the decoder wants to support tiled based decoding, this method must be
overridden. | |
312 // This is called by buildTileIndex(...) | |
313 virtual bool onBuildTileIndex(SkStreamRewindable*, int* /*width*/, int* /*he
ight*/); | |
314 | |
315 // If the decoder wants to support tiled based decoding, | |
316 // this method must be overridden. This guy is called by decodeRegion(...) | |
317 virtual bool onDecodeSubset(SkBitmap*, const SkIRect&) { | |
318 return false; | |
319 } | |
320 | |
321 /** If planes or rowBytes is NULL, decodes the header and computes component
Sizes | 291 /** If planes or rowBytes is NULL, decodes the header and computes component
Sizes |
322 for memory allocation. | 292 for memory allocation. |
323 Otherwise, decodes the YUV planes into the provided image planes and | 293 Otherwise, decodes the YUV planes into the provided image planes and |
324 updates componentSizes to the final image size. | 294 updates componentSizes to the final image size. |
325 Returns whether the decoding was successful. | 295 Returns whether the decoding was successful. |
326 */ | 296 */ |
327 virtual bool onDecodeYUV8Planes(SkStream*, SkISize[3] /*componentSizes*/, | 297 virtual bool onDecodeYUV8Planes(SkStream*, SkISize[3] /*componentSizes*/, |
328 void*[3] /*planes*/, size_t[3] /*rowBytes*/, | 298 void*[3] /*planes*/, size_t[3] /*rowBytes*/, |
329 SkYUVColorSpace*) { | 299 SkYUVColorSpace*) { |
330 return false; | 300 return false; |
331 } | 301 } |
332 | 302 |
333 /* | |
334 * Crop a rectangle from the src Bitmap to the dest Bitmap. src and dst are | |
335 * both sampled by sampleSize from an original Bitmap. | |
336 * | |
337 * @param dst the destination bitmap. | |
338 * @param src the source bitmap that is sampled by sampleSize from the | |
339 * original bitmap. | |
340 * @param sampleSize the sample size that src is sampled from the original b
itmap. | |
341 * @param (dstX, dstY) the upper-left point of the dest bitmap in terms of | |
342 * the coordinate in the original bitmap. | |
343 * @param (width, height) the width and height of the unsampled dst. | |
344 * @param (srcX, srcY) the upper-left point of the src bitmap in terms of | |
345 * the coordinate in the original bitmap. | |
346 * @return bool Whether or not it succeeded. | |
347 */ | |
348 bool cropBitmap(SkBitmap *dst, SkBitmap *src, int sampleSize, | |
349 int dstX, int dstY, int width, int height, | |
350 int srcX, int srcY); | |
351 | |
352 /** | 303 /** |
353 * Copy all fields on this decoder to the other decoder. Used by subclasses | 304 * Copy all fields on this decoder to the other decoder. Used by subclasses |
354 * to decode a subimage using a different decoder, but with the same settin
gs. | 305 * to decode a subimage using a different decoder, but with the same settin
gs. |
355 */ | 306 */ |
356 void copyFieldsToOther(SkImageDecoder* other); | 307 void copyFieldsToOther(SkImageDecoder* other); |
357 | 308 |
358 /** Can be queried from within onDecode, to see if the user (possibly in | 309 /** Can be queried from within onDecode, to see if the user (possibly in |
359 a different thread) has requested the decode to cancel. If this returns | 310 a different thread) has requested the decode to cancel. If this returns |
360 true, your onDecode() should stop and return false. | 311 true, your onDecode() should stop and return false. |
361 Each subclass needs to decide how often it can query this, to balance | 312 Each subclass needs to decide how often it can query this, to balance |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 DECLARE_DECODER_CREATOR(PKMImageDecoder); | 408 DECLARE_DECODER_CREATOR(PKMImageDecoder); |
458 DECLARE_DECODER_CREATOR(KTXImageDecoder); | 409 DECLARE_DECODER_CREATOR(KTXImageDecoder); |
459 DECLARE_DECODER_CREATOR(ASTCImageDecoder); | 410 DECLARE_DECODER_CREATOR(ASTCImageDecoder); |
460 | 411 |
461 // Typedefs to make registering decoder and formatter callbacks easier. | 412 // Typedefs to make registering decoder and formatter callbacks easier. |
462 // These have to be defined outside SkImageDecoder. :( | 413 // These have to be defined outside SkImageDecoder. :( |
463 typedef SkTRegistry<SkImageDecoder*(*)(SkStreamRewindable*)> SkImageDecod
er_DecodeReg; | 414 typedef SkTRegistry<SkImageDecoder*(*)(SkStreamRewindable*)> SkImageDecod
er_DecodeReg; |
464 typedef SkTRegistry<SkImageDecoder::Format(*)(SkStreamRewindable*)> SkImageDecod
er_FormatReg; | 415 typedef SkTRegistry<SkImageDecoder::Format(*)(SkStreamRewindable*)> SkImageDecod
er_FormatReg; |
465 | 416 |
466 #endif | 417 #endif |
OLD | NEW |