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 "Resources.h" | 10 #include "Resources.h" |
11 #include "SkGradientShader.h" | 11 #include "SkGradientShader.h" |
12 #include "SkTypeface.h" | 12 #include "SkTypeface.h" |
13 #include "SkImageDecoder.h" | |
14 #include "SkStream.h" | 13 #include "SkStream.h" |
15 #include "SkPaint.h" | 14 #include "SkPaint.h" |
16 | 15 |
17 static void make_checker(SkBitmap* bm, int size, int numChecks) { | 16 static void make_checker(SkBitmap* bm, int size, int numChecks) { |
18 bm->allocN32Pixels(size, size); | 17 bm->allocN32Pixels(size, size); |
19 for (int y = 0; y < size; ++y) { | 18 for (int y = 0; y < size; ++y) { |
20 for (int x = 0; x < size; ++x) { | 19 for (int x = 0; x < size; ++x) { |
21 SkPMColor* s = bm->getAddr32(x, y); | 20 SkPMColor* s = bm->getAddr32(x, y); |
22 int cx = (x * numChecks) / size; | 21 int cx = (x * numChecks) / size; |
23 int cy = (y * numChecks) / size; | 22 int cy = (y * numChecks) / size; |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 : INHERITED(filterQuality), fFilename(filename) | 163 : INHERITED(filterQuality), fFilename(filename) |
165 { | 164 { |
166 fName.printf("downsamplebitmap_image_%s_%s", this->filterQualityToSt
ring(), filename); | 165 fName.printf("downsamplebitmap_image_%s_%s", this->filterQualityToSt
ring(), filename); |
167 } | 166 } |
168 | 167 |
169 protected: | 168 protected: |
170 SkString fFilename; | 169 SkString fFilename; |
171 int fSize; | 170 int fSize; |
172 | 171 |
173 void make_bitmap() override { | 172 void make_bitmap() override { |
174 SkImageDecoder* codec = nullptr; | 173 if (!GetResourceAsBitmap(fFilename.c_str(), &fBM)) { |
175 SkString resourcePath = GetResourcePath(fFilename.c_str()); | 174 fBM.allocN32Pixels(1, 1); |
176 SkFILEStream stream(resourcePath.c_str()); | 175 fBM.eraseARGB(255, 255, 0 , 0); // red == bad |
177 if (stream.isValid()) { | 176 } |
178 codec = SkImageDecoder::Factory(&stream); | 177 fSize = fBM.height(); |
179 } | |
180 if (codec) { | |
181 stream.rewind(); | |
182 codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDe
codePixels_Mode); | |
183 delete codec; | |
184 } else { | |
185 fBM.allocN32Pixels(1, 1); | |
186 *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad | |
187 } | |
188 fSize = fBM.height(); | |
189 } | 178 } |
190 private: | 179 private: |
191 typedef DownsampleBitmapGM INHERITED; | 180 typedef DownsampleBitmapGM INHERITED; |
192 }; | 181 }; |
193 | 182 |
194 DEF_GM( return new DownsampleBitmapTextGM(72, kHigh_SkFilterQuality); ) | 183 DEF_GM( return new DownsampleBitmapTextGM(72, kHigh_SkFilterQuality); ) |
195 DEF_GM( return new DownsampleBitmapCheckerboardGM(512,256, kHigh_SkFilterQuality
); ) | 184 DEF_GM( return new DownsampleBitmapCheckerboardGM(512,256, kHigh_SkFilterQuality
); ) |
196 DEF_GM( return new DownsampleBitmapImageGM("mandrill_512.png", kHigh_SkFilterQua
lity); ) | 185 DEF_GM( return new DownsampleBitmapImageGM("mandrill_512.png", kHigh_SkFilterQua
lity); ) |
197 DEF_GM( return new DownsampleBitmapImageGM("mandrill_132x132_12x12.astc", | 186 DEF_GM( return new DownsampleBitmapImageGM("mandrill_132x132_12x12.astc", |
198 kHigh_SkFilterQuality); ) | 187 kHigh_SkFilterQuality); ) |
199 | 188 |
200 DEF_GM( return new DownsampleBitmapTextGM(72, kMedium_SkFilterQuality); ) | 189 DEF_GM( return new DownsampleBitmapTextGM(72, kMedium_SkFilterQuality); ) |
201 DEF_GM( return new DownsampleBitmapCheckerboardGM(512,256, kMedium_SkFilterQuali
ty); ) | 190 DEF_GM( return new DownsampleBitmapCheckerboardGM(512,256, kMedium_SkFilterQuali
ty); ) |
202 DEF_GM( return new DownsampleBitmapImageGM("mandrill_512.png", kMedium_SkFilterQ
uality); ) | 191 DEF_GM( return new DownsampleBitmapImageGM("mandrill_512.png", kMedium_SkFilterQ
uality); ) |
203 DEF_GM( return new DownsampleBitmapImageGM("mandrill_132x132_12x12.astc", | 192 DEF_GM( return new DownsampleBitmapImageGM("mandrill_132x132_12x12.astc", |
204 kMedium_SkFilterQuality); ) | 193 kMedium_SkFilterQuality); ) |
205 | 194 |
206 DEF_GM( return new DownsampleBitmapTextGM(72, kLow_SkFilterQuality); ) | 195 DEF_GM( return new DownsampleBitmapTextGM(72, kLow_SkFilterQuality); ) |
207 DEF_GM( return new DownsampleBitmapCheckerboardGM(512,256, kLow_SkFilterQuality)
; ) | 196 DEF_GM( return new DownsampleBitmapCheckerboardGM(512,256, kLow_SkFilterQuality)
; ) |
208 DEF_GM( return new DownsampleBitmapImageGM("mandrill_512.png", kLow_SkFilterQual
ity); ) | 197 DEF_GM( return new DownsampleBitmapImageGM("mandrill_512.png", kLow_SkFilterQual
ity); ) |
209 DEF_GM( return new DownsampleBitmapImageGM("mandrill_132x132_12x12.astc", | 198 DEF_GM( return new DownsampleBitmapImageGM("mandrill_132x132_12x12.astc", |
210 kLow_SkFilterQuality); ) | 199 kLow_SkFilterQuality); ) |
211 | 200 |
212 DEF_GM( return new DownsampleBitmapTextGM(72, kNone_SkFilterQuality); ) | 201 DEF_GM( return new DownsampleBitmapTextGM(72, kNone_SkFilterQuality); ) |
213 DEF_GM( return new DownsampleBitmapCheckerboardGM(512,256, kNone_SkFilterQuality
); ) | 202 DEF_GM( return new DownsampleBitmapCheckerboardGM(512,256, kNone_SkFilterQuality
); ) |
214 DEF_GM( return new DownsampleBitmapImageGM("mandrill_512.png", kNone_SkFilterQua
lity); ) | 203 DEF_GM( return new DownsampleBitmapImageGM("mandrill_512.png", kNone_SkFilterQua
lity); ) |
215 DEF_GM( return new DownsampleBitmapImageGM("mandrill_132x132_12x12.astc", | 204 DEF_GM( return new DownsampleBitmapImageGM("mandrill_132x132_12x12.astc", |
216 kNone_SkFilterQuality); ) | 205 kNone_SkFilterQuality); ) |
OLD | NEW |