| 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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 */ | 358 */ |
| 360 static bool DecodeMemory(const void* buffer, size_t size, SkBitmap* bitmap, | 359 static bool DecodeMemory(const void* buffer, size_t size, SkBitmap* bitmap, |
| 361 SkBitmap::Config prefConfig, Mode, | 360 SkBitmap::Config prefConfig, Mode, |
| 362 Format* format = NULL); | 361 Format* format = NULL); |
| 363 static bool DecodeMemory(const void* buffer, size_t size, SkBitmap* bitmap){ | 362 static bool DecodeMemory(const void* buffer, size_t size, SkBitmap* bitmap){ |
| 364 return DecodeMemory(buffer, size, bitmap, SkBitmap::kNo_Config, | 363 return DecodeMemory(buffer, size, bitmap, SkBitmap::kNo_Config, |
| 365 kDecodePixels_Mode, NULL); | 364 kDecodePixels_Mode, NULL); |
| 366 } | 365 } |
| 367 | 366 |
| 368 /** | 367 /** |
| 368 * Struct containing information about a pixel destination. |
| 369 */ |
| 370 struct Target { |
| 371 /** |
| 372 * Pre-allocated memory. |
| 373 */ |
| 374 void* fAddr; |
| 375 |
| 376 /** |
| 377 * Rowbytes of the allocated memory. |
| 378 */ |
| 379 size_t fRowBytes; |
| 380 }; |
| 381 |
| 382 /** |
| 369 * Decode memory. | 383 * Decode memory. |
| 370 * @param info Output parameter. Returns info about the encoded image. | 384 * @param info Output parameter. Returns info about the encoded image. |
| 371 * @param target Contains the address of pixel memory to decode into | 385 * @param target Contains the address of pixel memory to decode into |
| 372 * (which must be large enough to hold the width in info) and | 386 * (which must be large enough to hold the width in info) and |
| 373 * the row bytes to use. If NULL, returns info and does not | 387 * the row bytes to use. If NULL, returns info and does not |
| 374 * decode pixels. | 388 * decode pixels. |
| 375 * @return bool Whether the function succeeded. | 389 * @return bool Whether the function succeeded. |
| 376 * | 390 * |
| 377 * Sample usage: | 391 * Sample usage: |
| 378 * <code> | 392 * <code> |
| 379 * // Determine the image's info: width/height/config | 393 * // Determine the image's info: width/height/config |
| 380 * SkImageInfo info; | 394 * SkImageInfo info; |
| 381 * bool success = DecodeMemoryToTarget(src, size, &info, NULL); | 395 * bool success = DecodeMemoryToTarget(src, size, &info, NULL); |
| 382 * if (!success) return; | 396 * if (!success) return; |
| 383 * // Allocate space for the result: | 397 * // Allocate space for the result: |
| 384 * SkBitmapFactory::Target target; | 398 * SkBitmapFactory::Target target; |
| 385 * target.fAddr = malloc/other allocation | 399 * target.fAddr = malloc/other allocation |
| 386 * target.fRowBytes = ... | 400 * target.fRowBytes = ... |
| 387 * // Now decode the actual pixels into target. &info is optional, | 401 * // Now decode the actual pixels into target. &info is optional, |
| 388 * // and could be NULL | 402 * // and could be NULL |
| 389 * success = DecodeMemoryToTarget(src, size, &info, &target); | 403 * success = DecodeMemoryToTarget(src, size, &info, &target); |
| 390 * </code> | 404 * </code> |
| 391 */ | 405 */ |
| 392 static bool DecodeMemoryToTarget(const void* buffer, size_t size, SkImageInf
o* info, | 406 static bool DecodeMemoryToTarget(const void* buffer, size_t size, SkImageInf
o* info, |
| 393 const SkBitmapFactory::Target* target); | 407 const Target* target); |
| 394 | 408 |
| 395 /** Decode the image stored in the specified SkStreamRewindable, and store t
he result | 409 /** Decode the image stored in the specified SkStreamRewindable, and store t
he result |
| 396 in bitmap. Return true for success or false on failure. | 410 in bitmap. Return true for success or false on failure. |
| 397 | 411 |
| 398 @param prefConfig If the PrefConfigTable is not set, prefer this config. | 412 @param prefConfig If the PrefConfigTable is not set, prefer this config. |
| 399 See NOTE ABOUT PREFERRED CONFIGS. | 413 See NOTE ABOUT PREFERRED CONFIGS. |
| 400 | 414 |
| 401 @param format On success, if format is non-null, it is set to the format | 415 @param format On success, if format is non-null, it is set to the format |
| 402 of the decoded stream. On failure it is ignored. | 416 of the decoded stream. On failure it is ignored. |
| 403 */ | 417 */ |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 DECLARE_DECODER_CREATOR(WBMPImageDecoder); | 591 DECLARE_DECODER_CREATOR(WBMPImageDecoder); |
| 578 DECLARE_DECODER_CREATOR(WEBPImageDecoder); | 592 DECLARE_DECODER_CREATOR(WEBPImageDecoder); |
| 579 | 593 |
| 580 | 594 |
| 581 // Typedefs to make registering decoder and formatter callbacks easier. | 595 // Typedefs to make registering decoder and formatter callbacks easier. |
| 582 // These have to be defined outside SkImageDecoder. :( | 596 // These have to be defined outside SkImageDecoder. :( |
| 583 typedef SkTRegistry<SkImageDecoder*(*)(SkStreamRewindable*)> SkImageDecod
er_DecodeReg; | 597 typedef SkTRegistry<SkImageDecoder*(*)(SkStreamRewindable*)> SkImageDecod
er_DecodeReg; |
| 584 typedef SkTRegistry<SkImageDecoder::Format(*)(SkStreamRewindable*)> SkImageDecod
er_FormatReg; | 598 typedef SkTRegistry<SkImageDecoder::Format(*)(SkStreamRewindable*)> SkImageDecod
er_FormatReg; |
| 585 | 599 |
| 586 #endif | 600 #endif |
| OLD | NEW |