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

Side by Side Diff: src/effects/SkResizeImageFilter.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 | « include/effects/SkResizeImageFilter.h ('k') | src/ports/SkGlobalInitialization_chromium.cpp » ('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 The Android Open Source Project
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 "SkResizeImageFilter.h"
9 #include "SkBitmap.h"
10 #include "SkCanvas.h"
11 #include "SkDevice.h"
12 #include "SkColorPriv.h"
13 #include "SkFlattenableBuffers.h"
14 #include "SkMatrix.h"
15 #include "SkRect.h"
16
17 SkResizeImageFilter::SkResizeImageFilter(SkScalar sx, SkScalar sy, SkPaint::Filt erLevel filterLevel,
18 SkImageFilter* input)
19 : INHERITED(input),
20 fSx(sx),
21 fSy(sy),
22 fFilterLevel(filterLevel) {
23 }
24
25 SkResizeImageFilter::SkResizeImageFilter(SkFlattenableReadBuffer& buffer)
26 : INHERITED(1, buffer) {
27 fSx = buffer.readScalar();
28 fSy = buffer.readScalar();
29 fFilterLevel = static_cast<SkPaint::FilterLevel>(buffer.readInt());
30 }
31
32 void SkResizeImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const {
33 this->INHERITED::flatten(buffer);
34 buffer.writeScalar(fSx);
35 buffer.writeScalar(fSy);
36 buffer.writeInt(fFilterLevel);
37 }
38
39 SkResizeImageFilter::~SkResizeImageFilter() {
40 }
41
42 bool SkResizeImageFilter::onFilterImage(Proxy* proxy,
43 const SkBitmap& source,
44 const SkMatrix& matrix,
45 SkBitmap* result,
46 SkIPoint* offset) {
47 SkBitmap src = source;
48 SkIPoint srcOffset = SkIPoint::Make(0, 0);
49 if (getInput(0) && !getInput(0)->filterImage(proxy, source, matrix, &src, &s rcOffset)) {
50 return false;
51 }
52
53 SkRect dstRect;
54 SkIRect srcBounds, dstBounds;
55 src.getBounds(&srcBounds);
56 srcBounds.offset(srcOffset);
57 SkRect srcRect = SkRect::Make(srcBounds);
58 SkMatrix dstMatrix;
59 dstMatrix.setScale(fSx, fSy);
60 dstMatrix.mapRect(&dstRect, srcRect);
61 dstRect.roundOut(&dstBounds);
62
63 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(dstBounds.width(), dst Bounds.height()));
64 if (NULL == device.get()) {
65 return false;
66 }
67
68 SkCanvas canvas(device.get());
69 canvas.translate(-SkIntToScalar(dstBounds.fLeft), -SkIntToScalar(dstBounds.f Top));
70 SkPaint paint;
71
72 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
73 paint.setFilterLevel(fFilterLevel);
74 canvas.concat(dstMatrix);
75 canvas.drawBitmap(src, srcRect.left(), srcRect.top(), &paint);
76
77 *result = device.get()->accessBitmap(false);
78 offset->fX = dstBounds.fLeft;
79 offset->fY = dstBounds.fTop;
80 return true;
81 }
OLDNEW
« no previous file with comments | « include/effects/SkResizeImageFilter.h ('k') | src/ports/SkGlobalInitialization_chromium.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698