aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/codec/SkWbmpCodec.cpp
diff options
context:
space:
mode:
authorGravatar msarett <msarett@google.com>2016-02-12 15:00:10 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-02-12 15:00:10 -0800
commitdeabdb5b9712de9e3c6bbb9aa68ec2f20df80a8e (patch)
treedf8951bf09f0dc3b1926d082340f65c3e756100a /src/codec/SkWbmpCodec.cpp
parent3478f753ffc28a6f0f0877cc06be7373f960c527 (diff)
Revert of Fix colorType/alphaType checks in SkCodec (patchset #5 id:80001 of https://codereview.chromium.org/1695473002/ )
Reason for revert: Really bad images in Gold. Original issue's description: > Fix colorType/alphaType checks in SkCodec > > Make getPixels() and startScanlineDecode() behave > consistently. > > Require that kGray8 decodes are opaque. > > Assert that creating the swizzler succeeds. > > BUG=skia:4203 > GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1695473002 > > Committed: https://skia.googlesource.com/skia/+/c7578b6cdd03b61f076ffc7956efd952d6c301c0 TBR=scroggo@google.com # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=skia:4203 Review URL: https://codereview.chromium.org/1694023002
Diffstat (limited to 'src/codec/SkWbmpCodec.cpp')
-rw-r--r--src/codec/SkWbmpCodec.cpp37
1 files changed, 18 insertions, 19 deletions
diff --git a/src/codec/SkWbmpCodec.cpp b/src/codec/SkWbmpCodec.cpp
index 706d5ddd46..af1ab46f73 100644
--- a/src/codec/SkWbmpCodec.cpp
+++ b/src/codec/SkWbmpCodec.cpp
@@ -30,19 +30,6 @@ static inline void setup_color_table(SkColorType colorType,
}
}
-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;
@@ -97,6 +84,16 @@ bool SkWbmpCodec::onRewind() {
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 @@ SkCodec::Result SkWbmpCodec::onGetPixels(const SkImageInfo& info,
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 @@ SkCodec::Result SkWbmpCodec::onGetPixels(const SkImageInfo& info,
// 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();
@@ -195,8 +193,7 @@ SkCodec::Result SkWbmpCodec::onStartScanlineDecode(const SkImageInfo& dstInfo,
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;
}
@@ -210,7 +207,9 @@ SkCodec::Result SkWbmpCodec::onStartScanlineDecode(const SkImageInfo& dstInfo,
// 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);