OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 | 9 |
10 #include "Resources.h" | 10 #include "Resources.h" |
11 #include "SkBitmapProcState.h" | 11 #include "SkBitmapProcState.h" |
12 #include "SkBitmapScaler.h" | 12 #include "SkBitmapScaler.h" |
13 #include "SkGradientShader.h" | 13 #include "SkGradientShader.h" |
| 14 #include "SkImageDecoder.h" |
14 #include "SkImageEncoder.h" | 15 #include "SkImageEncoder.h" |
15 #include "SkStream.h" | 16 #include "SkStream.h" |
16 #include "SkTypeface.h" | 17 #include "SkTypeface.h" |
17 | 18 |
18 static SkSize computeSize(const SkBitmap& bm, const SkMatrix& mat) { | 19 static SkSize computeSize(const SkBitmap& bm, const SkMatrix& mat) { |
19 SkRect bounds = SkRect::MakeWH(SkIntToScalar(bm.width()), | 20 SkRect bounds = SkRect::MakeWH(SkIntToScalar(bm.width()), |
20 SkIntToScalar(bm.height())); | 21 SkIntToScalar(bm.height())); |
21 mat.mapRect(&bounds); | 22 mat.mapRect(&bounds); |
22 return SkSize::Make(bounds.width(), bounds.height()); | 23 return SkSize::Make(bounds.width(), bounds.height()); |
23 } | 24 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 | 92 |
92 protected: | 93 protected: |
93 SkString fFilename; | 94 SkString fFilename; |
94 int fSize; | 95 int fSize; |
95 | 96 |
96 SkScalar getScale() { | 97 SkScalar getScale() { |
97 return 192.f/fSize; | 98 return 192.f/fSize; |
98 } | 99 } |
99 | 100 |
100 void makeBitmap() { | 101 void makeBitmap() { |
101 if (!GetResourceAsBitmap(fFilename.c_str(), &fBM)) { | 102 SkImageDecoder* codec = nullptr; |
102 fBM.allocN32Pixels(1, 1); | 103 SkString resourcePath = GetResourcePath(fFilename.c_str()); |
103 fBM.eraseARGB(255, 255, 0 , 0); // red == bad | 104 SkFILEStream stream(resourcePath.c_str()); |
104 } | 105 if (stream.isValid()) { |
105 fSize = fBM.height(); | 106 codec = SkImageDecoder::Factory(&stream); |
| 107 } |
| 108 if (codec) { |
| 109 stream.rewind(); |
| 110 codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDe
codePixels_Mode); |
| 111 delete codec; |
| 112 } else { |
| 113 fBM.allocN32Pixels(1, 1); |
| 114 *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad |
| 115 } |
| 116 fSize = fBM.height(); |
106 } | 117 } |
107 private: | 118 private: |
108 typedef skiagm::GM INHERITED; | 119 typedef skiagm::GM INHERITED; |
109 }; | 120 }; |
110 | 121 |
111 ////////////////////////////////////////////////////////////////////////////// | 122 ////////////////////////////////////////////////////////////////////////////// |
112 | 123 |
113 | 124 |
114 DEF_GM( return new FilterIndiaBoxGM("box.gif"); ) | 125 DEF_GM( return new FilterIndiaBoxGM("box.gif"); ) |
OLD | NEW |