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 "SkData.h" | |
12 #include "SkImage.h" | |
11 #include "SkGradientShader.h" | 13 #include "SkGradientShader.h" |
12 #include "SkImageDecoder.h" | |
13 #include "SkStream.h" | 14 #include "SkStream.h" |
14 #include "SkTypeface.h" | 15 #include "SkTypeface.h" |
15 | 16 |
16 static void setTypeface(SkPaint* paint, const char name[], SkTypeface::Style sty le) { | 17 static void setTypeface(SkPaint* paint, const char name[], SkTypeface::Style sty le) { |
17 sk_tool_utils::set_portable_typeface(paint, name, style); | 18 sk_tool_utils::set_portable_typeface(paint, name, style); |
18 } | 19 } |
19 | 20 |
20 static SkSize computeSize(const SkBitmap& bm, const SkMatrix& mat) { | 21 static SkSize computeSize(const SkBitmap& bm, const SkMatrix& mat) { |
21 SkRect bounds = SkRect::MakeWH(SkIntToScalar(bm.width()), | 22 SkRect bounds = SkRect::MakeWH(SkIntToScalar(bm.width()), |
22 SkIntToScalar(bm.height())); | 23 SkIntToScalar(bm.height())); |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 | 190 |
190 protected: | 191 protected: |
191 SkString fFilename; | 192 SkString fFilename; |
192 int fSize; | 193 int fSize; |
193 | 194 |
194 SkScalar getScale() override { | 195 SkScalar getScale() override { |
195 return 192.f/fSize; | 196 return 192.f/fSize; |
196 } | 197 } |
197 | 198 |
198 void makeBitmap() override { | 199 void makeBitmap() override { |
199 SkImageDecoder* codec = nullptr; | 200 SkAutoTUnref<SkData> data(SkData::NewFromFileName( |
200 SkString resourcePath = GetResourcePath(fFilename.c_str()); | 201 GetResourcePath(fFilename.c_str()).c_str())); |
201 SkFILEStream stream(resourcePath.c_str()); | 202 SkAutoTDelete<SkImage> image(SkImage::NewFromEncoded(data)); |
202 if (stream.isValid()) { | 203 if (!image || !image->asLegacyBitmap(&fBM, SkImage::kRW_LegacyBitmapMode )) { |
scroggo
2016/03/17 13:05:48
GetResourceAsBitmap? Same for a few more files?
msarett
2016/03/17 13:53:38
Done.
| |
203 codec = SkImageDecoder::Factory(&stream); | 204 fBM.allocN32Pixels(1, 1); |
204 } | 205 fBM.eraseARGB(255, 255, 0 , 0); // red == bad |
205 if (codec) { | 206 } |
206 stream.rewind(); | 207 fSize = fBM.height(); |
207 codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDe codePixels_Mode); | 208 |
208 delete codec; | 209 if (fConvertToG8) { |
209 } else { | 210 SkBitmap tmp; |
210 fBM.allocN32Pixels(1, 1); | 211 fBM.copyTo(&tmp, kGray_8_SkColorType); |
211 *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad | 212 fBM = tmp; |
212 } | 213 } |
213 fSize = fBM.height(); | |
214 if (fConvertToG8) { | |
215 SkBitmap tmp; | |
216 fBM.copyTo(&tmp, kGray_8_SkColorType); | |
217 fBM = tmp; | |
218 } | |
219 } | 214 } |
220 private: | 215 private: |
221 const bool fConvertToG8; | 216 const bool fConvertToG8; |
222 typedef FilterBitmapGM INHERITED; | 217 typedef FilterBitmapGM INHERITED; |
223 }; | 218 }; |
224 | 219 |
225 ////////////////////////////////////////////////////////////////////////////// | 220 ////////////////////////////////////////////////////////////////////////////// |
226 | 221 |
227 DEF_GM( return new FilterBitmapTextGM(3); ) | 222 DEF_GM( return new FilterBitmapTextGM(3); ) |
228 DEF_GM( return new FilterBitmapTextGM(7); ) | 223 DEF_GM( return new FilterBitmapTextGM(7); ) |
229 DEF_GM( return new FilterBitmapTextGM(10); ) | 224 DEF_GM( return new FilterBitmapTextGM(10); ) |
230 DEF_GM( return new FilterBitmapCheckerboardGM(4,4); ) | 225 DEF_GM( return new FilterBitmapCheckerboardGM(4,4); ) |
231 DEF_GM( return new FilterBitmapCheckerboardGM(32,32); ) | 226 DEF_GM( return new FilterBitmapCheckerboardGM(32,32); ) |
232 DEF_GM( return new FilterBitmapCheckerboardGM(32,32, true); ) | 227 DEF_GM( return new FilterBitmapCheckerboardGM(32,32, true); ) |
233 DEF_GM( return new FilterBitmapCheckerboardGM(32,8); ) | 228 DEF_GM( return new FilterBitmapCheckerboardGM(32,8); ) |
234 DEF_GM( return new FilterBitmapCheckerboardGM(32,2); ) | 229 DEF_GM( return new FilterBitmapCheckerboardGM(32,2); ) |
235 DEF_GM( return new FilterBitmapCheckerboardGM(192,192); ) | 230 DEF_GM( return new FilterBitmapCheckerboardGM(192,192); ) |
236 DEF_GM( return new FilterBitmapImageGM("mandrill_16.png"); ) | 231 DEF_GM( return new FilterBitmapImageGM("mandrill_16.png"); ) |
237 DEF_GM( return new FilterBitmapImageGM("mandrill_32.png"); ) | 232 DEF_GM( return new FilterBitmapImageGM("mandrill_32.png"); ) |
238 DEF_GM( return new FilterBitmapImageGM("mandrill_64.png"); ) | 233 DEF_GM( return new FilterBitmapImageGM("mandrill_64.png"); ) |
239 DEF_GM( return new FilterBitmapImageGM("mandrill_64.png", true); ) | 234 DEF_GM( return new FilterBitmapImageGM("mandrill_64.png", true); ) |
240 DEF_GM( return new FilterBitmapImageGM("mandrill_128.png"); ) | 235 DEF_GM( return new FilterBitmapImageGM("mandrill_128.png"); ) |
241 DEF_GM( return new FilterBitmapImageGM("mandrill_256.png"); ) | 236 DEF_GM( return new FilterBitmapImageGM("mandrill_256.png"); ) |
242 DEF_GM( return new FilterBitmapImageGM("mandrill_512.png"); ) | 237 DEF_GM( return new FilterBitmapImageGM("mandrill_512.png"); ) |
243 DEF_GM( return new FilterBitmapImageGM("color_wheel.png"); ) | 238 DEF_GM( return new FilterBitmapImageGM("color_wheel.png"); ) |
OLD | NEW |