aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar senorblanco@chromium.org <senorblanco@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-15 04:49:18 +0000
committerGravatar senorblanco@chromium.org <senorblanco@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-15 04:49:18 +0000
commita612d4c5134655fe6703c8d2f63be710aa1e2767 (patch)
tree61e262f0e035e1ef5c99b1d1c96b632659273a81 /src
parent32678d9a453e2c9fd26e92be429cdd84250b4d85 (diff)
Implement a resize image filter. This is needed for the "filterRes" feature in SVG filter effects, which specifies the required size for intermediate processing buffers. In order to make this work, we need to render the primitive at the given resolution (doable at the callsite in Blink), and then to resize the result to the actual on-screen size. The latter is where this filter comes in.
It simply applies a scaling factor (and the current CTM) to its input, and draws its input bitmap at that size. R=reed@google.com Committed: https://code.google.com/p/skia/source/detail?r=13077 Reverted: https://code.google.com/p/skia/source/detail?r=13078 BUG= Review URL: https://codereview.chromium.org/136863006 git-svn-id: http://skia.googlecode.com/svn/trunk@13082 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r--src/effects/SkResizeImageFilter.cpp81
-rw-r--r--src/ports/SkGlobalInitialization_chromium.cpp2
-rw-r--r--src/ports/SkGlobalInitialization_default.cpp2
3 files changed, 85 insertions, 0 deletions
diff --git a/src/effects/SkResizeImageFilter.cpp b/src/effects/SkResizeImageFilter.cpp
new file mode 100644
index 0000000000..4d700901ef
--- /dev/null
+++ b/src/effects/SkResizeImageFilter.cpp
@@ -0,0 +1,81 @@
+/*
+ * 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(SkScalar sx, SkScalar sy, SkPaint::FilterLevel filterLevel,
+ SkImageFilter* input)
+ : INHERITED(input),
+ fSx(sx),
+ fSy(sy),
+ fFilterLevel(filterLevel) {
+}
+
+SkResizeImageFilter::SkResizeImageFilter(SkFlattenableReadBuffer& buffer)
+ : INHERITED(1, buffer) {
+ fSx = buffer.readScalar();
+ fSy = buffer.readScalar();
+ fFilterLevel = static_cast<SkPaint::FilterLevel>(buffer.readInt());
+}
+
+void SkResizeImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const {
+ this->INHERITED::flatten(buffer);
+ buffer.writeScalar(fSx);
+ buffer.writeScalar(fSy);
+ 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;
+ dstMatrix.setScale(fSx, fSy);
+ 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.concat(dstMatrix);
+ canvas.drawBitmap(src, srcRect.left(), srcRect.top(), &paint);
+
+ *result = device.get()->accessBitmap(false);
+ offset->fX = dstBounds.fLeft;
+ offset->fY = dstBounds.fTop;
+ return true;
+}
diff --git a/src/ports/SkGlobalInitialization_chromium.cpp b/src/ports/SkGlobalInitialization_chromium.cpp
index d402c02e21..79ed46c70e 100644
--- a/src/ports/SkGlobalInitialization_chromium.cpp
+++ b/src/ports/SkGlobalInitialization_chromium.cpp
@@ -52,6 +52,7 @@
#include "SkPerlinNoiseShader.h"
#include "SkPixelXorXfermode.h"
#include "SkRectShaderImageFilter.h"
+#include "SkResizeImageFilter.h"
#include "SkStippleMaskFilter.h"
#include "SkTableColorFilter.h"
#include "SkTestImageFilters.h"
@@ -89,6 +90,7 @@ static void InitializeFlattenables(int*) {
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkPerlinNoiseShader)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkPixelXorXfermode)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkRectShaderImageFilter)
+ SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkResizeImageFilter)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkStippleMaskFilter)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSumPathEffect)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTileImageFilter)
diff --git a/src/ports/SkGlobalInitialization_default.cpp b/src/ports/SkGlobalInitialization_default.cpp
index d402c02e21..79ed46c70e 100644
--- a/src/ports/SkGlobalInitialization_default.cpp
+++ b/src/ports/SkGlobalInitialization_default.cpp
@@ -52,6 +52,7 @@
#include "SkPerlinNoiseShader.h"
#include "SkPixelXorXfermode.h"
#include "SkRectShaderImageFilter.h"
+#include "SkResizeImageFilter.h"
#include "SkStippleMaskFilter.h"
#include "SkTableColorFilter.h"
#include "SkTestImageFilters.h"
@@ -89,6 +90,7 @@ static void InitializeFlattenables(int*) {
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkPerlinNoiseShader)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkPixelXorXfermode)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkRectShaderImageFilter)
+ SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkResizeImageFilter)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkStippleMaskFilter)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSumPathEffect)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTileImageFilter)