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

Unified Diff: tools/skimage_main.cpp

Issue 25964003: In skimage, copy to 8888 if encoding fails. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Respond to comments. Created 7 years, 2 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/skimage_main.cpp
diff --git a/tools/skimage_main.cpp b/tools/skimage_main.cpp
index 0d60f8afe96ddcd86a6a8141429a30402ea3a53b..11aeb766fbfe25d029d76292ce2fcb03ed2ce038 100644
--- a/tools/skimage_main.cpp
+++ b/tools/skimage_main.cpp
@@ -111,19 +111,22 @@ static SkBitmap::Config gPrefConfig(SkBitmap::kNo_Config);
SkAutoTUnref<skiagm::JsonExpectationsSource> gJsonExpectations;
static bool write_bitmap(const char outName[], const SkBitmap& bm) {
- const SkBitmap* bmPtr;
+ if (SkImageEncoder::EncodeFile(outName, bm, SkImageEncoder::kPNG_Type, 100)) {
+ return true;
+ }
+
+ if (bm.config() == SkBitmap::kARGB_8888_Config) {
+ // First attempt at encoding failed, and the bitmap was already 8888. Making
+ // a copy is not going to help.
+ return false;
+ }
+
+ // Encoding failed. Copy to 8888 and try again.
SkBitmap bm8888;
- if (bm.config() == SkBitmap::kA8_Config) {
- // Copy A8 into ARGB_8888, since our image encoders do not currently
- // support A8.
- if (!bm.copyTo(&bm8888, SkBitmap::kARGB_8888_Config)) {
- return false;
- }
- bmPtr = &bm8888;
- } else {
- bmPtr = &bm;
+ if (!bm.copyTo(&bm8888, SkBitmap::kARGB_8888_Config)) {
+ return false;
}
- return SkImageEncoder::EncodeFile(outName, *bmPtr, SkImageEncoder::kPNG_Type, 100);
+ return SkImageEncoder::EncodeFile(outName, bm8888, SkImageEncoder::kPNG_Type, 100);
}
/**
« 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