Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(342)

Side by Side Diff: include/core/SkImageDecoder.h

Issue 18083026: Allow decoding JPEG into A8. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Naming improvements, remove obsolete, add a test. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/images/SkImageDecoder.cpp » ('j') | tests/ImageDecodingTest.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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. Each field should be set to the
175 * preferred config for a src described in the name of the field. The
176 * src attributes are described in terms of depth (8-index,
177 * 8bit-grayscale, or 8-bits/component) and whether there is per-pixel
178 * alpha (does not apply to grayscale). If the caller has no preference
179 * for a particular src type, its slot should be set to kNo_Config.
180 *
181 * NOTE ABOUT PREFERRED CONFIGS:
182 * If a config is preferred, either using a pref table or as a parameter
183 * to some flavor of decode, it is still at the discretion of the codec
184 * as to what output config is actually returned, as it may not be able
185 * to support the caller's preference.
186 *
187 * If a bitmap is decoded into SkBitmap::A8_Config, the resulting bitmap
188 * will either be a conversion of the grayscale in the case of a
189 * grayscale source or the alpha channel in the case of a source with
190 * an alpha channel.
191 */
192 struct PrefConfigTable {
193 SkBitmap::Config fPrefFor_8Index_NoAlpha_src;
scroggo 2013/07/11 20:37:29 New names. Uglier, but also more clear what they s
194 SkBitmap::Config fPrefFor_8Index_YesAlpha_src;
195 SkBitmap::Config fPrefFor_8Gray_src;
196 SkBitmap::Config fPrefFor_8bpc_NoAlpha_src;
197 SkBitmap::Config fPrefFor_8bpc_YesAlpha_src;
scroggo 2013/07/11 20:37:29 The 32/24 duality was because we used the same Src
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 resetPrefConfigTable() { 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
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
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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 // helper function for decoders to handle the (common) case where there is o nly 469 // helper function for decoders to handle the (common) case where there is o nly
435 // once choice available in the image file. 470 // once choice available in the image file.
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
479 /**
480 * The raw data of the src image.
481 */
444 enum SrcDepth { 482 enum SrcDepth {
483 // Color-indexed.
445 kIndex_SrcDepth, 484 kIndex_SrcDepth,
446 k16Bit_SrcDepth, 485 // Grayscale in 8 bits.
447 k32Bit_SrcDepth 486 k8BitGray_SrcDepth,
487 // 8 bits per component. Used for 24 bit if there is no alpha.
488 k32Bit_SrcDepth,
448 }; 489 };
449 /** The subclass, inside onDecode(), calls this to determine the config of 490 /** The subclass, inside onDecode(), calls this to determine the config of
450 the returned bitmap. SrcDepth and hasAlpha reflect the raw data of the 491 the returned bitmap. SrcDepth and hasAlpha reflect the raw data of the
451 src image. This routine returns the caller's preference given 492 src image. This routine returns the caller's preference given
452 srcDepth and hasAlpha, or kNo_Config if there is no preference. 493 srcDepth and hasAlpha, or kNo_Config if there is no preference.
453 494
454 Note: this also takes into account GetDeviceConfig(), so the subclass 495 Note: this also takes into account GetDeviceConfig(), so the subclass
455 need not call that. 496 need not call that.
456 */ 497 */
457 SkBitmap::Config getPrefConfig(SrcDepth, bool hasAlpha) const; 498 SkBitmap::Config getPrefConfig(SrcDepth, bool hasAlpha) const;
458 499
459 private: 500 private:
460 Peeker* fPeeker; 501 Peeker* fPeeker;
461 Chooser* fChooser; 502 Chooser* fChooser;
462 SkBitmap::Allocator* fAllocator; 503 SkBitmap::Allocator* fAllocator;
463 int fSampleSize; 504 int fSampleSize;
464 SkBitmap::Config fDefaultPref; // use if fUsePrefTable is false 505 SkBitmap::Config fDefaultPref; // use if fUsePrefTable is false
465 SkBitmap::Config fPrefTable[6]; // use if fUsePrefTable is true 506 PrefConfigTable fPrefTable; // use if fUsePrefTable is true
466 bool fDitherImage; 507 bool fDitherImage;
467 bool fUsePrefTable; 508 bool fUsePrefTable;
468 mutable bool fShouldCancelDecode; 509 mutable bool fShouldCancelDecode;
469 bool fPreferQualityOverSpeed; 510 bool fPreferQualityOverSpeed;
470 bool fRequireUnpremultipliedColors; 511 bool fRequireUnpremultipliedColors;
471 }; 512 };
472 513
473 /** Calling newDecoder with a stream returns a new matching imagedecoder 514 /** 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 515 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 516 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
510 // not all of these will be available 551 // not all of these will be available
511 DECLARE_DECODER_CREATOR(BMPImageDecoder); 552 DECLARE_DECODER_CREATOR(BMPImageDecoder);
512 DECLARE_DECODER_CREATOR(GIFImageDecoder); 553 DECLARE_DECODER_CREATOR(GIFImageDecoder);
513 DECLARE_DECODER_CREATOR(ICOImageDecoder); 554 DECLARE_DECODER_CREATOR(ICOImageDecoder);
514 DECLARE_DECODER_CREATOR(JPEGImageDecoder); 555 DECLARE_DECODER_CREATOR(JPEGImageDecoder);
515 DECLARE_DECODER_CREATOR(PNGImageDecoder); 556 DECLARE_DECODER_CREATOR(PNGImageDecoder);
516 DECLARE_DECODER_CREATOR(WBMPImageDecoder); 557 DECLARE_DECODER_CREATOR(WBMPImageDecoder);
517 DECLARE_DECODER_CREATOR(WEBPImageDecoder); 558 DECLARE_DECODER_CREATOR(WEBPImageDecoder);
518 559
519 #endif 560 #endif
OLDNEW
« no previous file with comments | « no previous file | src/images/SkImageDecoder.cpp » ('j') | tests/ImageDecodingTest.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698