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

Unified Diff: src/codec/SkPngCodec.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/SkJpegCodec.cpp ('k') | src/codec/SkRawCodec.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/codec/SkPngCodec.cpp
diff --git a/src/codec/SkPngCodec.cpp b/src/codec/SkPngCodec.cpp
index 34e6f91131c3c696ed95d72ce292016e46c6e0ee..36ec21f0b8b2093f233134c5ad5f84bde3c221e1 100644
--- a/src/codec/SkPngCodec.cpp
+++ b/src/codec/SkPngCodec.cpp
@@ -357,25 +357,6 @@ static int bytes_per_pixel(int bitsPerPixel) {
return bitsPerPixel / 8;
}
-static bool png_conversion_possible(const SkImageInfo& dst, const SkImageInfo& src) {
- // Ensure the alpha type is valid
- if (!valid_alpha(dst.alphaType(), src.alphaType())) {
- return false;
- }
-
- // Check for supported color types
- switch (dst.colorType()) {
- case kRGBA_8888_SkColorType:
- case kBGRA_8888_SkColorType:
- case kRGBA_F16_SkColorType:
- return true;
- case kRGB_565_SkColorType:
- return kOpaque_SkAlphaType == src.alphaType();
- default:
- return dst.colorType() == src.colorType();
- }
-}
-
void SkPngCodec::allocateStorage(const SkImageInfo& dstInfo) {
switch (fXformMode) {
case kSwizzleOnly_XformMode:
@@ -422,7 +403,7 @@ public:
Result onStartScanlineDecode(const SkImageInfo& dstInfo, const Options& options,
SkPMColor ctable[], int* ctableCount) override {
- if (!png_conversion_possible(dstInfo, this->getInfo()) ||
+ if (!conversion_possible(dstInfo, this->getInfo()) ||
!this->initializeXforms(dstInfo, options, ctable, ctableCount))
{
return kInvalidConversion;
@@ -489,7 +470,7 @@ public:
Result onStartScanlineDecode(const SkImageInfo& dstInfo, const Options& options,
SkPMColor ctable[], int* ctableCount) override {
- if (!png_conversion_possible(dstInfo, this->getInfo()) ||
+ if (!conversion_possible(dstInfo, this->getInfo()) ||
!this->initializeXforms(dstInfo, options, ctable, ctableCount))
{
return kInvalidConversion;
@@ -807,20 +788,10 @@ bool SkPngCodec::initializeXforms(const SkImageInfo& dstInfo, const Options& opt
fSwizzler.reset(nullptr);
fColorXform = nullptr;
- bool needsColorXform = needs_color_xform(dstInfo, this->getInfo());
- if (needsColorXform) {
- if (kGray_8_SkColorType == dstInfo.colorType() ||
- kRGB_565_SkColorType == dstInfo.colorType())
- {
- return false;
- }
-
+ if (needs_color_xform(dstInfo, this->getInfo())) {
fColorXform = SkColorSpaceXform::New(sk_ref_sp(this->getInfo().colorSpace()),
sk_ref_sp(dstInfo.colorSpace()));
-
- if (!fColorXform && kRGBA_F16_SkColorType == dstInfo.colorType()) {
- return false;
- }
+ SkASSERT(fColorXform);
}
// If the image is RGBA and we have a color xform, we can skip the swizzler.
@@ -907,7 +878,7 @@ SkCodec::Result SkPngCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst,
size_t rowBytes, const Options& options,
SkPMColor ctable[], int* ctableCount,
int* rowsDecoded) {
- if (!png_conversion_possible(dstInfo, this->getInfo()) ||
+ if (!conversion_possible(dstInfo, this->getInfo()) ||
!this->initializeXforms(dstInfo, options, ctable, ctableCount))
{
return kInvalidConversion;
« no previous file with comments | « src/codec/SkJpegCodec.cpp ('k') | src/codec/SkRawCodec.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698