return kSuccess;
}
-SkCodec::Result SkBmpMaskCodec::prepareToDecode(const SkImageInfo& dstInfo,
- const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputColorCount) {
- // Initialize the mask swizzler
+bool SkBmpMaskCodec::initializeSwizzler(const SkImageInfo& dstInfo, const Options& options) {
+ // Create the swizzler
fMaskSwizzler.reset(SkMaskSwizzler::CreateMaskSwizzler(dstInfo, this->getInfo(), fMasks,
this->bitsPerPixel(), options));
- SkASSERT(fMaskSwizzler);
+
+ if (nullptr == fMaskSwizzler.get()) {
+ return false;
+ }
+
+ return true;
+}
+
+SkCodec::Result SkBmpMaskCodec::prepareToDecode(const SkImageInfo& dstInfo,
+ const SkCodec::Options& options, SkPMColor inputColorPtr[], int* inputColorCount) {
+ // Initialize a the mask swizzler
+ if (!this->initializeSwizzler(dstInfo, options)) {
+ SkCodecPrintf("Error: cannot initialize swizzler.\n");
+ return SkCodec::kInvalidConversion;
+ }
return SkCodec::kSuccess;
}
private:
+ bool initializeSwizzler(const SkImageInfo& dstInfo, const Options& options);
SkSampler* getSampler(bool createIfNecessary) override {
SkASSERT(fMaskSwizzler);
return fMaskSwizzler;
return true;
}
-void SkBmpStandardCodec::initializeSwizzler(const SkImageInfo& dstInfo, const Options& opts) {
+bool SkBmpStandardCodec::initializeSwizzler(const SkImageInfo& dstInfo, const Options& opts) {
// Get swizzler configuration
- SkSwizzler::SrcConfig config = SkSwizzler::kUnknown;
+ SkSwizzler::SrcConfig config;
switch (this->bitsPerPixel()) {
case 1:
config = SkSwizzler::kIndex1;
break;
default:
SkASSERT(false);
+ return false;
}
// Get a pointer to the color table if it exists
// Create swizzler
fSwizzler.reset(SkSwizzler::CreateSwizzler(config, colorPtr, dstInfo, opts));
- SkASSERT(fSwizzler);
+
+ if (nullptr == fSwizzler.get()) {
+ return false;
+ }
+ return true;
}
SkCodec::Result SkBmpStandardCodec::prepareToDecode(const SkImageInfo& dstInfo,
// Copy the color table to the client if necessary
copy_color_table(dstInfo, this->fColorTable, inputColorPtr, inputColorCount);
- // Initialize a swizzler
- this->initializeSwizzler(dstInfo, options);
+ // Initialize a swizzler if necessary
+ if (!this->initializeSwizzler(dstInfo, options)) {
+ SkCodecPrintf("Error: cannot initialize swizzler.\n");
+ return SkCodec::kInvalidConversion;
+ }
return SkCodec::kSuccess;
}
*/
bool createColorTable(SkAlphaType alphaType, int* colorCount);
- void initializeSwizzler(const SkImageInfo& dstInfo, const Options& opts);
+ bool initializeSwizzler(const SkImageInfo& dstInfo, const Options& opts);
int decodeRows(const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes,
const Options& opts) override;
ctable = nullptr;
}
+ {
+ SkAlphaType canonical;
+ if (!SkColorTypeValidateAlphaType(info.colorType(), info.alphaType(), &canonical)
+ || canonical != info.alphaType())
+ {
+ return kInvalidConversion;
+ }
+ }
+
if (!this->rewindIfNeeded()) {
return kCouldNotRewind;
}
case kN32_SkColorType:
return true;
case kRGB_565_SkColorType:
- return kOpaque_SkAlphaType == dst.alphaType();
- case kGray_8_SkColorType:
- if (kOpaque_SkAlphaType != dst.alphaType()) {
- return false;
- }
- // Fall through
+ return src.alphaType() == kOpaque_SkAlphaType;
default:
return dst.colorType() == src.colorType();
}
// Initialize color table and copy to the client if necessary
this->initializeColorTable(dstInfo, inputColorPtr, inputColorCount);
- this->initializeSwizzler(dstInfo, opts);
- return kSuccess;
+ return this->initializeSwizzler(dstInfo, opts);
}
-void SkGifCodec::initializeSwizzler(const SkImageInfo& dstInfo, const Options& opts) {
+SkCodec::Result SkGifCodec::initializeSwizzler(const SkImageInfo& dstInfo, const Options& opts) {
const SkPMColor* colorPtr = get_color_ptr(fColorTable.get());
const SkIRect* frameRect = fFrameIsSubset ? &fFrameRect : nullptr;
fSwizzler.reset(SkSwizzler::CreateSwizzler(SkSwizzler::kIndex, colorPtr, dstInfo, opts,
frameRect));
- SkASSERT(fSwizzler);
+
+ if (nullptr != fSwizzler.get()) {
+ return kSuccess;
+ }
+ return kUnimplemented;
}
bool SkGifCodec::readRow() {
* @param options Informs the swizzler if destination memory is zero initialized.
* Contains subset information.
*/
- void initializeSwizzler(const SkImageInfo& dstInfo,
+ Result initializeSwizzler(const SkImageInfo& dstInfo,
const Options& options);
SkSampler* getSampler(bool createIfNecessary) override {
}
fSwizzler.reset(SkSwizzler::CreateSwizzler(srcConfig, nullptr, dstInfo, options));
- SkASSERT(fSwizzler);
fStorage.reset(get_row_bytes(fDecoderMgr->dinfo()));
fSrcRow = fStorage.get();
}
}
}
-static inline bool valid_color_type(SkColorType colorType, SkAlphaType alphaType) {
- switch (colorType) {
- case kN32_SkColorType:
- case kIndex_8_SkColorType:
- return true;
- case kGray_8_SkColorType:
- case kRGB_565_SkColorType:
- return kOpaque_SkAlphaType == alphaType;
- default:
- return false;
- }
-}
-
static bool read_byte(SkStream* stream, uint8_t* data)
{
return stream->read(data, 1) == 1;
SkSwizzler* SkWbmpCodec::initializeSwizzler(const SkImageInfo& info, const SkPMColor* ctable,
const Options& opts) {
+ // Create the swizzler based on the desired color type
+ switch (info.colorType()) {
+ case kIndex_8_SkColorType:
+ case kN32_SkColorType:
+ case kRGB_565_SkColorType:
+ case kGray_8_SkColorType:
+ break;
+ default:
+ return nullptr;
+ }
return SkSwizzler::CreateSwizzler(SkSwizzler::kBit, ctable, info, opts);
}
return kUnimplemented;
}
- if (!valid_color_type(info.colorType(), info.alphaType()) ||
- !valid_alpha(info.alphaType(), this->getInfo().alphaType())) {
+ if (!valid_alpha(info.alphaType(), this->getInfo().alphaType())) {
return kInvalidConversion;
}
// Initialize the swizzler
SkAutoTDelete<SkSwizzler> swizzler(this->initializeSwizzler(info, ctable, options));
- SkASSERT(swizzler);
+ if (nullptr == swizzler.get()) {
+ return kInvalidConversion;
+ }
// Perform the decode
SkISize size = info.dimensions();
return kUnimplemented;
}
- if (!valid_color_type(dstInfo.colorType(), dstInfo.alphaType()) ||
- !valid_alpha(dstInfo.alphaType(), this->getInfo().alphaType())) {
+ if (!valid_alpha(dstInfo.alphaType(), this->getInfo().alphaType())) {
return kInvalidConversion;
}
// Initialize the swizzler
fSwizzler.reset(this->initializeSwizzler(dstInfo, get_color_ptr(fColorTable.get()), options));
- SkASSERT(fSwizzler);
+ if (nullptr == fSwizzler.get()) {
+ return kInvalidConversion;
+ }
fSrcBuffer.reset(fSrcRowBytes);