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