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

Unified Diff: src/images/SkImageDecoder_libpng.cpp

Issue 1506663002: SkPNGImageEncoder encodes all SkColorTypes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-12-07 (Monday) 16:33:43 EST Created 5 years 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/images/SkImageDecoder_libpng.cpp
diff --git a/src/images/SkImageDecoder_libpng.cpp b/src/images/SkImageDecoder_libpng.cpp
index a03ed10453f70d8053dc72bafee1bae8f8f5ae3f..fd09ce95b0eaafb27065e4c3a5c204583c101c70 100644
--- a/src/images/SkImageDecoder_libpng.cpp
+++ b/src/images/SkImageDecoder_libpng.cpp
@@ -827,10 +827,28 @@ private:
typedef SkImageEncoder INHERITED;
};
-bool SkPNGImageEncoder::onEncode(SkWStream* stream, const SkBitmap& bitmap, int /*quality*/) {
- SkColorType ct = bitmap.colorType();
+bool SkPNGImageEncoder::onEncode(SkWStream* stream,
+ const SkBitmap& originalBitmap,
+ int /*quality*/) {
+ SkBitmap copy;
+ const SkBitmap* bitmap = &originalBitmap;
+ switch (originalBitmap.colorType()) {
+ case kIndex_8_SkColorType:
+ case kN32_SkColorType:
+ case kARGB_4444_SkColorType:
+ case kRGB_565_SkColorType:
+ break;
+ default:
+ // TODO(scroggo): support 8888-but-not-N32 natively.
+ // TODO(scroggo): support kGray_8 directly.
+ // TODO(scroggo): support Alpha_8 as Grayscale(black)+Alpha
+ if (originalBitmap.copyTo(&copy, kN32_SkColorType)) {
+ bitmap = ©
+ }
+ }
+ SkColorType ct = bitmap->colorType();
- const bool hasAlpha = !bitmap.isOpaque();
+ const bool hasAlpha = !bitmap->isOpaque();
int colorType = PNG_COLOR_MASK_COLOR;
int bitDepth = 8; // default for color
png_color_8 sig_bit;
@@ -870,14 +888,14 @@ bool SkPNGImageEncoder::onEncode(SkWStream* stream, const SkBitmap& bitmap, int
sig_bit.alpha = 0;
}
- SkAutoLockPixels alp(bitmap);
+ SkAutoLockPixels alp(*bitmap);
// readyToDraw checks for pixels (and colortable if that is required)
- if (!bitmap.readyToDraw()) {
+ if (!bitmap->readyToDraw()) {
return false;
}
// we must do this after we have locked the pixels
- SkColorTable* ctable = bitmap.getColorTable();
+ SkColorTable* ctable = bitmap->getColorTable();
if (ctable) {
if (ctable->count() == 0) {
return false;
@@ -886,7 +904,7 @@ bool SkPNGImageEncoder::onEncode(SkWStream* stream, const SkBitmap& bitmap, int
bitDepth = computeBitDepth(ctable->count());
}
- return doEncode(stream, bitmap, hasAlpha, colorType, bitDepth, ct, sig_bit);
+ return doEncode(stream, *bitmap, hasAlpha, colorType, bitDepth, ct, sig_bit);
}
bool SkPNGImageEncoder::doEncode(SkWStream* stream, const SkBitmap& bitmap,
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698