Index: src/codec/SkWbmpCodec.cpp |
diff --git a/src/codec/SkWbmpCodec.cpp b/src/codec/SkWbmpCodec.cpp |
index dd6699473040bed3fd79001321a8d28299dc48ff..4dd0f2544d181f848dde3b0cf015967e69f12518 100644 |
--- a/src/codec/SkWbmpCodec.cpp |
+++ b/src/codec/SkWbmpCodec.cpp |
@@ -27,19 +27,6 @@ |
colorPtr[0] = SK_ColorBLACK; |
colorPtr[1] = SK_ColorWHITE; |
*colorCount = 2; |
- } |
-} |
- |
-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; |
} |
} |
@@ -97,6 +84,16 @@ |
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); |
} |
@@ -127,8 +124,7 @@ |
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; |
} |
@@ -137,7 +133,9 @@ |
// 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(); |
@@ -190,8 +188,7 @@ |
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; |
} |
@@ -205,7 +202,9 @@ |
// 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); |