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

Unified Diff: src/codec/SkPngCodec.cpp

Issue 2319293003: 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
Index: src/codec/SkPngCodec.cpp
diff --git a/src/codec/SkPngCodec.cpp b/src/codec/SkPngCodec.cpp
index ac7238d3e904f284ac182fc769a90c1166946b6f..db4819147d0a47b8a89aec8f1cb9c4d94d1832be 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;
@@ -809,16 +790,11 @@ bool SkPngCodec::initializeXforms(const SkImageInfo& dstInfo, const Options& opt
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()));
- if (!fColorXform && kRGBA_F16_SkColorType == dstInfo.colorType()) {
+ // TODO (msarett): Possibly working toward asserting this?
+ if (!fColorXform) {
return false;
}
}
@@ -907,7 +883,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;

Powered by Google App Engine
This is Rietveld 408576698