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); |
} |
/** |