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 |
11 #include "SkBitmap.h" | 11 #include "SkBitmap.h" |
12 #include "SkEncodedFormat.h" | |
12 #include "SkImage.h" | 13 #include "SkImage.h" |
13 #include "SkRect.h" | 14 #include "SkRect.h" |
14 #include "SkRefCnt.h" | 15 #include "SkRefCnt.h" |
15 #include "SkTRegistry.h" | 16 #include "SkTRegistry.h" |
16 #include "SkTypes.h" | 17 #include "SkTypes.h" |
17 | 18 |
18 class SkStream; | 19 class SkStream; |
19 class SkStreamRewindable; | 20 class SkStreamRewindable; |
20 | 21 |
21 /** \class SkImageDecoder | 22 /** \class SkImageDecoder |
22 | 23 |
23 Base class for decoding compressed images into a SkBitmap | 24 Base class for decoding compressed images into a SkBitmap |
24 */ | 25 */ |
25 class SkImageDecoder : SkNoncopyable { | 26 class SkImageDecoder : SkNoncopyable { |
26 public: | 27 public: |
27 virtual ~SkImageDecoder(); | 28 virtual ~SkImageDecoder(); |
28 | 29 |
29 enum Format { | |
scroggo
2015/03/19 20:00:21
I could leave this unchanged, since we're removing
| |
30 kUnknown_Format, | |
31 kBMP_Format, | |
32 kGIF_Format, | |
33 kICO_Format, | |
34 kJPEG_Format, | |
35 kPNG_Format, | |
36 kWBMP_Format, | |
37 kWEBP_Format, | |
38 kPKM_Format, | |
39 kKTX_Format, | |
40 kASTC_Format, | |
41 | |
42 kLastKnownFormat = kKTX_Format, | |
43 }; | |
44 | |
45 /** Return the format of image this decoder can decode. If this decoder can decode multiple | 30 /** Return the format of image this decoder can decode. If this decoder can decode multiple |
46 formats, kUnknown_Format will be returned. | 31 formats, kUnknown_Format will be returned. |
47 */ | 32 */ |
48 virtual Format getFormat() const; | 33 virtual SkEncodedFormat getFormat() const; |
49 | 34 |
50 /** If planes or rowBytes is NULL, decodes the header and computes component Sizes | 35 /** If planes or rowBytes is NULL, decodes the header and computes component Sizes |
51 for memory allocation. | 36 for memory allocation. |
52 Otherwise, decodes the YUV planes into the provided image planes and | 37 Otherwise, decodes the YUV planes into the provided image planes and |
53 updates componentSizes to the final image size. | 38 updates componentSizes to the final image size. |
54 Returns whether the decoding was successful. | 39 Returns whether the decoding was successful. |
55 */ | 40 */ |
56 bool decodeYUV8Planes(SkStream* stream, SkISize componentSizes[3], void* pla nes[3], | 41 bool decodeYUV8Planes(SkStream* stream, SkISize componentSizes[3], void* pla nes[3], |
57 size_t rowBytes[3], SkYUVColorSpace*); | 42 size_t rowBytes[3], SkYUVColorSpace*); |
58 | 43 |
59 /** Return the format of the SkStreamRewindable or kUnknown_Format if it can not be determined. | 44 /** Return the format of the SkStreamRewindable or kUnknown_SkEncodedFormat if it cannot be |
45 determined. | |
60 Rewinds the stream before returning. | 46 Rewinds the stream before returning. |
61 */ | 47 */ |
62 static Format GetStreamFormat(SkStreamRewindable*); | 48 static SkEncodedFormat GetStreamFormat(SkStreamRewindable*); |
63 | 49 |
64 /** Return a readable string of the Format provided. | 50 /** Return a readable string of the Format provided. |
65 */ | 51 */ |
66 static const char* GetFormatName(Format); | 52 static const char* GetFormatName(SkEncodedFormat); |
67 | 53 |
68 /** Return a readable string of the value returned by getFormat(). | 54 /** Return a readable string of the value returned by getFormat(). |
69 */ | 55 */ |
70 const char* getFormatName() const; | 56 const char* getFormatName() const; |
71 | 57 |
72 /** Whether the decoder should skip writing zeroes to output if possible. | 58 /** Whether the decoder should skip writing zeroes to output if possible. |
73 */ | 59 */ |
74 bool getSkipWritingZeroes() const { return fSkipWritingZeroes; } | 60 bool getSkipWritingZeroes() const { return fSkipWritingZeroes; } |
75 | 61 |
76 /** Set to true if the decoder should skip writing any zeroes when | 62 /** Set to true if the decoder should skip writing any zeroes when |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
265 | 251 |
266 /** Decode the image stored in the specified file, and store the result | 252 /** Decode the image stored in the specified file, and store the result |
267 in bitmap. Return true for success or false on failure. | 253 in bitmap. Return true for success or false on failure. |
268 | 254 |
269 @param pref Prefer this colortype. | 255 @param pref Prefer this colortype. |
270 | 256 |
271 @param format On success, if format is non-null, it is set to the format | 257 @param format On success, if format is non-null, it is set to the format |
272 of the decoded file. On failure it is ignored. | 258 of the decoded file. On failure it is ignored. |
273 */ | 259 */ |
274 static bool DecodeFile(const char file[], SkBitmap* bitmap, SkColorType pref , Mode, | 260 static bool DecodeFile(const char file[], SkBitmap* bitmap, SkColorType pref , Mode, |
275 Format* format = NULL); | 261 SkEncodedFormat* format = NULL); |
276 static bool DecodeFile(const char file[], SkBitmap* bitmap) { | 262 static bool DecodeFile(const char file[], SkBitmap* bitmap) { |
277 return DecodeFile(file, bitmap, kUnknown_SkColorType, kDecodePixels_Mode , NULL); | 263 return DecodeFile(file, bitmap, kUnknown_SkColorType, kDecodePixels_Mode , NULL); |
278 } | 264 } |
279 | 265 |
280 /** Decode the image stored in the specified memory buffer, and store the | 266 /** Decode the image stored in the specified memory buffer, and store the |
281 result in bitmap. Return true for success or false on failure. | 267 result in bitmap. Return true for success or false on failure. |
282 | 268 |
283 @param pref Prefer this colortype. | 269 @param pref Prefer this colortype. |
284 | 270 |
285 @param format On success, if format is non-null, it is set to the format | 271 @param format On success, if format is non-null, it is set to the format |
286 of the decoded buffer. On failure it is ignored. | 272 of the decoded buffer. On failure it is ignored. |
287 */ | 273 */ |
288 static bool DecodeMemory(const void* buffer, size_t size, SkBitmap* bitmap, SkColorType pref, | 274 static bool DecodeMemory(const void* buffer, size_t size, SkBitmap* bitmap, SkColorType pref, |
289 Mode, Format* format = NULL); | 275 Mode, SkEncodedFormat* format = NULL); |
290 static bool DecodeMemory(const void* buffer, size_t size, SkBitmap* bitmap){ | 276 static bool DecodeMemory(const void* buffer, size_t size, SkBitmap* bitmap){ |
291 return DecodeMemory(buffer, size, bitmap, kUnknown_SkColorType, kDecodeP ixels_Mode, NULL); | 277 return DecodeMemory(buffer, size, bitmap, kUnknown_SkColorType, kDecodeP ixels_Mode, NULL); |
292 } | 278 } |
293 | 279 |
294 /** Decode the image stored in the specified SkStreamRewindable, and store t he result | 280 /** Decode the image stored in the specified SkStreamRewindable, and store t he result |
295 in bitmap. Return true for success or false on failure. | 281 in bitmap. Return true for success or false on failure. |
296 | 282 |
297 @param pref Prefer this colortype. | 283 @param pref Prefer this colortype. |
298 | 284 |
299 @param format On success, if format is non-null, it is set to the format | 285 @param format On success, if format is non-null, it is set to the format |
300 of the decoded stream. On failure it is ignored. | 286 of the decoded stream. On failure it is ignored. |
301 */ | 287 */ |
302 static bool DecodeStream(SkStreamRewindable* stream, SkBitmap* bitmap, SkCol orType pref, Mode, | 288 static bool DecodeStream(SkStreamRewindable* stream, SkBitmap* bitmap, SkCol orType pref, Mode, |
303 Format* format = NULL); | 289 SkEncodedFormat* format = NULL); |
304 static bool DecodeStream(SkStreamRewindable* stream, SkBitmap* bitmap) { | 290 static bool DecodeStream(SkStreamRewindable* stream, SkBitmap* bitmap) { |
305 return DecodeStream(stream, bitmap, kUnknown_SkColorType, kDecodePixels_ Mode, NULL); | 291 return DecodeStream(stream, bitmap, kUnknown_SkColorType, kDecodePixels_ Mode, NULL); |
306 } | 292 } |
307 | 293 |
308 protected: | 294 protected: |
309 // must be overridden in subclasses. This guy is called by decode(...) | 295 // must be overridden in subclasses. This guy is called by decode(...) |
310 virtual Result onDecode(SkStream*, SkBitmap* bitmap, Mode) = 0; | 296 virtual Result onDecode(SkStream*, SkBitmap* bitmap, Mode) = 0; |
311 | 297 |
312 // If the decoder wants to support tiled based decoding, this method must be overridden. | 298 // If the decoder wants to support tiled based decoding, this method must be overridden. |
313 // This is called by buildTileIndex(...) | 299 // This is called by buildTileIndex(...) |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
456 DECLARE_DECODER_CREATOR(JPEGImageDecoder); | 442 DECLARE_DECODER_CREATOR(JPEGImageDecoder); |
457 DECLARE_DECODER_CREATOR(PNGImageDecoder); | 443 DECLARE_DECODER_CREATOR(PNGImageDecoder); |
458 DECLARE_DECODER_CREATOR(WBMPImageDecoder); | 444 DECLARE_DECODER_CREATOR(WBMPImageDecoder); |
459 DECLARE_DECODER_CREATOR(WEBPImageDecoder); | 445 DECLARE_DECODER_CREATOR(WEBPImageDecoder); |
460 DECLARE_DECODER_CREATOR(PKMImageDecoder); | 446 DECLARE_DECODER_CREATOR(PKMImageDecoder); |
461 DECLARE_DECODER_CREATOR(KTXImageDecoder); | 447 DECLARE_DECODER_CREATOR(KTXImageDecoder); |
462 DECLARE_DECODER_CREATOR(ASTCImageDecoder); | 448 DECLARE_DECODER_CREATOR(ASTCImageDecoder); |
463 | 449 |
464 // Typedefs to make registering decoder and formatter callbacks easier. | 450 // Typedefs to make registering decoder and formatter callbacks easier. |
465 // These have to be defined outside SkImageDecoder. :( | 451 // These have to be defined outside SkImageDecoder. :( |
466 typedef SkTRegistry<SkImageDecoder*(*)(SkStreamRewindable*)> SkImageDecod er_DecodeReg; | 452 typedef SkTRegistry<SkImageDecoder*(*)(SkStreamRewindable*)> SkImageDecoder_D ecodeReg; |
467 typedef SkTRegistry<SkImageDecoder::Format(*)(SkStreamRewindable*)> SkImageDecod er_FormatReg; | 453 typedef SkTRegistry<SkEncodedFormat(*)(SkStreamRewindable*)> SkImageDecoder_F ormatReg; |
468 | 454 |
469 #endif | 455 #endif |
OLD | NEW |