static int clampedToKernelSize(float value) { // Limit the kernel size to 500. A bigger radius won't make a big difference for the result image but // inflates the absolute paint rect too much. This is compatible with Firefox' behavior. unsigned size = std::max<unsigned>(2, static_cast<unsigned>(floorf(value * gaussianKernelFactor() + 0.5f))); return clampTo<int>(std::min(size, static_cast<unsigned>(gMaxKernelSize))); }
void FEGaussianBlur::calculateUnscaledKernelSize(unsigned& kernelSizeX, unsigned& kernelSizeY, float stdX, float stdY) { kernelSizeX = 0; if (stdX) kernelSizeX = max<unsigned>(2, static_cast<unsigned>(floorf(stdX * gaussianKernelFactor() + 0.5f))); kernelSizeY = 0; if (stdY) kernelSizeY = max<unsigned>(2, static_cast<unsigned>(floorf(stdY * gaussianKernelFactor() + 0.5f))); // Limit the kernel size to 1000. A bigger radius won't make a big difference for the result image but // inflates the absolute paint rect to much. This is compatible with Firefox' behavior. if (kernelSizeX > gMaxKernelSize) kernelSizeX = gMaxKernelSize; if (kernelSizeY > gMaxKernelSize) kernelSizeY = gMaxKernelSize; }
IntSize FEGaussianBlur::calculateUnscaledKernelSize(const FloatPoint& std) { ASSERT(std.x() >= 0 && std.y() >= 0); IntSize kernelSize; // Limit the kernel size to 1000. A bigger radius won't make a big difference for the result image but // inflates the absolute paint rect to much. This is compatible with Firefox' behavior. if (std.x()) { int size = std::max<unsigned>(2, static_cast<unsigned>(floorf(std.x() * gaussianKernelFactor() + 0.5f))); kernelSize.setWidth(std::min(size, gMaxKernelSize)); } if (std.y()) { int size = std::max<unsigned>(2, static_cast<unsigned>(floorf(std.y() * gaussianKernelFactor() + 0.5f))); kernelSize.setHeight(std::min(size, gMaxKernelSize)); } return kernelSize; }
float FEGaussianBlur::calculateStdDeviation(float radius) { // Blur radius represents 2/3 times the kernel size, the dest pixel is half of the radius applied 3 times return max((radius * 2 / 3.f - 0.5f) / gaussianKernelFactor(), 0.f); }