Bug 1409132 - Handle fX == 0 and fY == 0 appropriately when converting the frequency from user space to filter space. r?longsonr
MozReview-Commit-ID: 1kXGaXoE4ss
--- a/dom/svg/SVGFETurbulenceElement.cpp
+++ b/dom/svg/SVGFETurbulenceElement.cpp
@@ -142,20 +142,27 @@ SVGFETurbulenceElement::GetPrimitiveDesc
descr.Attributes().Set(eFloodColor, Color(0.5, 0.5, 0.5, 0.5));
return descr;
}
// We interpret the base frequency as relative to user space units. In other
// words, we consider one turbulence base period to be 1 / fX user space
// units wide and 1 / fY user space units high. We do not scale the frequency
// depending on the filter primitive region.
- gfxRect firstPeriodInUserSpace(0, 0, 1 / fX, 1 / fY);
+ // We now convert the frequency from user space to filter space.
+ // If a frequency in user space units is zero, then it will also be zero in
+ // filter space. During the conversion we use a dummy period length of 1
+ // for those frequencies but then ignore the converted length and use 0
+ // for the converted frequency. This avoids division by zero.
+ gfxRect firstPeriodInUserSpace(0, 0,
+ fX == 0 ? 1 : (1 / fX),
+ fY == 0 ? 1 : (1 / fY));
gfxRect firstPeriodInFilterSpace = aInstance->UserSpaceToFilterSpace(firstPeriodInUserSpace);
- Size frequencyInFilterSpace(1 / firstPeriodInFilterSpace.width,
- 1 / firstPeriodInFilterSpace.height);
+ Size frequencyInFilterSpace(fX == 0 ? 0 : (1 / firstPeriodInFilterSpace.width),
+ fY == 0 ? 0 : (1 / firstPeriodInFilterSpace.height));
gfxPoint offset = firstPeriodInFilterSpace.TopLeft();
FilterPrimitiveDescription descr(PrimitiveType::Turbulence);
descr.Attributes().Set(eTurbulenceOffset, IntPoint::Truncate(offset.x, offset.y));
descr.Attributes().Set(eTurbulenceBaseFrequency, frequencyInFilterSpace);
descr.Attributes().Set(eTurbulenceSeed, seed);
descr.Attributes().Set(eTurbulenceNumOctaves, octaves);
descr.Attributes().Set(eTurbulenceStitchable, stitch == SVG_STITCHTYPE_STITCH);