hide SkImageDecoder::Chooser
BUG=skia: R=scroggo@google.com Author: reed@google.com Review URL: https://codereview.chromium.org/331433003
This commit is contained in:
parent
d58a0ba9cf
commit
5926b86b90
@ -137,6 +137,7 @@ public:
|
||||
Peeker* getPeeker() const { return fPeeker; }
|
||||
Peeker* setPeeker(Peeker*);
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER
|
||||
/** \class Chooser
|
||||
|
||||
Base class for optional callbacks to choose an image from a format that
|
||||
@ -158,6 +159,7 @@ public:
|
||||
|
||||
Chooser* getChooser() const { return fChooser; }
|
||||
Chooser* setChooser(Chooser*);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Optional table describing the caller's preferred config based on
|
||||
@ -436,9 +438,11 @@ public:
|
||||
protected:
|
||||
SkImageDecoder();
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER
|
||||
// helper function for decoders to handle the (common) case where there is only
|
||||
// once choice available in the image file.
|
||||
bool chooseFromOneChoice(SkColorType, int width, int height) const;
|
||||
#endif
|
||||
|
||||
/* Helper for subclasses. Call this to allocate the pixel memory given the bitmap's
|
||||
width/height/rowbytes/config. Returns true on success. This method handles checking
|
||||
@ -469,7 +473,9 @@ protected:
|
||||
|
||||
private:
|
||||
Peeker* fPeeker;
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER
|
||||
Chooser* fChooser;
|
||||
#endif
|
||||
SkBitmap::Allocator* fAllocator;
|
||||
int fSampleSize;
|
||||
SkBitmap::Config fDefaultPref; // use if fUsePrefTable is false
|
||||
|
@ -30,7 +30,9 @@ void SkImageDecoder::SetDeviceConfig(SkBitmap::Config config)
|
||||
|
||||
SkImageDecoder::SkImageDecoder()
|
||||
: fPeeker(NULL)
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER
|
||||
, fChooser(NULL)
|
||||
#endif
|
||||
, fAllocator(NULL)
|
||||
, fSampleSize(1)
|
||||
, fDefaultPref(SkBitmap::kNo_Config)
|
||||
@ -43,7 +45,9 @@ SkImageDecoder::SkImageDecoder()
|
||||
|
||||
SkImageDecoder::~SkImageDecoder() {
|
||||
SkSafeUnref(fPeeker);
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER
|
||||
SkSafeUnref(fChooser);
|
||||
#endif
|
||||
SkSafeUnref(fAllocator);
|
||||
}
|
||||
|
||||
@ -52,7 +56,9 @@ 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);
|
||||
if (fUsePrefTable) {
|
||||
@ -107,10 +113,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);
|
||||
@ -124,6 +132,7 @@ void SkImageDecoder::setSampleSize(int size) {
|
||||
fSampleSize = size;
|
||||
}
|
||||
|
||||
#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 {
|
||||
@ -136,6 +145,7 @@ bool SkImageDecoder::chooseFromOneChoice(SkColorType colorType, int width, int h
|
||||
chooser->inspect(0, SkColorTypeToBitmapConfig(colorType), width, height);
|
||||
return chooser->choose() == 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool SkImageDecoder::allocPixelRef(SkBitmap* bitmap,
|
||||
SkColorTable* ctable) const {
|
||||
|
@ -62,10 +62,12 @@ bool SkKTXImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) {
|
||||
const unsigned short width = ktxFile.width();
|
||||
const unsigned short height = ktxFile.height();
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER
|
||||
// should we allow the Chooser (if present) to pick a config for us???
|
||||
if (!this->chooseFromOneChoice(kN32_SkColorType, width, height)) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Set a flag if our source is premultiplied alpha
|
||||
const SkString premulKey("KTXPremultipliedAlpha");
|
||||
|
@ -309,10 +309,12 @@ bool SkGIFImageDecoder::onDecode(SkStream* sk_stream, SkBitmap* bm, Mode mode) {
|
||||
imageTop = 0;
|
||||
}
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER
|
||||
// FIXME: We could give the caller a choice of images or configs.
|
||||
if (!this->chooseFromOneChoice(kIndex_8_SkColorType, width, height)) {
|
||||
return error_return(*bm, "chooseFromOneChoice");
|
||||
}
|
||||
#endif
|
||||
|
||||
SkScaledBitmapSampler sampler(width, height, this->getSampleSize());
|
||||
|
||||
|
@ -94,6 +94,7 @@ bool SkICOImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode)
|
||||
if (length < (size_t)(6 + count*16))
|
||||
return false;
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER
|
||||
int choice;
|
||||
Chooser* chooser = this->getChooser();
|
||||
//FIXME:if no chooser, consider providing the largest color image
|
||||
@ -138,6 +139,9 @@ bool SkICOImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode)
|
||||
//you never know what the chooser is going to supply
|
||||
if (choice >= count || choice < 0)
|
||||
return false;
|
||||
#else
|
||||
const int choice = 0; // TODO: fold this value into the expressions below
|
||||
#endif
|
||||
|
||||
//skip ahead to the correct header
|
||||
//commented out lines are not used, but if i switch to other read method, need to know how many to skip
|
||||
|
@ -613,10 +613,12 @@ bool SkJPEGImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) {
|
||||
}
|
||||
sampleSize = recompute_sampleSize(sampleSize, cinfo);
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER
|
||||
// should we allow the Chooser (if present) to pick a colortype for us???
|
||||
if (!this->chooseFromOneChoice(colorType, cinfo.output_width, cinfo.output_height)) {
|
||||
return return_false(cinfo, *bm, "chooseFromOneChoice");
|
||||
}
|
||||
#endif
|
||||
|
||||
SkScaledBitmapSampler sampler(cinfo.output_width, cinfo.output_height, sampleSize);
|
||||
// Assume an A8 bitmap is not opaque to avoid the check of each
|
||||
|
@ -607,9 +607,11 @@ bool SkPNGImageDecoder::getBitmapConfig(png_structp png_ptr, png_infop info_ptr,
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER
|
||||
if (!this->chooseFromOneChoice(*colorTypep, origWidth, origHeight)) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
// If the image has alpha and the decoder wants unpremultiplied
|
||||
// colors, the only supported config is 8888.
|
||||
|
@ -292,9 +292,11 @@ bool SkWEBPImageDecoder::setDecodeConfig(SkBitmap* decodedBitmap, int width, int
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER
|
||||
if (!this->chooseFromOneChoice(colorType, width, height)) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
SkAlphaType alphaType = kOpaque_SkAlphaType;
|
||||
if (SkToBool(fHasAlpha)) {
|
||||
@ -379,12 +381,14 @@ bool SkWEBPImageDecoder::onDecodeSubset(SkBitmap* decodedBitmap,
|
||||
if (!allocResult) {
|
||||
return return_false(*decodedBitmap, "allocPixelRef");
|
||||
}
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER
|
||||
} else {
|
||||
// This is also called in setDecodeConfig in above block.
|
||||
// i.e., when bitmap->isNull() is true.
|
||||
if (!chooseFromOneChoice(bitmap->colorType(), width, height)) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
SkAutoLockPixels alp(*bitmap);
|
||||
|
@ -46,10 +46,12 @@ bool SkPKMImageDecoder::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) {
|
||||
const unsigned short width = etc1_pkm_get_width(buf);
|
||||
const unsigned short height = etc1_pkm_get_height(buf);
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER
|
||||
// should we allow the Chooser (if present) to pick a config for us???
|
||||
if (!this->chooseFromOneChoice(kN32_SkColorType, width, height)) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Setup the sampler...
|
||||
SkScaledBitmapSampler sampler(width, height, this->getSampleSize());
|
||||
|
@ -73,9 +73,11 @@ SkImageDecoder::Peeker* SkImageDecoder::setPeeker(Peeker*) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER
|
||||
SkImageDecoder::Chooser* SkImageDecoder::setChooser(Chooser*) {
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
SkBitmap::Allocator* SkImageDecoder::setAllocator(SkBitmap::Allocator*) {
|
||||
return NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user