Chromium Code Reviews| Index: include/core/SkImageDecoder.h |
| diff --git a/include/core/SkImageDecoder.h b/include/core/SkImageDecoder.h |
| index 191fe53f4c588a0584486fee25b68ee7a2c7ab1f..7bdaaa8eb5f072b26eb7faf63d32fe493b5ff926 100644 |
| --- a/include/core/SkImageDecoder.h |
| +++ b/include/core/SkImageDecoder.h |
| @@ -139,14 +139,17 @@ public: |
| Chooser* getChooser() const { return fChooser; } |
| Chooser* setChooser(Chooser*); |
| - /** This optional table describes the caller's preferred config based on |
| + /** |
| + @Deprecated. Use the struct version instead. |
| + |
| + This optional table describes the caller's preferred config based on |
| information about the src data. For this table, the src attributes are |
| described in terms of depth (index (8), 16, 32/24) and if there is |
| per-pixel alpha. These inputs combine to create an index into the |
| pref[] table, which contains the caller's preferred config for that |
| input, or kNo_Config if there is no preference. |
| - To specify no preferrence, call setPrefConfigTable(NULL), which is |
| + To specify no preference, call setPrefConfigTable(NULL), which is |
| the default. |
| Note, it is still at the discretion of the codec as to what output |
| @@ -166,6 +169,50 @@ public: |
| */ |
| void setPrefConfigTable(const SkBitmap::Config pref[6]); |
| + /** |
| + * Optional table describing the caller's preferred config based on |
| + * information about the src data. Each field should be set to the |
| + * preferred config for a src described in the name of the field. The |
| + * src attributes are described in terms of depth (8-index, |
| + * 8bit-grayscale, or 8-bits/component) and whether there is per-pixel |
| + * alpha (does not apply to grayscale). If the caller has no preference |
| + * for a particular src type, its slot should be set to kNo_Config. |
| + * |
| + * NOTE ABOUT PREFERRED CONFIGS: |
| + * If a config is preferred, either using a pref table or as a parameter |
| + * to some flavor of decode, it is still at the discretion of the codec |
| + * as to what output config is actually returned, as it may not be able |
| + * to support the caller's preference. |
| + * |
| + * If a bitmap is decoded into SkBitmap::A8_Config, the resulting bitmap |
| + * will either be a conversion of the grayscale in the case of a |
| + * grayscale source or the alpha channel in the case of a source with |
| + * an alpha channel. |
| + */ |
| + struct PrefConfigTable { |
| + SkBitmap::Config fPrefFor_8Index_NoAlpha_src; |
|
scroggo
2013/07/11 20:37:29
New names. Uglier, but also more clear what they s
|
| + SkBitmap::Config fPrefFor_8Index_YesAlpha_src; |
| + SkBitmap::Config fPrefFor_8Gray_src; |
| + SkBitmap::Config fPrefFor_8bpc_NoAlpha_src; |
| + SkBitmap::Config fPrefFor_8bpc_YesAlpha_src; |
|
scroggo
2013/07/11 20:37:29
The 32/24 duality was because we used the same Src
|
| + }; |
| + |
| + /** |
| + * Set an optional table for specifying the caller's preferred config |
| + * based on information about the src data. |
| + * |
| + * The default is no preference, which will assume the config set by |
| + * decode is preferred. |
| + */ |
| + void setPrefConfigTable(const PrefConfigTable&); |
| + |
| + /** |
| + * Do not use a PrefConfigTable to determine the output config. This |
| + * is the default, so there is no need to call unless a PrefConfigTable |
| + * was previously set. |
| + */ |
| + void resetPrefConfigTable() { fUsePrefTable = false; } |
| + |
| SkBitmap::Allocator* getAllocator() const { return fAllocator; } |
| SkBitmap::Allocator* setAllocator(SkBitmap::Allocator*); |
| @@ -269,12 +316,8 @@ public: |
| /** Decode the image stored in the specified file, and store the result |
| in bitmap. Return true for success or false on failure. |
| - If pref is kNo_Config, then the decoder is free to choose the most natural |
| - config given the image data. If pref something other than kNo_Config, |
| - the decoder will attempt to decode the image into that format, unless |
| - there is a conflict (e.g. the image has per-pixel alpha and the bitmap's |
| - config does not support that), in which case the decoder will choose a |
| - closest match configuration. |
| + @param prefConfig If the PrefConfigTable is not set, prefer this config. |
| + See NOTE ABOUT PREFERRED CONFIGS. |
| @param format On success, if format is non-null, it is set to the format |
| of the decoded file. On failure it is ignored. |
| @@ -289,12 +332,8 @@ public: |
| /** Decode the image stored in the specified memory buffer, and store the |
| result in bitmap. Return true for success or false on failure. |
| - If pref is kNo_Config, then the decoder is free to choose the most natural |
| - config given the image data. If pref something other than kNo_Config, |
| - the decoder will attempt to decode the image into that format, unless |
| - there is a conflict (e.g. the image has per-pixel alpha and the bitmap's |
| - config does not support that), in which case the decoder will choose a |
| - closest match configuration. |
| + @param prefConfig If the PrefConfigTable is not set, prefer this config. |
| + See NOTE ABOUT PREFERRED CONFIGS. |
| @param format On success, if format is non-null, it is set to the format |
| of the decoded buffer. On failure it is ignored. |
| @@ -337,12 +376,8 @@ public: |
| /** Decode the image stored in the specified SkStream, and store the result |
| in bitmap. Return true for success or false on failure. |
| - If pref is kNo_Config, then the decoder is free to choose the most |
| - natural config given the image data. If pref something other than |
| - kNo_Config, the decoder will attempt to decode the image into that |
| - format, unless there is a conflict (e.g. the image has per-pixel alpha |
| - and the bitmap's config does not support that), in which case the |
| - decoder will choose a closest match configuration. |
| + @param prefConfig If the PrefConfigTable is not set, prefer this config. |
| + See NOTE ABOUT PREFERRED CONFIGS. |
| @param format On success, if format is non-null, it is set to the format |
| of the decoded stream. On failure it is ignored. |
| @@ -441,10 +476,16 @@ protected: |
| */ |
| bool allocPixelRef(SkBitmap*, SkColorTable*) const; |
| + /** |
| + * The raw data of the src image. |
| + */ |
| enum SrcDepth { |
| + // Color-indexed. |
| kIndex_SrcDepth, |
| - k16Bit_SrcDepth, |
| - k32Bit_SrcDepth |
| + // Grayscale in 8 bits. |
| + k8BitGray_SrcDepth, |
| + // 8 bits per component. Used for 24 bit if there is no alpha. |
| + k32Bit_SrcDepth, |
| }; |
| /** The subclass, inside onDecode(), calls this to determine the config of |
| the returned bitmap. SrcDepth and hasAlpha reflect the raw data of the |
| @@ -462,7 +503,7 @@ private: |
| SkBitmap::Allocator* fAllocator; |
| int fSampleSize; |
| SkBitmap::Config fDefaultPref; // use if fUsePrefTable is false |
| - SkBitmap::Config fPrefTable[6]; // use if fUsePrefTable is true |
| + PrefConfigTable fPrefTable; // use if fUsePrefTable is true |
| bool fDitherImage; |
| bool fUsePrefTable; |
| mutable bool fShouldCancelDecode; |