OLD | NEW |
---|---|
(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(const SkSize& scale, SkPaint::FilterLev el filterLevel, SkImageFilter* input) | |
18 : INHERITED(input), | |
19 fScale(scale), | |
20 fFilterLevel(filterLevel) { | |
21 } | |
22 | |
23 SkResizeImageFilter::SkResizeImageFilter(SkFlattenableReadBuffer& buffer) | |
24 : INHERITED(1, buffer) { | |
25 fScale.fWidth = buffer.readScalar(); | |
26 fScale.fHeight = buffer.readScalar(); | |
27 fFilterLevel = static_cast<SkPaint::FilterLevel>(buffer.readInt()); | |
28 } | |
29 | |
30 void SkResizeImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { | |
31 this->INHERITED::flatten(buffer); | |
32 buffer.writeScalar(fScale.fWidth); | |
33 buffer.writeScalar(fScale.fHeight); | |
34 buffer.writeInt(fFilterLevel); | |
35 } | |
36 | |
37 SkResizeImageFilter::~SkResizeImageFilter() { | |
38 } | |
39 | |
40 bool SkResizeImageFilter::onFilterImage(Proxy* proxy, | |
41 const SkBitmap& source, | |
42 const SkMatrix& matrix, | |
43 SkBitmap* result, | |
44 SkIPoint* offset) { | |
45 SkBitmap src = source; | |
46 SkIPoint srcOffset = SkIPoint::Make(0, 0); | |
47 if (getInput(0) && !getInput(0)->filterImage(proxy, source, matrix, &src, &s rcOffset)) { | |
48 return false; | |
49 } | |
50 | |
51 SkRect dstRect; | |
52 SkIRect srcBounds, dstBounds; | |
53 src.getBounds(&srcBounds); | |
54 srcBounds.offset(srcOffset); | |
55 SkRect srcRect = SkRect::Make(srcBounds); | |
56 SkMatrix dstMatrix = matrix; | |
57 dstMatrix.preScale(fScale.fWidth, fScale.fHeight); | |
58 dstMatrix.mapRect(&dstRect, srcRect); | |
59 dstRect.roundOut(&dstBounds); | |
60 | |
61 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(dstBounds.width(), dst Bounds.height())); | |
62 if (NULL == device.get()) { | |
63 return false; | |
64 } | |
65 | |
66 SkCanvas canvas(device.get()); | |
67 canvas.translate(-SkIntToScalar(dstBounds.fLeft), -SkIntToScalar(dstBounds.f Top)); | |
68 SkPaint paint; | |
69 | |
70 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | |
71 paint.setFilterLevel(fFilterLevel); | |
72 canvas.drawBitmapRectToRect(src, &srcRect, dstRect, &paint); | |
reed1
2014/01/13 22:02:57
can you instead call canvas.concat(dstMatrix) foll
Stephen White
2014/01/14 21:45:43
Done.
| |
73 | |
74 *result = device.get()->accessBitmap(false); | |
75 offset->fX = dstBounds.fLeft; | |
76 offset->fY = dstBounds.fTop; | |
77 return true; | |
78 } | |
OLD | NEW |