OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 The Android Open Source Project | 2 * Copyright 2013 The Android Open Source Project |
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 "SkResizeImageFilter.h" | 8 #include "SkResizeImageFilter.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 buffer.writeScalar(fSx); | 35 buffer.writeScalar(fSx); |
36 buffer.writeScalar(fSy); | 36 buffer.writeScalar(fSy); |
37 buffer.writeInt(fFilterLevel); | 37 buffer.writeInt(fFilterLevel); |
38 } | 38 } |
39 | 39 |
40 SkResizeImageFilter::~SkResizeImageFilter() { | 40 SkResizeImageFilter::~SkResizeImageFilter() { |
41 } | 41 } |
42 | 42 |
43 bool SkResizeImageFilter::onFilterImage(Proxy* proxy, | 43 bool SkResizeImageFilter::onFilterImage(Proxy* proxy, |
44 const SkBitmap& source, | 44 const SkBitmap& source, |
45 const SkMatrix& matrix, | 45 const SkMatrix& ctm, |
46 SkBitmap* result, | 46 SkBitmap* result, |
47 SkIPoint* offset) const { | 47 SkIPoint* offset) const { |
48 SkBitmap src = source; | 48 SkBitmap src = source; |
49 SkIPoint srcOffset = SkIPoint::Make(0, 0); | 49 SkIPoint srcOffset = SkIPoint::Make(0, 0); |
50 if (getInput(0) && !getInput(0)->filterImage(proxy, source, matrix, &src, &s
rcOffset)) { | 50 if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctm, &src, &srcO
ffset)) { |
51 return false; | 51 return false; |
52 } | 52 } |
53 | 53 |
54 SkRect dstRect; | 54 SkRect dstRect; |
55 SkIRect srcBounds, dstBounds; | 55 SkIRect srcBounds, dstBounds; |
56 src.getBounds(&srcBounds); | 56 src.getBounds(&srcBounds); |
57 srcBounds.offset(srcOffset); | 57 srcBounds.offset(srcOffset); |
58 SkRect srcRect = SkRect::Make(srcBounds); | 58 SkRect srcRect = SkRect::Make(srcBounds); |
59 SkMatrix dstMatrix; | 59 SkMatrix matrix; |
60 dstMatrix.setScale(fSx, fSy); | 60 if (!ctm.invert(&matrix)) { |
61 dstMatrix.mapRect(&dstRect, srcRect); | 61 return false; |
| 62 } |
| 63 matrix.postScale(fSx, fSy); |
| 64 matrix.postConcat(ctm); |
| 65 matrix.mapRect(&dstRect, srcRect); |
62 dstRect.roundOut(&dstBounds); | 66 dstRect.roundOut(&dstBounds); |
63 | 67 |
64 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(dstBounds.width(), dst
Bounds.height())); | 68 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(dstBounds.width(), dst
Bounds.height())); |
65 if (NULL == device.get()) { | 69 if (NULL == device.get()) { |
66 return false; | 70 return false; |
67 } | 71 } |
68 | 72 |
69 SkCanvas canvas(device.get()); | 73 SkCanvas canvas(device.get()); |
70 canvas.translate(-SkIntToScalar(dstBounds.fLeft), -SkIntToScalar(dstBounds.f
Top)); | 74 canvas.scale(fSx, fSy); |
71 SkPaint paint; | 75 SkPaint paint; |
72 | 76 |
73 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 77 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
74 paint.setFilterLevel(fFilterLevel); | 78 paint.setFilterLevel(fFilterLevel); |
75 canvas.concat(dstMatrix); | |
76 canvas.drawBitmap(src, srcRect.left(), srcRect.top(), &paint); | 79 canvas.drawBitmap(src, srcRect.left(), srcRect.top(), &paint); |
77 | 80 |
78 *result = device.get()->accessBitmap(false); | 81 *result = device.get()->accessBitmap(false); |
79 offset->fX = dstBounds.fLeft; | 82 offset->fX = dstBounds.fLeft; |
80 offset->fY = dstBounds.fTop; | 83 offset->fY = dstBounds.fTop; |
81 return true; | 84 return true; |
82 } | 85 } |
| 86 |
| 87 void SkResizeImageFilter::computeFastBounds(const SkRect& src, SkRect* dst) cons
t { |
| 88 SkRect bounds = src; |
| 89 if (getInput(0)) { |
| 90 getInput(0)->computeFastBounds(src, &bounds); |
| 91 } |
| 92 dst->setXYWH(bounds.x(), bounds.y(), bounds.width() * fSx, bounds.height() *
fSy); |
| 93 } |
| 94 |
| 95 bool SkResizeImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm
, |
| 96 SkIRect* dst) const { |
| 97 SkMatrix matrix; |
| 98 if (!ctm.invert(&matrix)) { |
| 99 return false; |
| 100 } |
| 101 matrix.postScale(SkScalarInvert(fSx), SkScalarInvert(fSy)); |
| 102 matrix.postConcat(ctm); |
| 103 SkRect floatBounds; |
| 104 matrix.mapRect(&floatBounds, SkRect::Make(src)); |
| 105 SkIRect bounds; |
| 106 floatBounds.roundOut(&bounds); |
| 107 if (getInput(0) && !getInput(0)->filterBounds(bounds, ctm, &bounds)) { |
| 108 return false; |
| 109 } |
| 110 |
| 111 *dst = bounds; |
| 112 return true; |
| 113 } |
OLD | NEW |