Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Unified Diff: src/codec/SkWebpCodec.cpp

Issue 2319293003: Checking for valid colorType, alphaType, colorSpace in SkCodec (Closed)
Patch Set: Fix nanobench Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/codec/SkRawCodec.cpp ('k') | tests/CodecTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/codec/SkWebpCodec.cpp
diff --git a/src/codec/SkWebpCodec.cpp b/src/codec/SkWebpCodec.cpp
index 0c3aa402bd70bfd2659b01d8468d4cfa252be82a..e8b27b2178fa98b76fa7afd6cf629e1366171632 100644
--- a/src/codec/SkWebpCodec.cpp
+++ b/src/codec/SkWebpCodec.cpp
@@ -144,25 +144,6 @@ SkCodec* SkWebpCodec::NewFromStream(SkStream* stream) {
streamDeleter.release(), demux.release(), std::move(data));
}
-static bool webp_conversion_possible(const SkImageInfo& dst, const SkImageInfo& src,
- SkColorSpaceXform* colorXform) {
- if (!valid_alpha(dst.alphaType(), src.alphaType())) {
- return false;
- }
-
- switch (dst.colorType()) {
- case kRGBA_F16_SkColorType:
- return nullptr != colorXform;
- case kBGRA_8888_SkColorType:
- case kRGBA_8888_SkColorType:
- return true;
- case kRGB_565_SkColorType:
- return nullptr == colorXform && src.alphaType() == kOpaque_SkAlphaType;
- default:
- return false;
- }
-}
-
SkISize SkWebpCodec::onGetScaledDimensions(float desiredScale) const {
SkISize dim = this->getInfo().dimensions();
// SkCodec treats zero dimensional images as errors, so the minimum size
@@ -212,15 +193,15 @@ bool SkWebpCodec::onGetValidSubset(SkIRect* desiredSubset) const {
SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst, size_t rowBytes,
const Options& options, SkPMColor*, int*,
int* rowsDecodedPtr) {
+ if (!conversion_possible(dstInfo, this->getInfo())) {
+ return kInvalidConversion;
+ }
std::unique_ptr<SkColorSpaceXform> colorXform = nullptr;
if (needs_color_xform(dstInfo, this->getInfo())) {
colorXform = SkColorSpaceXform::New(sk_ref_sp(this->getInfo().colorSpace()),
sk_ref_sp(dstInfo.colorSpace()));
- }
-
- if (!webp_conversion_possible(dstInfo, this->getInfo(), colorXform.get())) {
- return kInvalidConversion;
+ SkASSERT(colorXform);
}
WebPDecoderConfig config;
« no previous file with comments | « src/codec/SkRawCodec.cpp ('k') | tests/CodecTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698