diff options
Diffstat (limited to 'src/effects')
-rwxr-xr-x | src/effects/SkColorFilterImageFilter.cpp | 27 | ||||
-rw-r--r-- | src/effects/SkRectShaderImageFilter.cpp | 58 |
2 files changed, 74 insertions, 11 deletions
diff --git a/src/effects/SkColorFilterImageFilter.cpp b/src/effects/SkColorFilterImageFilter.cpp index 549a6867df..b5ab255ce7 100755 --- a/src/effects/SkColorFilterImageFilter.cpp +++ b/src/effects/SkColorFilterImageFilter.cpp @@ -62,16 +62,17 @@ SkColorFilterImageFilter* SkColorFilterImageFilter::Create(SkColorFilter* cf, SkScalar colorMatrix[20], inputMatrix[20]; SkColorFilter* inputColorFilter; if (input && cf->asColorMatrix(colorMatrix) - && (inputColorFilter = input->asColorFilter()) - && inputColorFilter->asColorMatrix(inputMatrix) - && !matrix_needs_clamping(inputMatrix)) { - SkScalar combinedMatrix[20]; - mult_color_matrix(inputMatrix, colorMatrix, combinedMatrix); - SkAutoTUnref<SkColorFilter> newCF(SkNEW_ARGS(SkColorMatrixFilter, (combinedMatrix))); - return SkNEW_ARGS(SkColorFilterImageFilter, (newCF, input->getInput(0))); - } else { - return SkNEW_ARGS(SkColorFilterImageFilter, (cf, input)); + && input->asColorFilter(&inputColorFilter) + && (NULL != inputColorFilter)) { + SkAutoUnref autoUnref(inputColorFilter); + if (inputColorFilter->asColorMatrix(inputMatrix) && !matrix_needs_clamping(inputMatrix)) { + SkScalar combinedMatrix[20]; + mult_color_matrix(inputMatrix, colorMatrix, combinedMatrix); + SkAutoTUnref<SkColorFilter> newCF(SkNEW_ARGS(SkColorMatrixFilter, (combinedMatrix))); + return SkNEW_ARGS(SkColorFilterImageFilter, (newCF, input->getInput(0))); + } } + return SkNEW_ARGS(SkColorFilterImageFilter, (cf, input)); } SkColorFilterImageFilter::SkColorFilterImageFilter(SkColorFilter* cf, SkImageFilter* input) : INHERITED(input), fColorFilter(cf) { @@ -110,6 +111,10 @@ bool SkColorFilterImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& sourc return true; } -SkColorFilter* SkColorFilterImageFilter::asColorFilter() const { - return fColorFilter; +bool SkColorFilterImageFilter::asColorFilter(SkColorFilter** filter) const { + if (filter) { + *filter = fColorFilter; + fColorFilter->ref(); + } + return true; } diff --git a/src/effects/SkRectShaderImageFilter.cpp b/src/effects/SkRectShaderImageFilter.cpp new file mode 100644 index 0000000000..b6c78efd0f --- /dev/null +++ b/src/effects/SkRectShaderImageFilter.cpp @@ -0,0 +1,58 @@ +/* + * Copyright 2013 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkRectShaderImageFilter.h" +#include "SkBitmap.h" +#include "SkCanvas.h" +#include "SkDevice.h" +#include "SkFlattenableBuffers.h" +#include "SkShader.h" + +SkRectShaderImageFilter* SkRectShaderImageFilter::Create(SkShader* s, SkRect region) { + SkASSERT(s); + return SkNEW_ARGS(SkRectShaderImageFilter, (s, region)); +} + +SkRectShaderImageFilter::SkRectShaderImageFilter(SkShader* s, SkRect region) + : INHERITED(NULL) + , fShader(s) + , fRegion(region) { + SkASSERT(s); + SkSafeRef(s); +} + +SkRectShaderImageFilter::SkRectShaderImageFilter(SkFlattenableReadBuffer& buffer) + : INHERITED(buffer) { + fShader = buffer.readFlattenableT<SkShader>(); + buffer.readRect(&fRegion); +} + +void SkRectShaderImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { + this->INHERITED::flatten(buffer); + + buffer.writeFlattenable(fShader); + buffer.writeRect(fRegion); +} + +SkRectShaderImageFilter::~SkRectShaderImageFilter() { + SkSafeUnref(fShader); +} + +bool SkRectShaderImageFilter::onFilterImage(Proxy* proxy, + const SkBitmap& source, + const SkMatrix& matrix, + SkBitmap* result, + SkIPoint* loc) { + SkAutoTUnref<SkDevice> device(proxy->createDevice(fRegion.width(), fRegion.height())); + SkCanvas canvas(device.get()); + SkPaint paint; + paint.setShader(fShader); + canvas.drawRect(fRegion, paint); + *result = device.get()->accessBitmap(false); + return true; +} + |