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 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 */ | 132 */ |
133 virtual int choose() = 0; | 133 virtual int choose() = 0; |
134 | 134 |
135 private: | 135 private: |
136 typedef SkRefCnt INHERITED; | 136 typedef SkRefCnt INHERITED; |
137 }; | 137 }; |
138 | 138 |
139 Chooser* getChooser() const { return fChooser; } | 139 Chooser* getChooser() const { return fChooser; } |
140 Chooser* setChooser(Chooser*); | 140 Chooser* setChooser(Chooser*); |
141 | 141 |
142 /** This optional table describes the caller's preferred config based on | 142 /** |
143 @Deprecated. Use the struct version instead. | |
144 | |
145 This optional table describes the caller's preferred config based on | |
143 information about the src data. For this table, the src attributes are | 146 information about the src data. For this table, the src attributes are |
144 described in terms of depth (index (8), 16, 32/24) and if there is | 147 described in terms of depth (index (8), 16, 32/24) and if there is |
145 per-pixel alpha. These inputs combine to create an index into the | 148 per-pixel alpha. These inputs combine to create an index into the |
146 pref[] table, which contains the caller's preferred config for that | 149 pref[] table, which contains the caller's preferred config for that |
147 input, or kNo_Config if there is no preference. | 150 input, or kNo_Config if there is no preference. |
148 | 151 |
149 To specify no preferrence, call setPrefConfigTable(NULL), which is | 152 To specify no preference, call setPrefConfigTable(NULL), which is |
150 the default. | 153 the default. |
151 | 154 |
152 Note, it is still at the discretion of the codec as to what output | 155 Note, it is still at the discretion of the codec as to what output |
153 config is actually returned, as it may not be able to support the | 156 config is actually returned, as it may not be able to support the |
154 caller's preference. | 157 caller's preference. |
155 | 158 |
156 Here is how the index into the table is computed from the src: | 159 Here is how the index into the table is computed from the src: |
157 depth [8, 16, 32/24] -> 0, 2, 4 | 160 depth [8, 16, 32/24] -> 0, 2, 4 |
158 alpha [no, yes] -> 0, 1 | 161 alpha [no, yes] -> 0, 1 |
159 The two index values are OR'd together. | 162 The two index values are OR'd together. |
160 src: 8-index, no-alpha -> 0 | 163 src: 8-index, no-alpha -> 0 |
161 src: 8-index, yes-alpha -> 1 | 164 src: 8-index, yes-alpha -> 1 |
162 src: 16bit, no-alpha -> 2 // e.g. 565 | 165 src: 16bit, no-alpha -> 2 // e.g. 565 |
163 src: 16bit, yes-alpha -> 3 // e.g. 1555 | 166 src: 16bit, yes-alpha -> 3 // e.g. 1555 |
164 src: 32/24, no-alpha -> 4 | 167 src: 32/24, no-alpha -> 4 |
165 src: 32/24, yes-alpha -> 5 | 168 src: 32/24, yes-alpha -> 5 |
166 */ | 169 */ |
167 void setPrefConfigTable(const SkBitmap::Config pref[6]); | 170 void setPrefConfigTable(const SkBitmap::Config pref[6]); |
168 | 171 |
172 /** | |
173 * Optional table describing the caller's preferred config based on | |
174 * information about the src data. The src attributes are described | |
175 * in terms of depth (8 (index or grayscale), 16, 32/24) and whether | |
176 * there is per-pixel alpha (does not apply to grayscale). If there | |
177 * is no preference, kNo_Config should be used for that src config. | |
178 * | |
179 * NOTE ABOUT PREFERRED CONFIGS: | |
180 * If a config is preferred, either using a pref table or as a parameter | |
181 * to some flavor of decode, it is still at the discretion of the codec | |
182 * as to what output config is actually returned, as it may not be able | |
183 * to support the caller's preference. | |
184 * | |
185 * If a bitmap is decoded into SkBitmap::A8_Config, the resulting bitmap | |
186 * will either be a conversion of the grayscale in the case of a | |
187 * grayscale source or the alpha channel in the case of a source with | |
188 * an alpha channel. | |
189 */ | |
190 struct PrefConfigTable { | |
191 SkBitmap::Config f8Index_NoAlpha; | |
192 SkBitmap::Config f8Index_YesAlpha; | |
193 SkBitmap::Config f8Gray; | |
194 SkBitmap::Config f16bit_NoAlpha; | |
195 SkBitmap::Config f16bit_YesAlpha; | |
196 SkBitmap::Config f32_24bit_NoAlpha; | |
197 SkBitmap::Config f32_24bit_YesAlpha; | |
198 }; | |
199 | |
200 /** | |
201 * Set an optional table for specifying the caller's preferred config | |
202 * based on information about the src data. | |
203 * | |
204 * The default is no preference, which will assume the config set by | |
205 * decode is preferred. | |
206 */ | |
207 void setPrefConfigTable(const PrefConfigTable&); | |
208 | |
209 /** | |
210 * Do not use a PrefConfigTable to determine the output config. This | |
211 * is the default, so there is no need to call unless a PrefConfigTable | |
212 * was previously set. | |
213 */ | |
214 void ignorePrefConfigTable() { fUsePrefTable = false; } | |
215 | |
169 SkBitmap::Allocator* getAllocator() const { return fAllocator; } | 216 SkBitmap::Allocator* getAllocator() const { return fAllocator; } |
170 SkBitmap::Allocator* setAllocator(SkBitmap::Allocator*); | 217 SkBitmap::Allocator* setAllocator(SkBitmap::Allocator*); |
171 | 218 |
172 // sample-size, if set to > 1, tells the decoder to return a smaller than | 219 // sample-size, if set to > 1, tells the decoder to return a smaller than |
173 // original bitmap, sampling 1 pixel for every size pixels. e.g. if sample | 220 // original bitmap, sampling 1 pixel for every size pixels. e.g. if sample |
174 // size is set to 3, then the returned bitmap will be 1/3 as wide and high, | 221 // size is set to 3, then the returned bitmap will be 1/3 as wide and high, |
175 // and will contain 1/9 as many pixels as the original. | 222 // and will contain 1/9 as many pixels as the original. |
176 // Note: this is a hint, and the codec may choose to ignore this, or only | 223 // Note: this is a hint, and the codec may choose to ignore this, or only |
177 // approximate the sample size. | 224 // approximate the sample size. |
178 int getSampleSize() const { return fSampleSize; } | 225 int getSampleSize() const { return fSampleSize; } |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
262 } | 309 } |
263 | 310 |
264 /** Given a stream, this will try to find an appropriate decoder object. | 311 /** Given a stream, this will try to find an appropriate decoder object. |
265 If none is found, the method returns NULL. | 312 If none is found, the method returns NULL. |
266 */ | 313 */ |
267 static SkImageDecoder* Factory(SkStream*); | 314 static SkImageDecoder* Factory(SkStream*); |
268 | 315 |
269 /** Decode the image stored in the specified file, and store the result | 316 /** Decode the image stored in the specified file, and store the result |
270 in bitmap. Return true for success or false on failure. | 317 in bitmap. Return true for success or false on failure. |
271 | 318 |
272 If pref is kNo_Config, then the decoder is free to choose the most natur al | 319 @param prefConfig If the PrefConfigTable is not set, prefer this config. |
273 config given the image data. If pref something other than kNo_Config, | 320 See NOTE ABOUT PREFERRED CONFIGS. |
274 the decoder will attempt to decode the image into that format, unless | |
275 there is a conflict (e.g. the image has per-pixel alpha and the bitmap's | |
276 config does not support that), in which case the decoder will choose a | |
277 closest match configuration. | |
278 | 321 |
279 @param format On success, if format is non-null, it is set to the format | 322 @param format On success, if format is non-null, it is set to the format |
280 of the decoded file. On failure it is ignored. | 323 of the decoded file. On failure it is ignored. |
281 */ | 324 */ |
282 static bool DecodeFile(const char file[], SkBitmap* bitmap, | 325 static bool DecodeFile(const char file[], SkBitmap* bitmap, |
283 SkBitmap::Config prefConfig, Mode, | 326 SkBitmap::Config prefConfig, Mode, |
284 Format* format = NULL); | 327 Format* format = NULL); |
285 static bool DecodeFile(const char file[], SkBitmap* bitmap) { | 328 static bool DecodeFile(const char file[], SkBitmap* bitmap) { |
286 return DecodeFile(file, bitmap, SkBitmap::kNo_Config, | 329 return DecodeFile(file, bitmap, SkBitmap::kNo_Config, |
287 kDecodePixels_Mode, NULL); | 330 kDecodePixels_Mode, NULL); |
288 } | 331 } |
289 /** Decode the image stored in the specified memory buffer, and store the | 332 /** Decode the image stored in the specified memory buffer, and store the |
290 result in bitmap. Return true for success or false on failure. | 333 result in bitmap. Return true for success or false on failure. |
291 | 334 |
292 If pref is kNo_Config, then the decoder is free to choose the most natur al | 335 @param prefConfig If the PrefConfigTable is not set, prefer this config. |
293 config given the image data. If pref something other than kNo_Config, | 336 See NOTE ABOUT PREFERRED CONFIGS. |
294 the decoder will attempt to decode the image into that format, unless | |
295 there is a conflict (e.g. the image has per-pixel alpha and the bitmap's | |
296 config does not support that), in which case the decoder will choose a | |
297 closest match configuration. | |
298 | 337 |
299 @param format On success, if format is non-null, it is set to the format | 338 @param format On success, if format is non-null, it is set to the format |
300 of the decoded buffer. On failure it is ignored. | 339 of the decoded buffer. On failure it is ignored. |
301 */ | 340 */ |
302 static bool DecodeMemory(const void* buffer, size_t size, SkBitmap* bitmap, | 341 static bool DecodeMemory(const void* buffer, size_t size, SkBitmap* bitmap, |
303 SkBitmap::Config prefConfig, Mode, | 342 SkBitmap::Config prefConfig, Mode, |
304 Format* format = NULL); | 343 Format* format = NULL); |
305 static bool DecodeMemory(const void* buffer, size_t size, SkBitmap* bitmap){ | 344 static bool DecodeMemory(const void* buffer, size_t size, SkBitmap* bitmap){ |
306 return DecodeMemory(buffer, size, bitmap, SkBitmap::kNo_Config, | 345 return DecodeMemory(buffer, size, bitmap, SkBitmap::kNo_Config, |
307 kDecodePixels_Mode, NULL); | 346 kDecodePixels_Mode, NULL); |
(...skipping 22 matching lines...) Expand all Loading... | |
330 * // and could be NULL | 369 * // and could be NULL |
331 * success = DecodeMemoryToTarget(src, size, &info, &target); | 370 * success = DecodeMemoryToTarget(src, size, &info, &target); |
332 * </code> | 371 * </code> |
333 */ | 372 */ |
334 static bool DecodeMemoryToTarget(const void* buffer, size_t size, SkImage::I nfo* info, | 373 static bool DecodeMemoryToTarget(const void* buffer, size_t size, SkImage::I nfo* info, |
335 const SkBitmapFactory::Target* target); | 374 const SkBitmapFactory::Target* target); |
336 | 375 |
337 /** Decode the image stored in the specified SkStream, and store the result | 376 /** Decode the image stored in the specified SkStream, and store the result |
338 in bitmap. Return true for success or false on failure. | 377 in bitmap. Return true for success or false on failure. |
339 | 378 |
340 If pref is kNo_Config, then the decoder is free to choose the most | 379 @param prefConfig If the PrefConfigTable is not set, prefer this config. |
341 natural config given the image data. If pref something other than | 380 See NOTE ABOUT PREFERRED CONFIGS. |
342 kNo_Config, the decoder will attempt to decode the image into that | |
343 format, unless there is a conflict (e.g. the image has per-pixel alpha | |
344 and the bitmap's config does not support that), in which case the | |
345 decoder will choose a closest match configuration. | |
346 | 381 |
347 @param format On success, if format is non-null, it is set to the format | 382 @param format On success, if format is non-null, it is set to the format |
348 of the decoded stream. On failure it is ignored. | 383 of the decoded stream. On failure it is ignored. |
349 */ | 384 */ |
350 static bool DecodeStream(SkStream* stream, SkBitmap* bitmap, | 385 static bool DecodeStream(SkStream* stream, SkBitmap* bitmap, |
351 SkBitmap::Config prefConfig, Mode, | 386 SkBitmap::Config prefConfig, Mode, |
352 Format* format = NULL); | 387 Format* format = NULL); |
353 static bool DecodeStream(SkStream* stream, SkBitmap* bitmap) { | 388 static bool DecodeStream(SkStream* stream, SkBitmap* bitmap) { |
354 return DecodeStream(stream, bitmap, SkBitmap::kNo_Config, | 389 return DecodeStream(stream, bitmap, SkBitmap::kNo_Config, |
355 kDecodePixels_Mode, NULL); | 390 kDecodePixels_Mode, NULL); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
436 bool chooseFromOneChoice(SkBitmap::Config config, int width, int height) con st; | 471 bool chooseFromOneChoice(SkBitmap::Config config, int width, int height) con st; |
437 | 472 |
438 /* Helper for subclasses. Call this to allocate the pixel memory given the bitmap's | 473 /* Helper for subclasses. Call this to allocate the pixel memory given the bitmap's |
439 width/height/rowbytes/config. Returns true on success. This method handl es checking | 474 width/height/rowbytes/config. Returns true on success. This method handl es checking |
440 for an optional Allocator. | 475 for an optional Allocator. |
441 */ | 476 */ |
442 bool allocPixelRef(SkBitmap*, SkColorTable*) const; | 477 bool allocPixelRef(SkBitmap*, SkColorTable*) const; |
443 | 478 |
444 enum SrcDepth { | 479 enum SrcDepth { |
445 kIndex_SrcDepth, | 480 kIndex_SrcDepth, |
481 k8BitGray_SrcDepth, | |
446 k16Bit_SrcDepth, | 482 k16Bit_SrcDepth, |
scroggo
2013/07/11 20:37:29
Removed this, since it was never used.
| |
447 k32Bit_SrcDepth | 483 k32Bit_SrcDepth, |
448 }; | 484 }; |
449 /** The subclass, inside onDecode(), calls this to determine the config of | 485 /** The subclass, inside onDecode(), calls this to determine the config of |
450 the returned bitmap. SrcDepth and hasAlpha reflect the raw data of the | 486 the returned bitmap. SrcDepth and hasAlpha reflect the raw data of the |
451 src image. This routine returns the caller's preference given | 487 src image. This routine returns the caller's preference given |
452 srcDepth and hasAlpha, or kNo_Config if there is no preference. | 488 srcDepth and hasAlpha, or kNo_Config if there is no preference. |
453 | 489 |
454 Note: this also takes into account GetDeviceConfig(), so the subclass | 490 Note: this also takes into account GetDeviceConfig(), so the subclass |
455 need not call that. | 491 need not call that. |
456 */ | 492 */ |
457 SkBitmap::Config getPrefConfig(SrcDepth, bool hasAlpha) const; | 493 SkBitmap::Config getPrefConfig(SrcDepth, bool hasAlpha) const; |
458 | 494 |
459 private: | 495 private: |
460 Peeker* fPeeker; | 496 Peeker* fPeeker; |
461 Chooser* fChooser; | 497 Chooser* fChooser; |
462 SkBitmap::Allocator* fAllocator; | 498 SkBitmap::Allocator* fAllocator; |
463 int fSampleSize; | 499 int fSampleSize; |
464 SkBitmap::Config fDefaultPref; // use if fUsePrefTable is false | 500 SkBitmap::Config fDefaultPref; // use if fUsePrefTable is false |
465 SkBitmap::Config fPrefTable[6]; // use if fUsePrefTable is true | 501 PrefConfigTable fPrefTable; // use if fUsePrefTable is true |
466 bool fDitherImage; | 502 bool fDitherImage; |
467 bool fUsePrefTable; | 503 bool fUsePrefTable; |
468 mutable bool fShouldCancelDecode; | 504 mutable bool fShouldCancelDecode; |
469 bool fPreferQualityOverSpeed; | 505 bool fPreferQualityOverSpeed; |
470 bool fRequireUnpremultipliedColors; | 506 bool fRequireUnpremultipliedColors; |
471 }; | 507 }; |
472 | 508 |
473 /** Calling newDecoder with a stream returns a new matching imagedecoder | 509 /** Calling newDecoder with a stream returns a new matching imagedecoder |
474 instance, or NULL if none can be found. The caller must manage its ownership | 510 instance, or NULL if none can be found. The caller must manage its ownership |
475 of the stream as usual, calling unref() when it is done, as the returned | 511 of the stream as usual, calling unref() when it is done, as the returned |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
510 // not all of these will be available | 546 // not all of these will be available |
511 DECLARE_DECODER_CREATOR(BMPImageDecoder); | 547 DECLARE_DECODER_CREATOR(BMPImageDecoder); |
512 DECLARE_DECODER_CREATOR(GIFImageDecoder); | 548 DECLARE_DECODER_CREATOR(GIFImageDecoder); |
513 DECLARE_DECODER_CREATOR(ICOImageDecoder); | 549 DECLARE_DECODER_CREATOR(ICOImageDecoder); |
514 DECLARE_DECODER_CREATOR(JPEGImageDecoder); | 550 DECLARE_DECODER_CREATOR(JPEGImageDecoder); |
515 DECLARE_DECODER_CREATOR(PNGImageDecoder); | 551 DECLARE_DECODER_CREATOR(PNGImageDecoder); |
516 DECLARE_DECODER_CREATOR(WBMPImageDecoder); | 552 DECLARE_DECODER_CREATOR(WBMPImageDecoder); |
517 DECLARE_DECODER_CREATOR(WEBPImageDecoder); | 553 DECLARE_DECODER_CREATOR(WEBPImageDecoder); |
518 | 554 |
519 #endif | 555 #endif |
OLD | NEW |