FilterOperation.cpp [plain text]
#include "config.h"
#if ENABLE(CSS_FILTERS)
#include "FilterOperation.h"
#include "AnimationUtilities.h"
namespace WebCore {
PassRefPtr<FilterOperation> BasicColorMatrixFilterOperation::blend(const FilterOperation* from, double progress, bool blendToPassthrough)
{
if (from && !from->isSameType(*this))
return this;
if (blendToPassthrough)
return BasicColorMatrixFilterOperation::create(WebCore::blend(m_amount, passthroughAmount(), progress), m_type);
const BasicColorMatrixFilterOperation* fromOp = static_cast<const BasicColorMatrixFilterOperation*>(from);
double fromAmount = fromOp ? fromOp->amount() : passthroughAmount();
return BasicColorMatrixFilterOperation::create(WebCore::blend(fromAmount, m_amount, progress), m_type);
}
double BasicColorMatrixFilterOperation::passthroughAmount() const
{
switch (m_type) {
case GRAYSCALE:
case SEPIA:
case HUE_ROTATE:
return 0;
case SATURATE:
return 1;
default:
ASSERT_NOT_REACHED();
return 0;
}
}
PassRefPtr<FilterOperation> BasicComponentTransferFilterOperation::blend(const FilterOperation* from, double progress, bool blendToPassthrough)
{
if (from && !from->isSameType(*this))
return this;
if (blendToPassthrough)
return BasicComponentTransferFilterOperation::create(WebCore::blend(m_amount, passthroughAmount(), progress), m_type);
const BasicComponentTransferFilterOperation* fromOp = static_cast<const BasicComponentTransferFilterOperation*>(from);
double fromAmount = fromOp ? fromOp->amount() : passthroughAmount();
return BasicComponentTransferFilterOperation::create(WebCore::blend(fromAmount, m_amount, progress), m_type);
}
double BasicComponentTransferFilterOperation::passthroughAmount() const
{
switch (m_type) {
case OPACITY:
return 1;
case INVERT:
return 0;
case CONTRAST:
return 1;
case BRIGHTNESS:
return 1;
default:
ASSERT_NOT_REACHED();
return 0;
}
}
PassRefPtr<FilterOperation> GammaFilterOperation::blend(const FilterOperation* from, double progress, bool blendToPassthrough)
{
if (from && !from->isSameType(*this))
return this;
if (blendToPassthrough)
return GammaFilterOperation::create(
WebCore::blend(m_amplitude, 1.0, progress),
WebCore::blend(m_exponent, 1.0, progress),
WebCore::blend(m_offset, 0.0, progress), m_type);
const GammaFilterOperation* fromOp = static_cast<const GammaFilterOperation*>(from);
double fromAmplitude = fromOp ? fromOp->amplitude() : 1;
double fromExponent = fromOp ? fromOp->exponent() : 1;
double fromOffset = fromOp ? fromOp->offset() : 0;
return GammaFilterOperation::create(
WebCore::blend(fromAmplitude, m_amplitude, progress),
WebCore::blend(fromExponent, m_exponent, progress),
WebCore::blend(fromOffset, m_offset, progress), m_type);
}
PassRefPtr<FilterOperation> BlurFilterOperation::blend(const FilterOperation* from, double progress, bool blendToPassthrough)
{
if (from && !from->isSameType(*this))
return this;
LengthType lengthType = m_stdDeviation.type();
if (blendToPassthrough)
return BlurFilterOperation::create(Length(lengthType).blend(m_stdDeviation, progress), m_type);
const BlurFilterOperation* fromOp = static_cast<const BlurFilterOperation*>(from);
Length fromLength = fromOp ? fromOp->m_stdDeviation : Length(lengthType);
return BlurFilterOperation::create(m_stdDeviation.blend(fromLength, progress), m_type);
}
PassRefPtr<FilterOperation> DropShadowFilterOperation::blend(const FilterOperation* from, double progress, bool blendToPassthrough)
{
if (from && !from->isSameType(*this))
return this;
if (blendToPassthrough)
return DropShadowFilterOperation::create(
WebCore::blend(m_location, IntPoint(), progress),
WebCore::blend(m_stdDeviation, 0, progress),
WebCore::blend(m_color, Color(Color::transparent), progress),
m_type);
const DropShadowFilterOperation* fromOp = static_cast<const DropShadowFilterOperation*>(from);
IntPoint fromLocation = fromOp ? fromOp->location() : IntPoint();
int fromStdDeviation = fromOp ? fromOp->stdDeviation() : 0;
Color fromColor = fromOp ? fromOp->color() : Color(Color::transparent);
return DropShadowFilterOperation::create(
WebCore::blend(fromLocation, m_location, progress),
WebCore::blend(fromStdDeviation, m_stdDeviation, progress),
WebCore::blend(fromColor, m_color, progress), m_type);
}
}
#endif // ENABLE(CSS_FILTERS)