OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkImageDecoder.h" | 10 #include "SkImageDecoder.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 SkFILEStream stream(path.c_str()); | 28 SkFILEStream stream(path.c_str()); |
29 if (stream.isValid()) { | 29 if (stream.isValid()) { |
30 codec = SkImageDecoder::Factory(&stream); | 30 codec = SkImageDecoder::Factory(&stream); |
31 } | 31 } |
32 if (codec) { | 32 if (codec) { |
33 stream.rewind(); | 33 stream.rewind(); |
34 codec->decode(&stream, &fBM, SkBitmap::kARGB_8888_Config, | 34 codec->decode(&stream, &fBM, SkBitmap::kARGB_8888_Config, |
35 SkImageDecoder::kDecodePixels_Mode); | 35 SkImageDecoder::kDecodePixels_Mode); |
36 SkDELETE(codec); | 36 SkDELETE(codec); |
37 } else { | 37 } else { |
38 fBM.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); | 38 fBM.allocN32Pixels(1, 1); |
39 fBM.allocPixels(); | |
40 *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad | 39 *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad |
41 } | 40 } |
42 fSize = fBM.height(); | 41 fSize = fBM.height(); |
43 } | 42 } |
44 | 43 |
45 protected: | 44 protected: |
46 | 45 |
47 | 46 |
48 SkBitmap fBM; | 47 SkBitmap fBM; |
49 SkString fName; | 48 SkString fName; |
50 SkString fFilename; | 49 SkString fFilename; |
51 int fSize; | 50 int fSize; |
52 float fScale; | 51 float fScale; |
53 | 52 |
54 | 53 |
55 virtual SkString onShortName() SK_OVERRIDE { | 54 virtual SkString onShortName() SK_OVERRIDE { |
56 return fName; | 55 return fName; |
57 } | 56 } |
58 | 57 |
59 virtual SkISize onISize() SK_OVERRIDE { | 58 virtual SkISize onISize() SK_OVERRIDE { |
60 return SkISize::Make(fBM.width() * fScale, fBM.height() * fScale); | 59 return SkISize::Make(fBM.width() * fScale, fBM.height() * fScale); |
61 } | 60 } |
62 | 61 |
63 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 62 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
64 SkBitmap dst; | 63 SkBitmap dst; |
65 dst.setConfig(SkBitmap::kARGB_8888_Config, fBM.width() * fScale, fBM.hei
ght() * fScale); | 64 dst.allocN32Pixels(fBM.width() * fScale, fBM.height() * fScale); |
66 dst.allocPixels(); | |
67 fBM.scale(&dst); | 65 fBM.scale(&dst); |
68 | 66 |
69 canvas->drawBitmap(dst, 0, 0); | 67 canvas->drawBitmap(dst, 0, 0); |
70 } | 68 } |
71 | 69 |
72 private: | 70 private: |
73 typedef skiagm::GM INHERITED; | 71 typedef skiagm::GM INHERITED; |
74 }; | 72 }; |
75 | 73 |
76 class ScaleBitmapMipmapGM: public ScaleBitmapGM { | 74 class ScaleBitmapMipmapGM: public ScaleBitmapGM { |
(...skipping 27 matching lines...) Expand all Loading... |
104 | 102 |
105 DEF_GM( return new ScaleBitmapGM("nature.jpg", 0.5f); ) | 103 DEF_GM( return new ScaleBitmapGM("nature.jpg", 0.5f); ) |
106 DEF_GM( return new ScaleBitmapGM("nature.jpg", 0.25f); ) | 104 DEF_GM( return new ScaleBitmapGM("nature.jpg", 0.25f); ) |
107 DEF_GM( return new ScaleBitmapGM("nature.jpg", 0.125f); ) | 105 DEF_GM( return new ScaleBitmapGM("nature.jpg", 0.125f); ) |
108 DEF_GM( return new ScaleBitmapGM("nature.jpg", 0.0625f); ) | 106 DEF_GM( return new ScaleBitmapGM("nature.jpg", 0.0625f); ) |
109 | 107 |
110 DEF_GM( return new ScaleBitmapMipmapGM("nature.jpg", 0.5f); ) | 108 DEF_GM( return new ScaleBitmapMipmapGM("nature.jpg", 0.5f); ) |
111 DEF_GM( return new ScaleBitmapMipmapGM("nature.jpg", 0.25f); ) | 109 DEF_GM( return new ScaleBitmapMipmapGM("nature.jpg", 0.25f); ) |
112 DEF_GM( return new ScaleBitmapMipmapGM("nature.jpg", 0.125f); ) | 110 DEF_GM( return new ScaleBitmapMipmapGM("nature.jpg", 0.125f); ) |
113 DEF_GM( return new ScaleBitmapMipmapGM("nature.jpg", 0.0625f); ) | 111 DEF_GM( return new ScaleBitmapMipmapGM("nature.jpg", 0.0625f); ) |
OLD | NEW |