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

Unified Diff: src/codec/SkPngCodec.cpp

Issue 2212563003: Modify SkPngCodec to recognize 565 images from the sBIT chunk (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Allow SkPngCodec to set SkImageInfo directly Created 4 years, 4 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/SkPngCodec.h ('k') | tests/CodecTest.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 60f7b9b866518dc5ee6679f0a8a1028524417f61..0d13e6ac2e70fc73606e99e65e3e15c36f67f6db 100644
--- a/src/codec/SkPngCodec.cpp
+++ b/src/codec/SkPngCodec.cpp
@@ -370,11 +370,10 @@ void SkPngCodec::allocateStorage(const SkImageInfo& dstInfo) {
class SkPngNormalCodec : public SkPngCodec {
public:
- SkPngNormalCodec(int width, int height, const SkEncodedInfo& info, SkStream* stream,
- SkPngChunkReader* chunkReader, png_structp png_ptr, png_infop info_ptr, int bitDepth,
- sk_sp<SkColorSpace> colorSpace)
- : INHERITED(width, height, info, stream, chunkReader, png_ptr, info_ptr, bitDepth, 1,
- colorSpace)
+ SkPngNormalCodec(const SkEncodedInfo& encodedInfo, const SkImageInfo& imageInfo,
+ SkStream* stream, SkPngChunkReader* chunkReader, png_structp png_ptr,
+ png_infop info_ptr, int bitDepth)
+ : INHERITED(encodedInfo, imageInfo, stream, chunkReader, png_ptr, info_ptr, bitDepth, 1)
{}
Result onStartScanlineDecode(const SkImageInfo& dstInfo, const Options& options,
@@ -447,11 +446,11 @@ public:
class SkPngInterlacedCodec : public SkPngCodec {
public:
- SkPngInterlacedCodec(int width, int height, const SkEncodedInfo& info,
+ SkPngInterlacedCodec(const SkEncodedInfo& encodedInfo, const SkImageInfo& imageInfo,
SkStream* stream, SkPngChunkReader* chunkReader, png_structp png_ptr,
- png_infop info_ptr, int bitDepth, int numberPasses, sk_sp<SkColorSpace> colorSpace)
- : INHERITED(width, height, info, stream, chunkReader, png_ptr, info_ptr, bitDepth,
- numberPasses, colorSpace)
+ png_infop info_ptr, int bitDepth, int numberPasses)
+ : INHERITED(encodedInfo, imageInfo, stream, chunkReader, png_ptr, info_ptr, bitDepth,
+ numberPasses)
, fCanSkipRewind(false)
{
SkASSERT(numberPasses != 1);
@@ -723,30 +722,41 @@ static bool read_header(SkStream* stream, SkPngChunkReader* chunkReader, SkCodec
colorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
}
- SkEncodedInfo info = SkEncodedInfo::Make(color, alpha, 8);
+ SkEncodedInfo encodedInfo = SkEncodedInfo::Make(color, alpha, 8);
+ SkImageInfo imageInfo = encodedInfo.makeImageInfo(origWidth, origHeight, colorSpace);
+
+ if (SkEncodedInfo::kOpaque_Alpha == alpha) {
+ png_color_8p sigBits;
+ if (png_get_sBIT(png_ptr, info_ptr, &sigBits)) {
+ if (5 == sigBits->red && 6 == sigBits->green && 5 == sigBits->blue) {
+ // Recommend a decode to 565 if the sBIT indicates 565.
+ imageInfo = imageInfo.makeColorType(kRGB_565_SkColorType);
+ }
+ }
+ }
if (1 == numberPasses) {
- *outCodec = new SkPngNormalCodec(origWidth, origHeight, info, stream,
- chunkReader, png_ptr, info_ptr, bitDepth, colorSpace);
+ *outCodec = new SkPngNormalCodec(encodedInfo, imageInfo, stream,
+ chunkReader, png_ptr, info_ptr, bitDepth);
} else {
- *outCodec = new SkPngInterlacedCodec(origWidth, origHeight, info, stream,
- chunkReader, png_ptr, info_ptr, bitDepth, numberPasses, colorSpace);
+ *outCodec = new SkPngInterlacedCodec(encodedInfo, imageInfo, stream,
+ chunkReader, png_ptr, info_ptr, bitDepth, numberPasses);
}
}
return true;
}
-SkPngCodec::SkPngCodec(int width, int height, const SkEncodedInfo& info, SkStream* stream,
- SkPngChunkReader* chunkReader, png_structp png_ptr, png_infop info_ptr,
- int bitDepth, int numberPasses, sk_sp<SkColorSpace> colorSpace)
- : INHERITED(width, height, info, stream, colorSpace)
+SkPngCodec::SkPngCodec(const SkEncodedInfo& encodedInfo, const SkImageInfo& imageInfo,
+ SkStream* stream, SkPngChunkReader* chunkReader, png_structp png_ptr,
+ png_infop info_ptr, int bitDepth, int numberPasses)
+ : INHERITED(encodedInfo, imageInfo, stream)
, fPngChunkReader(SkSafeRef(chunkReader))
, fPng_ptr(png_ptr)
, fInfo_ptr(info_ptr)
, fSwizzlerSrcRow(nullptr)
, fColorXformSrcRow(nullptr)
- , fSrcRowBytes(width * (bytes_per_pixel(this->getEncodedInfo().bitsPerPixel())))
+ , fSrcRowBytes(imageInfo.width() * (bytes_per_pixel(this->getEncodedInfo().bitsPerPixel())))
, fNumberPasses(numberPasses)
, fBitDepth(bitDepth)
{}
« no previous file with comments | « src/codec/SkPngCodec.h ('k') | tests/CodecTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698