Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Side by Side Diff: gm/filterbitmap.cpp

Issue 1791583002: Remove uses of SkImageDecoder from gms (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gm/factory.cpp ('k') | gm/filterindiabox.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
13 #include "SkStream.h" 12 #include "SkStream.h"
14 #include "SkTypeface.h" 13 #include "SkTypeface.h"
15 14
16 static void setTypeface(SkPaint* paint, const char name[], SkTypeface::Style sty le) { 15 static void setTypeface(SkPaint* paint, const char name[], SkTypeface::Style sty le) {
17 sk_tool_utils::set_portable_typeface(paint, name, style); 16 sk_tool_utils::set_portable_typeface(paint, name, style);
18 } 17 }
19 18
20 static SkSize computeSize(const SkBitmap& bm, const SkMatrix& mat) { 19 static SkSize computeSize(const SkBitmap& bm, const SkMatrix& mat) {
21 SkRect bounds = SkRect::MakeWH(SkIntToScalar(bm.width()), 20 SkRect bounds = SkRect::MakeWH(SkIntToScalar(bm.width()),
22 SkIntToScalar(bm.height())); 21 SkIntToScalar(bm.height()));
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 188
190 protected: 189 protected:
191 SkString fFilename; 190 SkString fFilename;
192 int fSize; 191 int fSize;
193 192
194 SkScalar getScale() override { 193 SkScalar getScale() override {
195 return 192.f/fSize; 194 return 192.f/fSize;
196 } 195 }
197 196
198 void makeBitmap() override { 197 void makeBitmap() override {
199 SkImageDecoder* codec = nullptr; 198 if (!GetResourceAsBitmap(fFilename.c_str(), &fBM)) {
200 SkString resourcePath = GetResourcePath(fFilename.c_str()); 199 fBM.allocN32Pixels(1, 1);
201 SkFILEStream stream(resourcePath.c_str()); 200 fBM.eraseARGB(255, 255, 0 , 0); // red == bad
202 if (stream.isValid()) { 201 }
203 codec = SkImageDecoder::Factory(&stream); 202 fSize = fBM.height();
204 } 203
205 if (codec) { 204 if (fConvertToG8) {
206 stream.rewind(); 205 SkBitmap tmp;
207 codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDe codePixels_Mode); 206 fBM.copyTo(&tmp, kGray_8_SkColorType);
208 delete codec; 207 fBM = tmp;
209 } else { 208 }
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 }
219 } 209 }
220 private: 210 private:
221 const bool fConvertToG8; 211 const bool fConvertToG8;
222 typedef FilterBitmapGM INHERITED; 212 typedef FilterBitmapGM INHERITED;
223 }; 213 };
224 214
225 ////////////////////////////////////////////////////////////////////////////// 215 //////////////////////////////////////////////////////////////////////////////
226 216
227 DEF_GM( return new FilterBitmapTextGM(3); ) 217 DEF_GM( return new FilterBitmapTextGM(3); )
228 DEF_GM( return new FilterBitmapTextGM(7); ) 218 DEF_GM( return new FilterBitmapTextGM(7); )
229 DEF_GM( return new FilterBitmapTextGM(10); ) 219 DEF_GM( return new FilterBitmapTextGM(10); )
230 DEF_GM( return new FilterBitmapCheckerboardGM(4,4); ) 220 DEF_GM( return new FilterBitmapCheckerboardGM(4,4); )
231 DEF_GM( return new FilterBitmapCheckerboardGM(32,32); ) 221 DEF_GM( return new FilterBitmapCheckerboardGM(32,32); )
232 DEF_GM( return new FilterBitmapCheckerboardGM(32,32, true); ) 222 DEF_GM( return new FilterBitmapCheckerboardGM(32,32, true); )
233 DEF_GM( return new FilterBitmapCheckerboardGM(32,8); ) 223 DEF_GM( return new FilterBitmapCheckerboardGM(32,8); )
234 DEF_GM( return new FilterBitmapCheckerboardGM(32,2); ) 224 DEF_GM( return new FilterBitmapCheckerboardGM(32,2); )
235 DEF_GM( return new FilterBitmapCheckerboardGM(192,192); ) 225 DEF_GM( return new FilterBitmapCheckerboardGM(192,192); )
236 DEF_GM( return new FilterBitmapImageGM("mandrill_16.png"); ) 226 DEF_GM( return new FilterBitmapImageGM("mandrill_16.png"); )
237 DEF_GM( return new FilterBitmapImageGM("mandrill_32.png"); ) 227 DEF_GM( return new FilterBitmapImageGM("mandrill_32.png"); )
238 DEF_GM( return new FilterBitmapImageGM("mandrill_64.png"); ) 228 DEF_GM( return new FilterBitmapImageGM("mandrill_64.png"); )
239 DEF_GM( return new FilterBitmapImageGM("mandrill_64.png", true); ) 229 DEF_GM( return new FilterBitmapImageGM("mandrill_64.png", true); )
240 DEF_GM( return new FilterBitmapImageGM("mandrill_128.png"); ) 230 DEF_GM( return new FilterBitmapImageGM("mandrill_128.png"); )
241 DEF_GM( return new FilterBitmapImageGM("mandrill_256.png"); ) 231 DEF_GM( return new FilterBitmapImageGM("mandrill_256.png"); )
242 DEF_GM( return new FilterBitmapImageGM("mandrill_512.png"); ) 232 DEF_GM( return new FilterBitmapImageGM("mandrill_512.png"); )
243 DEF_GM( return new FilterBitmapImageGM("color_wheel.png"); ) 233 DEF_GM( return new FilterBitmapImageGM("color_wheel.png"); )
OLDNEW
« no previous file with comments | « gm/factory.cpp ('k') | gm/filterindiabox.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698