Chromium Code Reviews| Index: src/effects/SkResizeImageFilter.cpp |
| diff --git a/src/effects/SkResizeImageFilter.cpp b/src/effects/SkResizeImageFilter.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..30fbdf0ec4838c7068b28bd5d3221262c05990d5 |
| --- /dev/null |
| +++ b/src/effects/SkResizeImageFilter.cpp |
| @@ -0,0 +1,78 @@ |
| +/* |
| + * Copyright 2013 The Android Open Source Project |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| + |
| +#include "SkResizeImageFilter.h" |
| +#include "SkBitmap.h" |
| +#include "SkCanvas.h" |
| +#include "SkDevice.h" |
| +#include "SkColorPriv.h" |
| +#include "SkFlattenableBuffers.h" |
| +#include "SkMatrix.h" |
| +#include "SkRect.h" |
| + |
| +SkResizeImageFilter::SkResizeImageFilter(const SkSize& scale, SkPaint::FilterLevel filterLevel, SkImageFilter* input) |
| + : INHERITED(input), |
| + fScale(scale), |
| + fFilterLevel(filterLevel) { |
| +} |
| + |
| +SkResizeImageFilter::SkResizeImageFilter(SkFlattenableReadBuffer& buffer) |
| + : INHERITED(1, buffer) { |
| + fScale.fWidth = buffer.readScalar(); |
| + fScale.fHeight = buffer.readScalar(); |
| + fFilterLevel = static_cast<SkPaint::FilterLevel>(buffer.readInt()); |
| +} |
| + |
| +void SkResizeImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { |
| + this->INHERITED::flatten(buffer); |
| + buffer.writeScalar(fScale.fWidth); |
| + buffer.writeScalar(fScale.fHeight); |
| + buffer.writeInt(fFilterLevel); |
| +} |
| + |
| +SkResizeImageFilter::~SkResizeImageFilter() { |
| +} |
| + |
| +bool SkResizeImageFilter::onFilterImage(Proxy* proxy, |
| + const SkBitmap& source, |
| + const SkMatrix& matrix, |
| + SkBitmap* result, |
| + SkIPoint* offset) { |
| + SkBitmap src = source; |
| + SkIPoint srcOffset = SkIPoint::Make(0, 0); |
| + if (getInput(0) && !getInput(0)->filterImage(proxy, source, matrix, &src, &srcOffset)) { |
| + return false; |
| + } |
| + |
| + SkRect dstRect; |
| + SkIRect srcBounds, dstBounds; |
| + src.getBounds(&srcBounds); |
| + srcBounds.offset(srcOffset); |
| + SkRect srcRect = SkRect::Make(srcBounds); |
| + SkMatrix dstMatrix = matrix; |
| + dstMatrix.preScale(fScale.fWidth, fScale.fHeight); |
| + dstMatrix.mapRect(&dstRect, srcRect); |
| + dstRect.roundOut(&dstBounds); |
| + |
| + SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(dstBounds.width(), dstBounds.height())); |
| + if (NULL == device.get()) { |
| + return false; |
| + } |
| + |
| + SkCanvas canvas(device.get()); |
| + canvas.translate(-SkIntToScalar(dstBounds.fLeft), -SkIntToScalar(dstBounds.fTop)); |
| + SkPaint paint; |
| + |
| + paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| + paint.setFilterLevel(fFilterLevel); |
| + 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.
|
| + |
| + *result = device.get()->accessBitmap(false); |
| + offset->fX = dstBounds.fLeft; |
| + offset->fY = dstBounds.fTop; |
| + return true; |
| +} |