This source file includes following definitions.
- m_radiusY
- create
- morphologyOperator
- setMorphologyOperator
- radiusX
- setRadiusX
- radiusY
- mapRect
- setRadiusY
- applySoftware
- createImageFilter
- externalRepresentation
#include "config.h"
#include "platform/graphics/filters/FEMorphology.h"
#include "SkMorphologyImageFilter.h"
#include "platform/graphics/filters/ParallelJobs.h"
#include "platform/graphics/filters/SkiaImageFilterBuilder.h"
#include "platform/text/TextStream.h"
#include "wtf/Uint8ClampedArray.h"
#include "wtf/Vector.h"
using namespace std;
namespace WebCore {
FEMorphology::FEMorphology(Filter* filter, MorphologyOperatorType type, float radiusX, float radiusY)
: FilterEffect(filter)
, m_type(type)
, m_radiusX(radiusX)
, m_radiusY(radiusY)
{
}
PassRefPtr<FEMorphology> FEMorphology::create(Filter* filter, MorphologyOperatorType type, float radiusX, float radiusY)
{
return adoptRef(new FEMorphology(filter, type, radiusX, radiusY));
}
MorphologyOperatorType FEMorphology::morphologyOperator() const
{
return m_type;
}
bool FEMorphology::setMorphologyOperator(MorphologyOperatorType type)
{
if (m_type == type)
return false;
m_type = type;
return true;
}
float FEMorphology::radiusX() const
{
return m_radiusX;
}
bool FEMorphology::setRadiusX(float radiusX)
{
if (m_radiusX == radiusX)
return false;
m_radiusX = radiusX;
return true;
}
float FEMorphology::radiusY() const
{
return m_radiusY;
}
FloatRect FEMorphology::mapRect(const FloatRect& rect, bool)
{
FloatRect result = rect;
result.inflateX(filter()->applyHorizontalScale(m_radiusX));
result.inflateY(filter()->applyVerticalScale(m_radiusY));
return result;
}
bool FEMorphology::setRadiusY(float radiusY)
{
if (m_radiusY == radiusY)
return false;
m_radiusY = radiusY;
return true;
}
void FEMorphology::applySoftware()
{
ImageBuffer* resultImage = createImageBufferResult();
if (!resultImage)
return;
FilterEffect* in = inputEffect(0);
IntRect drawingRegion = drawingRegionOfInputImage(in->absolutePaintRect());
setIsAlphaImage(in->isAlphaImage());
float radiusX = filter()->applyHorizontalScale(m_radiusX);
float radiusY = filter()->applyVerticalScale(m_radiusY);
RefPtr<Image> image = in->asImageBuffer()->copyImage(DontCopyBackingStore);
SkPaint paint;
GraphicsContext* dstContext = resultImage->context();
if (m_type == FEMORPHOLOGY_OPERATOR_DILATE)
paint.setImageFilter(new SkDilateImageFilter(radiusX, radiusY))->unref();
else if (m_type == FEMORPHOLOGY_OPERATOR_ERODE)
paint.setImageFilter(new SkErodeImageFilter(radiusX, radiusY))->unref();
SkRect bounds = SkRect::MakeWH(absolutePaintRect().width(), absolutePaintRect().height());
dstContext->saveLayer(&bounds, &paint);
dstContext->drawImage(image.get(), drawingRegion.location(), CompositeCopy);
dstContext->restoreLayer();
}
PassRefPtr<SkImageFilter> FEMorphology::createImageFilter(SkiaImageFilterBuilder* builder)
{
RefPtr<SkImageFilter> input(builder->build(inputEffect(0), operatingColorSpace()));
SkScalar radiusX = SkFloatToScalar(filter()->applyHorizontalScale(m_radiusX));
SkScalar radiusY = SkFloatToScalar(filter()->applyVerticalScale(m_radiusY));
SkImageFilter::CropRect rect = getCropRect(builder->cropOffset());
if (m_type == FEMORPHOLOGY_OPERATOR_DILATE)
return adoptRef(new SkDilateImageFilter(radiusX, radiusY, input.get(), &rect));
return adoptRef(new SkErodeImageFilter(radiusX, radiusY, input.get(), &rect));
}
static TextStream& operator<<(TextStream& ts, const MorphologyOperatorType& type)
{
switch (type) {
case FEMORPHOLOGY_OPERATOR_UNKNOWN:
ts << "UNKNOWN";
break;
case FEMORPHOLOGY_OPERATOR_ERODE:
ts << "ERODE";
break;
case FEMORPHOLOGY_OPERATOR_DILATE:
ts << "DILATE";
break;
}
return ts;
}
TextStream& FEMorphology::externalRepresentation(TextStream& ts, int indent) const
{
writeIndent(ts, indent);
ts << "[feMorphology";
FilterEffect::externalRepresentation(ts);
ts << " operator=\"" << morphologyOperator() << "\" "
<< "radius=\"" << radiusX() << ", " << radiusY() << "\"]\n";
inputEffect(0)->externalRepresentation(ts, indent + 1);
return ts;
}
}