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

Unified Diff: src/codec/SkPngCodec.cpp

Issue 2328663002: Revert of Checking for valid colorType, alphaType, colorSpace in SkCodec (Closed)
Patch Set: 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 bfa695773d22baa6793014b4c1bd013b29eb0526..ac7238d3e904f284ac182fc769a90c1166946b6f 100644
--- a/src/codec/SkPngCodec.cpp
+++ b/src/codec/SkPngCodec.cpp
@@ -355,6 +355,25 @@
// Note that we will have to change this implementation if we start
// supporting outputs from libpng that are less than 8-bits per component.
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) {
@@ -403,7 +422,7 @@
Result onStartScanlineDecode(const SkImageInfo& dstInfo, const Options& options,
SkPMColor ctable[], int* ctableCount) override {
- if (!conversion_possible(dstInfo, this->getInfo()) ||
+ if (!png_conversion_possible(dstInfo, this->getInfo()) ||
!this->initializeXforms(dstInfo, options, ctable, ctableCount))
{
return kInvalidConversion;
@@ -470,7 +489,7 @@
Result onStartScanlineDecode(const SkImageInfo& dstInfo, const Options& options,
SkPMColor ctable[], int* ctableCount) override {
- if (!conversion_possible(dstInfo, this->getInfo()) ||
+ if (!png_conversion_possible(dstInfo, this->getInfo()) ||
!this->initializeXforms(dstInfo, options, ctable, ctableCount))
{
return kInvalidConversion;
@@ -788,10 +807,20 @@
fSwizzler.reset(nullptr);
fColorXform = nullptr;
- if (needs_color_xform(dstInfo, this->getInfo())) {
+ bool needsColorXform = needs_color_xform(dstInfo, this->getInfo());
+ if (needsColorXform) {
+ if (kGray_8_SkColorType == dstInfo.colorType() ||
+ kRGB_565_SkColorType == dstInfo.colorType())
+ {
+ return false;
+ }
+
fColorXform = SkColorSpaceXform::New(sk_ref_sp(this->getInfo().colorSpace()),
sk_ref_sp(dstInfo.colorSpace()));
- SkASSERT(fColorXform);
+
+ if (!fColorXform && kRGBA_F16_SkColorType == dstInfo.colorType()) {
+ return false;
+ }
}
// If the image is RGBA and we have a color xform, we can skip the swizzler.
@@ -878,7 +907,7 @@
size_t rowBytes, const Options& options,
SkPMColor ctable[], int* ctableCount,
int* rowsDecoded) {
- if (!conversion_possible(dstInfo, this->getInfo()) ||
+ if (!png_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