remove dead SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER code
BUG=skia: Review URL: https://codereview.chromium.org/816273002
This commit is contained in:
parent
080e673b10
commit
2d73d80d68
@ -145,30 +145,6 @@ 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
|
||||
contains multiple images.
|
||||
*/
|
||||
class Chooser : public SkRefCnt {
|
||||
public:
|
||||
SK_DECLARE_INST_COUNT(Chooser)
|
||||
|
||||
virtual void begin(int count) {}
|
||||
virtual void inspect(int index, SkBitmap::Config config, int width, int height) {}
|
||||
/** Return the index of the subimage you want, or -1 to choose none of them.
|
||||
*/
|
||||
virtual int choose() = 0;
|
||||
|
||||
private:
|
||||
typedef SkRefCnt INHERITED;
|
||||
};
|
||||
|
||||
Chooser* getChooser() const { return fChooser; }
|
||||
Chooser* setChooser(Chooser*);
|
||||
#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
|
||||
@ -400,12 +376,6 @@ protected:
|
||||
*/
|
||||
SkColorType getDefaultPref() { return fDefaultPref; }
|
||||
|
||||
#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 info.
|
||||
Returns true on success. This method handles checking for an optional Allocator.
|
||||
*/
|
||||
@ -431,9 +401,6 @@ protected:
|
||||
|
||||
private:
|
||||
Peeker* fPeeker;
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER
|
||||
Chooser* fChooser;
|
||||
#endif
|
||||
SkBitmap::Allocator* fAllocator;
|
||||
int fSampleSize;
|
||||
SkColorType fDefaultPref; // use if fUsePrefTable is false
|
||||
|
@ -16,9 +16,6 @@
|
||||
|
||||
SkImageDecoder::SkImageDecoder()
|
||||
: fPeeker(NULL)
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER
|
||||
, fChooser(NULL)
|
||||
#endif
|
||||
, fAllocator(NULL)
|
||||
, fSampleSize(1)
|
||||
, fDefaultPref(kUnknown_SkColorType)
|
||||
@ -31,9 +28,6 @@ SkImageDecoder::SkImageDecoder()
|
||||
|
||||
SkImageDecoder::~SkImageDecoder() {
|
||||
SkSafeUnref(fPeeker);
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER
|
||||
SkSafeUnref(fChooser);
|
||||
#endif
|
||||
SkSafeUnref(fAllocator);
|
||||
}
|
||||
|
||||
@ -42,9 +36,6 @@ 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);
|
||||
other->setPreserveSrcDepth(fPreserveSrcDepth);
|
||||
@ -97,13 +88,6 @@ 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);
|
||||
return alloc;
|
||||
@ -116,21 +100,6 @@ 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 {
|
||||
Chooser* chooser = fChooser;
|
||||
|
||||
if (NULL == chooser) { // no chooser, we just say YES to decoding :)
|
||||
return true;
|
||||
}
|
||||
chooser->begin(1);
|
||||
chooser->inspect(0, SkColorTypeToBitmapConfig(colorType), width, height);
|
||||
return chooser->choose() == 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool SkImageDecoder::allocPixelRef(SkBitmap* bitmap,
|
||||
SkColorTable* ctable) const {
|
||||
return bitmap->tryAllocPixels(fAllocator, ctable);
|
||||
|
@ -117,13 +117,6 @@ SkImageDecoder::Result SkASTCImageDecoder::onDecode(SkStream* stream, SkBitmap*
|
||||
// Advance the buffer past the image dimensions
|
||||
buf += 9;
|
||||
|
||||
#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 kFailure;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Setup the sampler...
|
||||
SkScaledBitmapSampler sampler(width, height, this->getSampleSize());
|
||||
|
||||
|
@ -62,13 +62,6 @@ SkImageDecoder::Result SkKTXImageDecoder::onDecode(SkStream* stream, SkBitmap* b
|
||||
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 kFailure;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Set a flag if our source is premultiplied alpha
|
||||
const SkString premulKey("KTXPremultipliedAlpha");
|
||||
const bool bSrcIsPremul = ktxFile.getValueForKey(premulKey) == SkString("True");
|
||||
|
@ -310,13 +310,6 @@ SkImageDecoder::Result SkGIFImageDecoder::onDecode(SkStream* sk_stream, SkBitmap
|
||||
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());
|
||||
|
||||
bm->setInfo(SkImageInfo::Make(sampler.scaledWidth(), sampler.scaledHeight(),
|
||||
|
@ -97,67 +97,17 @@ SkImageDecoder::Result SkICOImageDecoder::onDecode(SkStream* stream, SkBitmap* b
|
||||
return kFailure;
|
||||
}
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER
|
||||
int choice;
|
||||
Chooser* chooser = this->getChooser();
|
||||
//FIXME:if no chooser, consider providing the largest color image
|
||||
//what are the odds that the largest image would be monochrome?
|
||||
if (NULL == chooser) {
|
||||
choice = 0;
|
||||
} else {
|
||||
chooser->begin(count);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//need to find out the config, width, and height from the stream
|
||||
int width = readByte(buf, 6 + i*16);
|
||||
int height = readByte(buf, 7 + i*16);
|
||||
int offset = read4Bytes(buf, 18 + i*16);
|
||||
int bitCount = read2Bytes(buf, offset+14);
|
||||
SkBitmap::Config c;
|
||||
//currently only provide ARGB_8888_, but maybe we want kIndex8_Config for 1 and 4, and possibly 8?
|
||||
//or maybe we'll determine this based on the provided config
|
||||
switch (bitCount)
|
||||
{
|
||||
case 1:
|
||||
case 4:
|
||||
// In reality, at least for the moment, these will be decoded into kARGB_8888 bitmaps.
|
||||
// However, this will be used to distinguish between the lower quality 1bpp and 4 bpp
|
||||
// images and the higher quality images.
|
||||
c = SkBitmap::kIndex8_Config;
|
||||
break;
|
||||
case 8:
|
||||
case 24:
|
||||
case 32:
|
||||
c = SkBitmap::kARGB_8888_Config;
|
||||
break;
|
||||
default:
|
||||
SkDEBUGF(("Image with %ibpp not supported\n", bitCount));
|
||||
continue;
|
||||
}
|
||||
chooser->inspect(i, c, width, height);
|
||||
}
|
||||
choice = chooser->choose();
|
||||
}
|
||||
|
||||
//you never know what the chooser is going to supply
|
||||
if (choice >= count || choice < 0) {
|
||||
return kFailure;
|
||||
}
|
||||
#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
|
||||
//otherwise, they could be used for error checking
|
||||
int w = readByte(buf, 6 + choice*16);
|
||||
int h = readByte(buf, 7 + choice*16);
|
||||
int colorCount = readByte(buf, 8 + choice*16);
|
||||
int w = readByte(buf, 6);
|
||||
int h = readByte(buf, 7);
|
||||
int colorCount = readByte(buf, 8);
|
||||
//int reservedToo = readByte(buf, 9 + choice*16); //0
|
||||
//int planes = read2Bytes(buf, 10 + choice*16); //1 - but often 0
|
||||
//int fakeBitCount = read2Bytes(buf, 12 + choice*16); //should be real - usually 0
|
||||
const size_t size = read4Bytes(buf, 14 + choice*16); //matters?
|
||||
const size_t offset = read4Bytes(buf, 18 + choice*16);
|
||||
const size_t size = read4Bytes(buf, 14); //matters?
|
||||
const size_t offset = read4Bytes(buf, 18);
|
||||
// promote the sum to 64-bits to avoid overflow
|
||||
if (offset > length || size > length || ((uint64_t)offset + size) > length) {
|
||||
return kFailure;
|
||||
|
@ -640,13 +640,6 @@ SkImageDecoder::Result SkJPEGImageDecoder::onDecode(SkStream* stream, SkBitmap*
|
||||
}
|
||||
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_failure(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
|
||||
// individual pixel. It is very unlikely to be opaque, since
|
||||
|
@ -614,12 +614,6 @@ bool SkPNGImageDecoder::getBitmapColorType(png_structp png_ptr, png_infop info_p
|
||||
}
|
||||
}
|
||||
|
||||
#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 colortype is 8888.
|
||||
if (this->getRequireUnpremultipliedColors() && *hasAlphap) {
|
||||
|
@ -303,12 +303,6 @@ 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)) {
|
||||
if (this->getRequireUnpremultipliedColors()) {
|
||||
@ -390,14 +384,6 @@ 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);
|
||||
|
@ -47,13 +47,6 @@ SkImageDecoder::Result SkPKMImageDecoder::onDecode(SkStream* stream, SkBitmap* b
|
||||
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 kFailure;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Setup the sampler...
|
||||
SkScaledBitmapSampler sampler(width, height, this->getSampleSize());
|
||||
|
||||
|
@ -68,12 +68,6 @@ 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;
|
||||
}
|
||||
@ -85,12 +79,6 @@ bool SkImageDecoder::cropBitmap(SkBitmap*, SkBitmap*, int, int, int, int, int,
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEDECODER_CHOOSER
|
||||
bool SkImageDecoder::chooseFromOneChoice(SkColorType, int, int) const {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool SkImageDecoder::allocPixelRef(SkBitmap*, SkColorTable*) const {
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user