diff options
Diffstat (limited to 'chromium/third_party/skia/src/images/SkImageDecoder.cpp')
-rw-r--r-- | chromium/third_party/skia/src/images/SkImageDecoder.cpp | 96 |
1 files changed, 50 insertions, 46 deletions
diff --git a/chromium/third_party/skia/src/images/SkImageDecoder.cpp b/chromium/third_party/skia/src/images/SkImageDecoder.cpp index 32cf087ed86..fe61906357d 100644 --- a/chromium/third_party/skia/src/images/SkImageDecoder.cpp +++ b/chromium/third_party/skia/src/images/SkImageDecoder.cpp @@ -14,28 +14,18 @@ #include "SkTemplates.h" #include "SkCanvas.h" -static SkBitmap::Config gDeviceConfig = SkBitmap::kNo_Config; - -SkBitmap::Config SkImageDecoder::GetDeviceConfig() -{ - return gDeviceConfig; -} - -void SkImageDecoder::SetDeviceConfig(SkBitmap::Config config) -{ - gDeviceConfig = config; -} - -/////////////////////////////////////////////////////////////////////////////// - SkImageDecoder::SkImageDecoder() : fPeeker(NULL) +#ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER , fChooser(NULL) +#endif , fAllocator(NULL) , fSampleSize(1) - , fDefaultPref(SkBitmap::kNo_Config) + , fDefaultPref(kUnknown_SkColorType) , fDitherImage(true) +#ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG , fUsePrefTable(false) +#endif , fSkipWritingZeroes(false) , fPreferQualityOverSpeed(false) , fRequireUnpremultipliedColors(false) { @@ -43,7 +33,9 @@ SkImageDecoder::SkImageDecoder() SkImageDecoder::~SkImageDecoder() { SkSafeUnref(fPeeker); +#ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER SkSafeUnref(fChooser); +#endif SkSafeUnref(fAllocator); } @@ -52,14 +44,18 @@ void SkImageDecoder::copyFieldsToOther(SkImageDecoder* other) { return; } other->setPeeker(fPeeker); +#ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER other->setChooser(fChooser); +#endif other->setAllocator(fAllocator); other->setSampleSize(fSampleSize); +#ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG if (fUsePrefTable) { other->setPrefConfigTable(fPrefTable); } else { other->fDefaultPref = fDefaultPref; } +#endif other->setDitherImage(fDitherImage); other->setSkipWritingZeroes(fSkipWritingZeroes); other->setPreferQualityOverSpeed(fPreferQualityOverSpeed); @@ -84,6 +80,10 @@ const char* SkImageDecoder::GetFormatName(Format format) { return "GIF"; case kICO_Format: return "ICO"; + case kPKM_Format: + return "PKM"; + case kKTX_Format: + return "KTX"; case kJPEG_Format: return "JPEG"; case kPNG_Format: @@ -103,10 +103,12 @@ SkImageDecoder::Peeker* SkImageDecoder::setPeeker(Peeker* peeker) { return peeker; } +#ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER SkImageDecoder::Chooser* SkImageDecoder::setChooser(Chooser* chooser) { SkRefCnt_SafeAssign(fChooser, chooser); return chooser; } +#endif SkBitmap::Allocator* SkImageDecoder::setAllocator(SkBitmap::Allocator* alloc) { SkRefCnt_SafeAssign(fAllocator, alloc); @@ -120,17 +122,20 @@ void SkImageDecoder::setSampleSize(int size) { fSampleSize = size; } -bool SkImageDecoder::chooseFromOneChoice(SkBitmap::Config config, int width, - int height) const { +#ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER +// TODO: change Chooser virtual to take colorType, so we can stop calling SkColorTypeToBitmapConfig +// +bool SkImageDecoder::chooseFromOneChoice(SkColorType colorType, int width, int height) const { Chooser* chooser = fChooser; - + if (NULL == chooser) { // no chooser, we just say YES to decoding :) return true; } chooser->begin(1); - chooser->inspect(0, config, width, height); + chooser->inspect(0, SkColorTypeToBitmapConfig(colorType), width, height); return chooser->choose() == 0; } +#endif bool SkImageDecoder::allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable) const { @@ -139,16 +144,22 @@ bool SkImageDecoder::allocPixelRef(SkBitmap* bitmap, /////////////////////////////////////////////////////////////////////////////// +#ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG void SkImageDecoder::setPrefConfigTable(const PrefConfigTable& prefTable) { fUsePrefTable = true; fPrefTable = prefTable; } +#endif -SkBitmap::Config SkImageDecoder::getPrefConfig(SrcDepth srcDepth, - bool srcHasAlpha) const { - SkBitmap::Config config = SkBitmap::kNo_Config; +// TODO: use colortype in fPrefTable, fDefaultPref so we can stop using SkBitmapConfigToColorType() +// +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; switch (srcDepth) { case kIndex_SrcDepth: config = srcHasAlpha ? fPrefTable.fPrefFor_8Index_YesAlpha_src @@ -162,21 +173,17 @@ SkBitmap::Config SkImageDecoder::getPrefConfig(SrcDepth srcDepth, : fPrefTable.fPrefFor_8bpc_NoAlpha_src; break; } - } else { - config = fDefaultPref; - } - - if (SkBitmap::kNo_Config == config) { - config = SkImageDecoder::GetDeviceConfig(); + // now return to SkColorType land + ct = SkBitmapConfigToColorType(config); } - return config; +#endif + return ct; } -bool SkImageDecoder::decode(SkStream* stream, SkBitmap* bm, - SkBitmap::Config pref, Mode mode) { +bool SkImageDecoder::decode(SkStream* stream, SkBitmap* bm, SkColorType pref, Mode mode) { // we reset this to false before calling onDecode fShouldCancelDecode = false; - // assign this, for use by getPrefConfig(), in case fUsePrefTable is false + // assign this, for use by getPrefColorType(), in case fUsePrefTable is false fDefaultPref = pref; // pass a temporary bitmap, so that if we return false, we are assured of @@ -189,18 +196,16 @@ bool SkImageDecoder::decode(SkStream* stream, SkBitmap* bm, return true; } -bool SkImageDecoder::decodeSubset(SkBitmap* bm, const SkIRect& rect, - SkBitmap::Config pref) { +bool SkImageDecoder::decodeSubset(SkBitmap* bm, const SkIRect& rect, SkColorType pref) { // we reset this to false before calling onDecodeSubset fShouldCancelDecode = false; - // assign this, for use by getPrefConfig(), in case fUsePrefTable is false + // assign this, for use by getPrefColorType(), in case fUsePrefTable is false fDefaultPref = pref; return this->onDecodeSubset(bm, rect); } -bool SkImageDecoder::buildTileIndex(SkStreamRewindable* stream, - int *width, int *height) { +bool SkImageDecoder::buildTileIndex(SkStreamRewindable* stream, int *width, int *height) { // we reset this to false before calling onBuildTileIndex fShouldCancelDecode = false; @@ -212,7 +217,7 @@ bool SkImageDecoder::cropBitmap(SkBitmap *dst, SkBitmap *src, int sampleSize, int srcX, int srcY) { int w = width / sampleSize; int h = height / sampleSize; - if (src->config() == SkBitmap::kIndex8_Config) { + if (src->colorType() == kIndex_8_SkColorType) { // kIndex8 does not allow drawing via an SkCanvas, as is done below. // Instead, use extractSubset. Note that this shares the SkPixelRef and // SkColorTable. @@ -228,7 +233,7 @@ bool SkImageDecoder::cropBitmap(SkBitmap *dst, SkBitmap *src, int sampleSize, } // if the destination has no pixels then we must allocate them. if (dst->isNull()) { - dst->setConfig(src->config(), w, h, 0, src->alphaType()); + dst->setInfo(src->info().makeWH(w, h)); if (!this->allocPixelRef(dst, NULL)) { SkDEBUGF(("failed to allocate pixels needed to crop the bitmap")); @@ -256,8 +261,8 @@ bool SkImageDecoder::cropBitmap(SkBitmap *dst, SkBitmap *src, int sampleSize, /////////////////////////////////////////////////////////////////////////////// -bool SkImageDecoder::DecodeFile(const char file[], SkBitmap* bm, - SkBitmap::Config pref, Mode mode, Format* format) { +bool SkImageDecoder::DecodeFile(const char file[], SkBitmap* bm, SkColorType pref, Mode mode, + Format* format) { SkASSERT(file); SkASSERT(bm); @@ -271,8 +276,8 @@ bool SkImageDecoder::DecodeFile(const char file[], SkBitmap* bm, return false; } -bool SkImageDecoder::DecodeMemory(const void* buffer, size_t size, SkBitmap* bm, - SkBitmap::Config pref, Mode mode, Format* format) { +bool SkImageDecoder::DecodeMemory(const void* buffer, size_t size, SkBitmap* bm, SkColorType pref, + Mode mode, Format* format) { if (0 == size) { return false; } @@ -282,9 +287,8 @@ bool SkImageDecoder::DecodeMemory(const void* buffer, size_t size, SkBitmap* bm, return SkImageDecoder::DecodeStream(&stream, bm, pref, mode, format); } -bool SkImageDecoder::DecodeStream(SkStreamRewindable* stream, SkBitmap* bm, - SkBitmap::Config pref, Mode mode, - Format* format) { +bool SkImageDecoder::DecodeStream(SkStreamRewindable* stream, SkBitmap* bm, SkColorType pref, + Mode mode, Format* format) { SkASSERT(stream); SkASSERT(bm); |