Index: gm/downsamplebitmap.cpp |
diff --git a/gm/downsamplebitmap.cpp b/gm/downsamplebitmap.cpp |
index a99bae0cd998937cec663fef3d29fcef9d0f07da..771eb6ab53d34c8b75ae246b777eb3f09e850e45 100644 |
--- a/gm/downsamplebitmap.cpp |
+++ b/gm/downsamplebitmap.cpp |
@@ -10,6 +10,7 @@ |
#include "Resources.h" |
#include "SkGradientShader.h" |
#include "SkTypeface.h" |
+#include "SkImageDecoder.h" |
#include "SkStream.h" |
#include "SkPaint.h" |
@@ -170,11 +171,21 @@ |
int fSize; |
void make_bitmap() override { |
- if (!GetResourceAsBitmap(fFilename.c_str(), &fBM)) { |
- fBM.allocN32Pixels(1, 1); |
- fBM.eraseARGB(255, 255, 0 , 0); // red == bad |
- } |
- fSize = fBM.height(); |
+ SkImageDecoder* codec = nullptr; |
+ SkString resourcePath = GetResourcePath(fFilename.c_str()); |
+ SkFILEStream stream(resourcePath.c_str()); |
+ if (stream.isValid()) { |
+ codec = SkImageDecoder::Factory(&stream); |
+ } |
+ if (codec) { |
+ stream.rewind(); |
+ codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode); |
+ delete codec; |
+ } else { |
+ fBM.allocN32Pixels(1, 1); |
+ *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad |
+ } |
+ fSize = fBM.height(); |
} |
private: |
typedef DownsampleBitmapGM INHERITED; |