OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #ifndef SkImageDecoder_DEFINED | 10 #ifndef SkImageDecoder_DEFINED |
11 #define SkImageDecoder_DEFINED | 11 #define SkImageDecoder_DEFINED |
12 | 12 |
13 #include "SkBitmap.h" | 13 #include "SkBitmap.h" |
14 #include "SkBitmapFactory.h" | |
15 #include "SkImage.h" | 14 #include "SkImage.h" |
16 #include "SkRect.h" | 15 #include "SkRect.h" |
17 #include "SkRefCnt.h" | 16 #include "SkRefCnt.h" |
18 #include "SkTRegistry.h" | 17 #include "SkTRegistry.h" |
19 #include "SkTypes.h" | 18 #include "SkTypes.h" |
20 | 19 |
21 class SkStream; | 20 class SkStream; |
22 class SkStreamRewindable; | 21 class SkStreamRewindable; |
23 | 22 |
24 /** \class SkImageDecoder | 23 /** \class SkImageDecoder |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 */ | 328 */ |
330 static bool DecodeMemory(const void* buffer, size_t size, SkBitmap* bitmap, | 329 static bool DecodeMemory(const void* buffer, size_t size, SkBitmap* bitmap, |
331 SkBitmap::Config prefConfig, Mode, | 330 SkBitmap::Config prefConfig, Mode, |
332 Format* format = NULL); | 331 Format* format = NULL); |
333 static bool DecodeMemory(const void* buffer, size_t size, SkBitmap* bitmap){ | 332 static bool DecodeMemory(const void* buffer, size_t size, SkBitmap* bitmap){ |
334 return DecodeMemory(buffer, size, bitmap, SkBitmap::kNo_Config, | 333 return DecodeMemory(buffer, size, bitmap, SkBitmap::kNo_Config, |
335 kDecodePixels_Mode, NULL); | 334 kDecodePixels_Mode, NULL); |
336 } | 335 } |
337 | 336 |
338 /** | 337 /** |
| 338 * Struct containing information about a pixel destination. |
| 339 */ |
| 340 struct Target { |
| 341 /** |
| 342 * Pre-allocated memory. |
| 343 */ |
| 344 void* fAddr; |
| 345 |
| 346 /** |
| 347 * Rowbytes of the allocated memory. |
| 348 */ |
| 349 size_t fRowBytes; |
| 350 }; |
| 351 |
| 352 /** |
339 * Decode memory. | 353 * Decode memory. |
340 * @param info Output parameter. Returns info about the encoded image. | 354 * @param info Output parameter. Returns info about the encoded image. |
341 * @param target Contains the address of pixel memory to decode into | 355 * @param target Contains the address of pixel memory to decode into |
342 * (which must be large enough to hold the width in info) and | 356 * (which must be large enough to hold the width in info) and |
343 * the row bytes to use. If NULL, returns info and does not | 357 * the row bytes to use. If NULL, returns info and does not |
344 * decode pixels. | 358 * decode pixels. |
345 * @return bool Whether the function succeeded. | 359 * @return bool Whether the function succeeded. |
346 * | 360 * |
347 * Sample usage: | 361 * Sample usage: |
348 * <code> | 362 * <code> |
349 * // Determine the image's info: width/height/config | 363 * // Determine the image's info: width/height/config |
350 * SkImageInfo info; | 364 * SkImageInfo info; |
351 * bool success = DecodeMemoryToTarget(src, size, &info, NULL); | 365 * bool success = DecodeMemoryToTarget(src, size, &info, NULL); |
352 * if (!success) return; | 366 * if (!success) return; |
353 * // Allocate space for the result: | 367 * // Allocate space for the result: |
354 * SkBitmapFactory::Target target; | 368 * SkBitmapFactory::Target target; |
355 * target.fAddr = malloc/other allocation | 369 * target.fAddr = malloc/other allocation |
356 * target.fRowBytes = ... | 370 * target.fRowBytes = ... |
357 * // Now decode the actual pixels into target. &info is optional, | 371 * // Now decode the actual pixels into target. &info is optional, |
358 * // and could be NULL | 372 * // and could be NULL |
359 * success = DecodeMemoryToTarget(src, size, &info, &target); | 373 * success = DecodeMemoryToTarget(src, size, &info, &target); |
360 * </code> | 374 * </code> |
361 */ | 375 */ |
362 static bool DecodeMemoryToTarget(const void* buffer, size_t size, SkImageInf
o* info, | 376 static bool DecodeMemoryToTarget(const void* buffer, size_t size, SkImageInf
o* info, |
363 const SkBitmapFactory::Target* target); | 377 const Target* target); |
364 | 378 |
365 /** Decode the image stored in the specified SkStreamRewindable, and store t
he result | 379 /** Decode the image stored in the specified SkStreamRewindable, and store t
he result |
366 in bitmap. Return true for success or false on failure. | 380 in bitmap. Return true for success or false on failure. |
367 | 381 |
368 @param prefConfig If the PrefConfigTable is not set, prefer this config. | 382 @param prefConfig If the PrefConfigTable is not set, prefer this config. |
369 See NOTE ABOUT PREFERRED CONFIGS. | 383 See NOTE ABOUT PREFERRED CONFIGS. |
370 | 384 |
371 @param format On success, if format is non-null, it is set to the format | 385 @param format On success, if format is non-null, it is set to the format |
372 of the decoded stream. On failure it is ignored. | 386 of the decoded stream. On failure it is ignored. |
373 */ | 387 */ |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 DECLARE_DECODER_CREATOR(WBMPImageDecoder); | 561 DECLARE_DECODER_CREATOR(WBMPImageDecoder); |
548 DECLARE_DECODER_CREATOR(WEBPImageDecoder); | 562 DECLARE_DECODER_CREATOR(WEBPImageDecoder); |
549 | 563 |
550 | 564 |
551 // Typedefs to make registering decoder and formatter callbacks easier. | 565 // Typedefs to make registering decoder and formatter callbacks easier. |
552 // These have to be defined outside SkImageDecoder. :( | 566 // These have to be defined outside SkImageDecoder. :( |
553 typedef SkTRegistry<SkImageDecoder*(*)(SkStreamRewindable*)> SkImageDecod
er_DecodeReg; | 567 typedef SkTRegistry<SkImageDecoder*(*)(SkStreamRewindable*)> SkImageDecod
er_DecodeReg; |
554 typedef SkTRegistry<SkImageDecoder::Format(*)(SkStreamRewindable*)> SkImageDecod
er_FormatReg; | 568 typedef SkTRegistry<SkImageDecoder::Format(*)(SkStreamRewindable*)> SkImageDecod
er_FormatReg; |
555 | 569 |
556 #endif | 570 #endif |
OLD | NEW |