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

Side by Side Diff: gm/resizeimagefilter.cpp

Issue 136863006: Implement a resize image filter. This is needed for the "filterRes" feature in SVG filter effects, … (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Add registration to fix cross-process pipe tests. Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | gyp/effects.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "gm.h"
9 #include "SkColor.h"
10 #include "SkResizeImageFilter.h"
11
12 namespace skiagm {
13
14 class ResizeGM : public GM {
15 public:
16 ResizeGM() {
17 this->setBGColor(0x00000000);
18 }
19
20 protected:
21 virtual SkString onShortName() {
22 return SkString("resizeimagefilter");
23 }
24
25 void draw(SkCanvas* canvas,
26 const SkRect& rect,
27 const SkSize& deviceSize,
28 SkPaint::FilterLevel filterLevel) {
29 SkRect dstRect;
30 canvas->getTotalMatrix().mapRect(&dstRect, rect);
31 canvas->save();
32 SkScalar deviceScaleX = SkScalarDiv(deviceSize.width(), dstRect.width()) ;
33 SkScalar deviceScaleY = SkScalarDiv(deviceSize.height(), dstRect.height( ));
34 canvas->translate(rect.x(), rect.y());
35 canvas->scale(deviceScaleX, deviceScaleY);
36 canvas->translate(-rect.x(), -rect.y());
37 SkAutoTUnref<SkImageFilter> imageFilter(
38 new SkResizeImageFilter(SkScalarInvert(deviceScaleX),
39 SkScalarInvert(deviceScaleY),
40 filterLevel));
41 SkPaint filteredPaint;
42 filteredPaint.setImageFilter(imageFilter.get());
43 canvas->saveLayer(&rect, &filteredPaint);
44 SkPaint paint;
45 paint.setColor(0xFF00FF00);
46 SkRect ovalRect = rect;
47 ovalRect.inset(SkIntToScalar(4), SkIntToScalar(4));
48 canvas->drawOval(ovalRect, paint);
49 canvas->restore(); // for saveLayer
50 canvas->restore();
51 }
52
53 virtual SkISize onISize() {
54 return make_isize(420, 100);
55 }
56
57 virtual void onDraw(SkCanvas* canvas) {
58 canvas->clear(0x00000000);
59
60 SkRect srcRect = SkRect::MakeWH(96, 96);
61
62 SkSize deviceSize = SkSize::Make(16, 16);
63 draw(canvas,
64 srcRect,
65 deviceSize,
66 SkPaint::kNone_FilterLevel);
67
68 canvas->translate(srcRect.width() + SkIntToScalar(10), 0);
69 draw(canvas,
70 srcRect,
71 deviceSize,
72 SkPaint::kLow_FilterLevel);
73
74 canvas->translate(srcRect.width() + SkIntToScalar(10), 0);
75 draw(canvas,
76 srcRect,
77 deviceSize,
78 SkPaint::kMedium_FilterLevel);
79
80 canvas->translate(srcRect.width() + SkIntToScalar(10), 0);
81 draw(canvas,
82 srcRect,
83 deviceSize,
84 SkPaint::kHigh_FilterLevel);
85 }
86
87 private:
88 typedef GM INHERITED;
89 };
90
91 //////////////////////////////////////////////////////////////////////////////
92
93 static GM* MyFactory(void*) { return new ResizeGM; }
94 static GMRegistry reg(MyFactory);
95
96 }
OLDNEW
« no previous file with comments | « no previous file | gyp/effects.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698