add setPreserveSrcDepth to replace PrefTable API for android

BUG=skia:
R=scroggo@google.com

Author: reed@google.com

Review URL: https://codereview.chromium.org/371273007
This commit is contained in:
reed 2014-07-08 11:15:59 -07:00 committed by Commit bot
parent 65b6fa1777
commit be08aceaab
2 changed files with 30 additions and 1 deletions

View File

@ -205,6 +205,20 @@ public:
void resetPrefConfigTable() { fUsePrefTable = false; }
#endif
/**
* By default, the codec will try to comply with the "pref" colortype
* that is passed to decode() or decodeSubset(). However, this can be called
* to override that, causing the codec to try to match the src depth instead
* (as shown below).
*
* src_8Index -> kIndex_8_SkColorType
* src_8Gray -> kN32_SkColorType
* src_8bpc -> kN32_SkColorType
*/
void setPreserveSrcDepth(bool preserve) {
fPreserveSrcDepth = preserve;
}
SkBitmap::Allocator* getAllocator() const { return fAllocator; }
SkBitmap::Allocator* setAllocator(SkBitmap::Allocator*);
@ -456,6 +470,7 @@ private:
PrefConfigTable fPrefTable; // use if fUsePrefTable is true
bool fUsePrefTable;
#endif
bool fPreserveSrcDepth;
bool fDitherImage;
bool fSkipWritingZeroes;
mutable bool fShouldCancelDecode;

View File

@ -22,6 +22,7 @@ SkImageDecoder::SkImageDecoder()
, fAllocator(NULL)
, fSampleSize(1)
, fDefaultPref(kUnknown_SkColorType)
, fPreserveSrcDepth(false)
, fDitherImage(true)
#ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG
, fUsePrefTable(false)
@ -56,6 +57,7 @@ void SkImageDecoder::copyFieldsToOther(SkImageDecoder* other) {
other->fDefaultPref = fDefaultPref;
}
#endif
other->setPreserveSrcDepth(fPreserveSrcDepth);
other->setDitherImage(fDitherImage);
other->setSkipWritingZeroes(fSkipWritingZeroes);
other->setPreferQualityOverSpeed(fPreferQualityOverSpeed);
@ -156,7 +158,6 @@ void SkImageDecoder::setPrefConfigTable(const PrefConfigTable& prefTable) {
SkColorType SkImageDecoder::getPrefColorType(SrcDepth srcDepth, bool srcHasAlpha) const {
SkColorType ct = fDefaultPref;
#ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG
if (fUsePrefTable) {
// Until we kill or change the PrefTable, we have to go into Config land for a moment.
SkBitmap::Config config = SkBitmap::kNo_Config;
@ -177,6 +178,19 @@ SkColorType SkImageDecoder::getPrefColorType(SrcDepth srcDepth, bool srcHasAlpha
ct = SkBitmapConfigToColorType(config);
}
#endif
if (fPreserveSrcDepth) {
switch (srcDepth) {
case kIndex_SrcDepth:
ct = kIndex_8_SkColorType;
break;
case k8BitGray_SrcDepth:
ct = kN32_SkColorType;
break;
case k32Bit_SrcDepth:
ct = kN32_SkColorType;
break;
}
}
return ct;
}