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

Side by Side Diff: gm/imagemagnifier.cpp

Issue 1882943002: Switch SkMagnifierImageFilter over to new onFilterImage interface (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update Created 4 years, 8 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 | « no previous file | include/effects/SkMagnifierImageFilter.h » ('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 2012 Google Inc. 2 * Copyright 2012 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 #include "SkImageSource.h"
9 #include "SkMagnifierImageFilter.h" 10 #include "SkMagnifierImageFilter.h"
10 #include "SkRandom.h" 11 #include "SkRandom.h"
12 #include "SkSurface.h"
11 13
12 #define WIDTH 500 14 #define WIDTH 500
13 #define HEIGHT 500 15 #define HEIGHT 500
14 16
15 DEF_SIMPLE_GM_BG(imagemagnifier, canvas, WIDTH, HEIGHT, SK_ColorBLACK) { 17 DEF_SIMPLE_GM_BG(imagemagnifier, canvas, WIDTH, HEIGHT, SK_ColorBLACK) {
16 SkPaint filterPaint; 18 SkPaint filterPaint;
17 filterPaint.setImageFilter( 19 filterPaint.setImageFilter(
18 SkMagnifierImageFilter::Make( 20 SkMagnifierImageFilter::Make(
19 SkRect::MakeXYWH(SkIntToScalar(100), SkIntToScalar(100), 21 SkRect::MakeXYWH(SkIntToScalar(100), SkIntToScalar(100),
20 SkIntToScalar(WIDTH / 2), 22 SkIntToScalar(WIDTH / 2),
21 SkIntToScalar(HEIGHT / 2)), 23 SkIntToScalar(HEIGHT / 2)),
22 100, nullptr)); 24 100, nullptr));
23 canvas->saveLayer(nullptr, &filterPaint); 25 canvas->saveLayer(nullptr, &filterPaint);
24 const char* str = "The quick brown fox jumped over the lazy dog."; 26 const char* str = "The quick brown fox jumped over the lazy dog.";
25 SkRandom rand; 27 SkRandom rand;
26 for (int i = 0; i < 25; ++i) { 28 for (int i = 0; i < 25; ++i) {
27 int x = rand.nextULessThan(WIDTH); 29 int x = rand.nextULessThan(WIDTH);
28 int y = rand.nextULessThan(HEIGHT); 30 int y = rand.nextULessThan(HEIGHT);
29 SkPaint paint; 31 SkPaint paint;
30 sk_tool_utils::set_portable_typeface(&paint); 32 sk_tool_utils::set_portable_typeface(&paint);
31 paint.setColor(sk_tool_utils::color_to_565(rand.nextBits(24) | 0xFF0 00000)); 33 paint.setColor(sk_tool_utils::color_to_565(rand.nextBits(24) | 0xFF0 00000));
32 paint.setTextSize(rand.nextRangeScalar(0, 300)); 34 paint.setTextSize(rand.nextRangeScalar(0, 300));
33 paint.setAntiAlias(true); 35 paint.setAntiAlias(true);
34 canvas->drawText(str, strlen(str), SkIntToScalar(x), 36 canvas->drawText(str, strlen(str), SkIntToScalar(x),
35 SkIntToScalar(y), paint); 37 SkIntToScalar(y), paint);
36 } 38 }
37 canvas->restore(); 39 canvas->restore();
38 } 40 }
41
42 ////////////////////////////////////////////////////////////////////////////////
43 #define WIDTH_HEIGHT 256
44
45 static sk_sp<SkImage> make_img() {
46 const SkImageInfo info = SkImageInfo::MakeN32Premul(WIDTH_HEIGHT, WIDTH_HEIG HT);
47
48 sk_sp<SkSurface> surf(SkSurface::MakeRaster(info));
49
50 SkCanvas* canvas = surf->getCanvas();
51
52 canvas->clear(0x0);
53
54 SkPaint paint;
55 paint.setColor(SK_ColorBLUE);
56
57 for (float pos = 0; pos < WIDTH_HEIGHT; pos += 16) {
58 canvas->drawLine(0, pos, SkIntToScalar(WIDTH_HEIGHT), pos, paint);
59 canvas->drawLine(pos, 0, pos, SkIntToScalar(WIDTH_HEIGHT), paint);
60 }
61
62 return surf->makeImageSnapshot();
63 }
64
65 DEF_SIMPLE_GM_BG(imagemagnifier_cropped, canvas, WIDTH_HEIGHT, WIDTH_HEIGHT, SK_ ColorBLACK) {
66
67 sk_sp<SkImage> image(make_img());
68
69 sk_sp<SkImageFilter> imageSource(SkImageSource::Make(std::move(image)));
70
71 SkRect srcRect = SkRect::MakeWH(SkIntToScalar(WIDTH_HEIGHT-32),
72 SkIntToScalar(WIDTH_HEIGHT-32));
73 srcRect.inset(64.0f, 64.0f);
74
75 static const SkScalar kInset = 64.0f;
76
77 // Crop out a 16 pixel ring around the result
78 const SkRect rect = SkRect::MakeXYWH(16, 16, WIDTH_HEIGHT-32, WIDTH_HEIGHT-3 2);
79 SkImageFilter::CropRect cropRect(rect);
80
81 SkPaint filterPaint;
82 filterPaint.setImageFilter(SkMagnifierImageFilter::Make(srcRect, kInset,
83 std::move(imageSourc e),
84 &cropRect));
85
86 canvas->saveLayer(nullptr, &filterPaint);
87 canvas->restore();
88 }
OLDNEW
« no previous file with comments | « no previous file | include/effects/SkMagnifierImageFilter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698