EUROGRAPHICS ’0x / N.N. and N.N. Volume 0 (1981), Number 0 (Editors)

Analytic Rasterization of with Polynomial Filters

Josiah Manson and Scott Schaefer

Texas A&M University

Figure 1: Vector graphic art of butterflies represented by cubic curves, scaled by the golden ratio. The images were analytically rasterized using our method with a radial filter of radius three.

Abstract We present a method of analytically rasterizing shapes that have curved boundaries and linear color gradients using piecewise polynomial prefilters. By transforming the convolution of filters with the image from an integral over area into a boundary integral, we find closed-form expressions for rasterizing shapes. We show that a poly- nomial expression can be used to rasterize any combination of polynomial curves and filters. Our rasterizer also handles rational quadratic boundaries, which allows us to evaluate and ellipses. We apply our technique to rasterizing vector graphics and show that our derivation gives an efficient implementation as a scanline rasterizer.

Categories and Subject Descriptors (according to ACM CCS): I.3.7 [Computer Graphics]: Three-Dimensional Graphics and Realism—Color, shading, shadowing, and texture

1. Introduction Although many shapes are stored in vector format, dis- plays are typically raster devices. This means that vector im- There are two basic ways of representing images: raster ages must be converted to pixel intensities to be displayed. graphics and vector graphics. Raster graphics are images that A major benefit of vector images is that they can be drawn are stored as an array of pixel values, whereas vector graph- accurately at different resolutions. For example, text appears ics represent images as collections of geometric shapes, such the same when printed at 600 dpi on paper or on a 72 dpi as lines, curves, circles, and . Vector graphics are screen and the butterflies in Figure1 are easily drawn at dif- used in many applications in computer graphics. In 3D, al- ferent sizes. Recently, mobile devices have become another most all is represented in vector form as polygons important medium and have generated a renewed interest in or smooth parametric shapes. Even in two dimensions, vec- scalable graphics. In particular, websites are often viewed tor images are extremely common. For example, nearly all both on computers with screens thousands of pixels wide and text is drawn with vector fonts, where letters are stored as on phones with screens hundreds of pixels across. Therefore quadratic curves that indicate the transition between the in- text, images, and icons must scale gracefully. side and outside of the letter. Vector images are also used in maps, signs, and logos to give a crisp, clear appearance. There has been a trend to improve the quality of images

c 0x The Author(s) Computer Graphics Forum c 0x The Eurographics Association and Blackwell Publishing Ltd. Published by Blackwell Publishing, 9600 Garsington Road, Oxford OX4 2DQ, UK and 350 Main Street, Malden, MA 02148, USA. J. Manson & S. Schaefer / Analytic Rasterization of Curves with Polynomial Filters rather than the number of pixels that are drawn. In part, this over areas of an image, and accurate approximations require trend exists because the rate at which mathematical oper- numerous point samples, regardless of the sampling pattern. ations are performed is increasing faster than the speed of Calculating area integrals is complicated, especially when memory. The biggest improvement to pixel quality comes taking occlusion into account, but calculating integrals from reducing aliasing. Aliasing refers to any artifact that is more tractable. Several papers [GT96, JP00, GBAM11] results from sampling a signal at a frequency less than twice have described methods of approximating area integrals by the highest frequency in the signal. Without changing the calculating a one dimensional quadrature over line samples sampling frequency, the only way to reduce aliasing is to that are computed analytically. This approach reduces the di- filter the signal to remove frequencies that are higher than mensionality of the problem by one, and yields a rasteriza- half of the sampling frequency. Multisampling, anisotropic tion with fewer artifacts from the same number of samples. texture-filtering, mipmapping, and motion blur are all filter- One can also evaluate area integrals exactly. One of the ing techniques commonly used to reduce aliasing. first methods to do so [Cat78] solves both the visibility and When rasterizing curves, another form of aliasing is integration problems simultaneously. The method clips poly- present. Most rasterizers only draw polygons and approx- gons to pixels, and then against each other, so that the re- imate curved boundaries as many-sided polygons. Thus, maining list of polygons in a pixel are all completely visi- aliasing appears both when sampling points on the to ble. It then sums the areas of the polygons in the pixel times form a and from polygon rasterization. Our paper their color, which is equivalent to sampling with a box filter. reduces both forms of aliasing simultaneously by directly Some other methods simplify cutting to pixels by first cut- rasterizing curved boundaries using high-order filters. We ting polygons into trapezoids aligned with scanlines [GT92]. show that analytic solutions for pixel values can be found us- These trapezoids are easier to cut into pixels than polygons ing polynomial filters to rasterize curved shapes with linear and one can easily find the area of a trapezoid. color gradients. We rasterize shapes with a variety of differ- Duff uses trapezoid decomposition to evaluate polynomial ent curves and have closed-form solutions for Bézier curves filters over polygons [Duf89]. Our method is more general, of arbitrary degree as well as rational quadratic Bézier because we are able to rasterize curved boundaries in addi- curves, which allows us to rasterize exact circles and el- tion to polygonal boundaries. Our derivation of closed-form lipses. In practice, this set of shapes encompasses most prim- rasterization equations also leads to a different rasterization itives that make up vector images. algorithm, because Duff integrates over areas perpendicu- lar to the scanline, whereas we integrate over the boundary 1.1. Related Work along the scanline. The simplest form of rasterization is point sampling, which Some methods rasterize polygons with radial filters. An simply determines if a point is inside of a polygon or not. early method [Cat84] clips polygons to pixels and adds each Calculating which polygon, if any, contains an arbitrary sam- edge’s contribution using a radial filter. If an edge forms a ple can be done using ray casting [App68]. One can also re- triangle with the center of the filter, that triangle is split into cursively cut the image into quadrants, subdividing around two right triangles. Each right triangle is parameterized by polygon edges [War69]. More typically, pixel values are cal- two values that index a lookup table to find the edge’s con- culated a scanline at a time [WREE67]. tribution. A more recent algorithm [LCSW05b] removes the The solution to reducing aliasing artifacts is to convolve need of clipping polygons to pixels by taking the modulo of the signal with a filter that removes frequencies that are final pixel values. The method also has analytic solutions for higher than half the sampling rate. This is equivalent to as- polynomial filters, but cannot use filters with negative val- signing pixel values by integrating the product of the image ues because of the modulo operation. The authors published and the filter centered at the pixel. Approximating this in- a paper describing positive filters that are suitable for their tegral by quadrature is called supersampling, and as more method [LCSW05a]. samples are used for each pixel, the quality of the rasteriza- There are also some rasterizers that are difficult to clas- tion improves. If subsamples are also on a regular grid, alias- sify. One method approximates the rasterization of self- ing artifacts can still occur for very high-frequency images. intersecting polygons [Doa04]. In this method, the con- In ray casting there is significant freedom in sample place- tours within pixels that contain intersections are simpli- ment, and several early papers [DW85, Coo86, Mit87] ana- fied and clipped against other contours. Another method lyze image sampling patterns. These works show that sam- calculates analytic rasterizations of shapes filtered by box ples should be random but have uniform density, and there splines [McC95]. Filters must be positive, and the method is renewed interest in such sampling patterns [JC99, HC06, only rasterizes triangles. Auzinger et al. [AGJ12] analyti- Kal07,GM09,Wei10,Fat11,EDP ∗11]. There is also research cally rasterize antialiased triangles and tetrahedra with linear on how to optimize the sampling pattern and weights simul- data defined over the simplices. We also handle linear gra- taneously [LA06]. dients, but we analytically rasterize complex, curved, two- Calculating prefiltered pixel values requires an integral dimensional shapes. A process similar to polygon rasteri-

c 0x The Author(s) c 0x The Eurographics Association and Blackwell Publishing Ltd. J. Manson & S. Schaefer / Analytic Rasterization of Curves with Polynomial Filters zation has also been used to calculate irradiance in the area integral a raytracer by using Stokes’ theorem to evaluate incoming ZZ light from polygonal light sources [CA00, CA01]. I(x,y)h(x − `x,y − `y) dx dy. R2 The main contribution of our paper is prefiltered, an- We can simplify the expression by changing the domain of tialiased rasterization of shapes with curved boundaries. integration to be only over the interior of M because the im- There has been some work in directly rasterizing shapes age is zero outside of the boundary. with curved boundaries, but most rasterizers simply approxi- ZZ mate curved boundaries by subdividing the curves into many c(x,y)h(x − `x,y − `y) dx dy (1) x,y∈M sided polygons [Cat74]. One of the first papers to rasterize curved shapes [CJ88] accurately determined if pixels were The divergence theorem relates an integral over the bound- inside or outside of the region bounded by the curves, but ary of a domain to an integral over the domain by only performed point sampling for rasterization. I ZZ F(p(s)) · n(s) ds = ∇ · F(x,y) dx dy, Most antialiased rasterization methods estimate the dis- p(s)∈∂M x,y∈M tance to the boundary in some way [FF97, LB05, QMK06, where the unit normal of the shape is given by n(s) and the QMK08, NH08] and approximate a radial filter by setting domain’s boundary is given by the arc-length parameterized pixel values based on the distance to the boundary. Using curve p(s). Therefore, if we find a vector function F(x,y) distance to approximate a radial filter is only exact for line whose divergence is equal to f (x,y) = c(x,y)h(x − `x,y − segments when no vertices are in the filter’s support and `y), then we can evaluate Equation1 as a boundary integral. works especially poorly between curves that are within a fil- Because divergence is a sum of differentials, we find ter diameter of one another. F(x,y) by integrating f (x,y) and we parameterize solutions Another method [MS11] calculates exact filtering of for F(x,y) by α, such that shapes bounded by Bézier curves. The method is reminiscent  (1 − α)R x f (u,y) du  of the recursive algorithm of Warnock, because the method F(x,y) = −∞ . αR y f (x,u) du calculates wavelet coefficients over a quad-tree to produce −∞ a filtered rasterization of the shape. If the scaling func- Thus, we have converted the rasterization problem from tion approximates a low-pass filter, such as a box filter, the integration over an unknown interior to integration over a method performs antialiasing. Unfortunately, this method known boundary. Wavelet rasterization [MS11] has a similar only works with wavelet filters, and most common filters derivation, but uses the inner product to calculate projections other than the box filter are not wavelets. Our method com- onto a wavelet basis. In the case of wavelets, it is possible to bines the best aspects from Duff’s work [Duf89] and wavelet choose α so that F(x,y) has compact support, but compact rasterization [MS11] because our method has closed-form support is impossible for arbitrary polynomial filters. How- solutions to polynomial curves sampled using polynomial ever, if we choose α = 0, then F(x,y) has infinite support filters. In addition, we show how our derivation can rasterize only in the direction of the scanline, which we will exploit shapes with rational quadratic boundaries such as circles and during rasterization in Section 2.1. shapes with linear color gradients in their interior. The unit normal of the curve is defined as n(s) = p⊥(s)/kp0(s)k, where the direction perpendicular to the curve is 2. Rasterizer  0  ⊥ py(s) Rasterization is the process of sampling an image I(x,y) p (s) = 0 . −px(s) defined by a set of closed shapes, where each shape Mi is 0 defined by a set of boundary curves ∂Mi. We assume that We use the notation that p (s) is the derivative of p(s) with the input does not contain overlapping shapes. If this is respect to s, while x and y subscripts, respectively, refer not the case, we can preprocess the input to remove over- to the first and second components of a vector quantity. laps [HW07]. We define I(x,y) = ∑i Ii(x,y) as the sum of Changing variables from an arc-length parameterization ds images of each shape Ii(x,y), where each shape has color to a uniform parameterization dt weights the differential by 0 ci(x,y) inside of Mi and is zero outside. To remove aliasing, ds = kp (t)k dt, which simplifies our expression because we prefilter the image by convolving I(x,y) with a low-pass p⊥(t)kp0(t)k dt ⊥ n(s) ds = kp0(t)k = p (t) dt. The dot product be- filter h(x,y) prior to point sampling, which is equivalent to tween vector functions also simplifies to a scalar product, taking the inner product of the image I(x,y) with the filter I ⊥ I 0 centered at each pixel. We explain how to rasterize the image F(p(t)) · p (t) dt = Fx(p(t))py(t) dt, (2) of a single shape and drop the shape index i in the remainder of the paper because the final image is just a sum of shape that uses only the x-component, Fx(x,y), of F(x,y) because images. We calculate the value of a pixel located at `x,`y by the y-component, Fy(x,y), is zero when α = 0. Note that

c 0x The Author(s) c 0x The Eurographics Association and Blackwell Publishing Ltd. J. Manson & S. Schaefer / Analytic Rasterization of Curves with Polynomial Filters

Figure 2: A filter f (x,y) is shown on the left and its inte- gral in the x-direction Fx(x,y) is shown on the right. The Figure 3: We decompose a filter f (x) into pixel sized pieces graphs are plotted over the filter’s support. In Fx(x,y), val- and evaluate each piece separately. The integral over f (x) ues remain constant in the direction of integration beyond is equal to one, but the integral over each piece is not. f (x,y)’s support.

decomposition of the filter into pixel-sized pieces and the most boundary curves p(t) are defined piecewise, and it is integrals of the pieces. Each piece h(i, j)(x,y) is defined over trivial to sum the integral of each piece of the curve to eval- the (x,y) ∈ [0,1)2 domain and is indexed by i, j so that uate Equation2. Differentiation, integration, multiplication, (i, j) and function application are closed under polynomials; so if h(x,y) = ∑∑h (x − i,y − j). (3) h(x,y), c(x,y), and p(t) are polynomial, the entire expres- i j sion evaluates to a polynomial. An example of f (x,y) and We then define the colored filter pieces over the same do- (i, j) (i, j) its integral Fx(x,y) are shown in Figure2. In this figure, it is main as f (x,y) = c(x + `x,y + `y)h (x,y), with inte- clear that the support of Fx(x,y) extends beyond the support (i, j) R x (i, j) grals Fx (x,y) = −∞ f (u,y) du. Because our filter is of f (x,y) in the positive x-direction only, so that the value of piecewise polynomial with polynomial pieces that align to a pixel depends on the boundary to the right of the pixel. the pixel grid, we cut boundary curves to the pixel grid. With There are a variety of filters h(x,y) to choose from. Some proper care, solving for the points to cut polynomials is ro- filters, such as the box, tent, and Gaussian filters, blur the bust even for degenerate curves [Bli05,Bli07]. We index cut image to remove aliasing. There are also frequency bandpass curves by the cell λx,λy so that each curve segment filters that approximate the sinc function. The sinc function   p(λx,λy)(t) = p(t) ∩ [ , )2 + ( , ) − ( , ) has too large of a support to be practical, so sinc is typ- 0 1 λx λy λx λy ically windowed to produce tensor-product filters such as is within the same [0,1)2 domain as the filter pieces. We can the Lánczos and Mitchell-Netravali [MN88] filters. In two- evaluate each pixel sized piece of the filter independently dimensions, a circular bandpass results in a radial jinc filter. and sum the results to evaluate a pixel with indices ` ,` by If a filter is not already polynomial, we can approximate it x y by a piecewise polynomial. We approximate windowed jinc Z 1   F(i, j) p(`x+i,`y+ j)(t) p0(`x+i,`y+ j)(t) dt. (4) and Lánczos filters by piecewise cubic and bicubic polyno- ∑∑ x y i j 0 mials respectively with C0 continuity aligned to pixel bound- aries. This approximation produces images that are visually Because summation is commutative, the order in which we indistinguishable from images of the original filters. evaluate Equation4 does not matter and allows us to evalu- ate each curve, scanline, and filter piece in parallel. Given a curve p(λx,λy)(t) and filter piece f (i, j)(x,y), we can see from 2.1. Scanline Algorithm Equation4 that p(λx,λy)(t) = p(`x+i,`y+ j)(t), and we there- To rasterize an image, we evaluate Equation2 using the fore add the contribution from curve p(λx,λy)(t) to the pixel curves that are in the support of Fx(x,y), which is finite in y, (λx − i,λy − j). Our only constraint is that we must evaluate but is infinite in the positive x-direction. This directionality each filter piece in scanline order due to the infinite support (i, j) of infinite support leads to a scanline rasterization algorithm of Fx (x,y). that evaluates pixels from right to left (although changing the direction of integration yields a traditional left to right Figure4 illustrates the process of rasterizing a single piece (i, j) rasterization algorithm). We assume that the filter is repre- of f (x,y). We show a scanline consisting of four pixels, sented as a piecewise polynomial where the pieces align to where each row shows how we evaluate the pixel drawn in (i, j) the pixel grid. Since the polynomial pieces do not overlap, orange with the extended support of Fx (x,y) drawn in red. we can write the filter as a sum of polynomial pieces. In Fig- The figure shows evaluation of a single curve that we draw in ure3, we show the decomposition of a one-dimensional tent blue, with normals to indicate the curve’s orientation. When filter into multiple pieces. We show the full filter and its inte- the curve is within the support of the filter piece (top row), gral on the top row of the figure, below which, we show the we evaluate of the curve integral and immediately update the

c 0x The Author(s) c 0x The Eurographics Association and Blackwell Publishing Ltd. J. Manson & S. Schaefer / Analytic Rasterization of Curves with Polynomial Filters

Figure 5: Examples of (a) point sampling, (b) 16x MSAA Figure 4: The thick box outlines show which pixel is being tent filtering using an ATI Radeon HD 5700, (c) analytic tent evaluated for a filter piece f (i, j)(x,y). Evaluating a curve filtering. has two possible values: one within the filter piece; and one for all pieces to the left, found by setting the curve’s x-coordinate equal to one. a batch process prior to rasterization, where curves are dis- tributed between processors. Each scanline is then evaluated pixel value. All pixels left of the curve (bottom rows) will in parallel, as is each polynomial piece of a filter. Note that (i, j) this parallel implementation processes each curve a number have the same value added because F (x,y) is constant x of times equal to the area of support of the filter. It is also with respect to x in the red region. We efficiently propagate possible to write an efficient serial implementation that scans this constant contribution by evaluating the curve once to over the entire image once but maintains an array of accumu- update an accumulator that we add to remaining pixels in lation values, one for each polynomial piece, and processes the scanline. Furthermore, we can simplify Equation2 for each curve once. propagated values by treating the curve as a that connects the curve’s end points and has x-coordinates equal to one. Before processing a scanline, the accumulator 3. Results is initialized to zero outside of the shape. The orientation of a curve automatically adds color as the filter moves inside Closed-form solutions are available for a wide variety of in- the shape’s boundary and subtracts color as the filter moves teresting filters and curves and we show that high-order fil- outside of the shape. ters reduce aliasing artifacts in several test images. We also show that calculating closed-form solutions of the rasteriza- Rasterizing shapes with linear color gradients is almost tion equation is competitive in speed with approximate solu- the same as rasterizing shapes with constant color. The only tions while generating higher-quality images by comparing (i, j) difference is that in Equation4, Fx (x,y) depends on the our implementation to other rasterizers. pixel coordinates ` ,` when c(x,y) is linear. We define the x y The advantages of using high-order filters are most appar- color of the shape as c(x,y) = C +C x +C y in the shape’s 0 1 2 ent in images with high-frequency details. We show rasteri- reference coordinate system. This means that the difference zations of test patterns that are prone to aliasing in Figures5 in value when moving from a pixel (` ,` ) to (` − 1,` ) is x y x y and6, where we rasterize the images using different filters. Z x (i, j) Figure5 shows lines that are at a frequency of 1/4 lines per −C1 h (u,y) du. (5) −∞ pixel at the top to 2 lines per pixel at the bottom. This figure illustrates the difference between point sampling and super- The integral of h(i, j)(x,y) is constant to the right of the filter sampling with a GPU (ATI Radeon HD 5700) versus ana- piece, so we augment the accumulation buffer with a linear lytically rasterizing images. Image (a) is point sampled and term that stores the value of Equation5. The modification to aliasing is clearly visible. Both (b) and (c) are sampled us- our algorithm is simply that after processing a pixel, we add ing a tent filter, but (b) is supersampled with 16 points per the linear accumulation term to the constant accumulation pixel and has obvious aliasing, whereas exact evaluation of term. This process is easily extended to general polynomial (c) using our method suppresses most aliasing. color functions, where a quadratic term is accumulated into a linear term, and so on. Figure6 shows differences between analytically evaluated filters of increasing quality. The top row shows examples using linear curves, while the bottom shapes are made of 2.2. Implementation quadratic curves. As the order of the filter increases, the tran- We have described a general framework for a rasterization sition between detailed and blurred regions becomes sharper algorithm. The key idea is that the equations we use for ras- and aliasing is reduced. The box filter (a) is clearly the worst terization naturally lead to efficient evaluation by rasterizing filter, because it does not remove high frequencies very well, in scanline order. Rasterization using our method is easily which results in obvious aliasing patterns. The tent filter (b) parallelizable. Cutting all of the curves to pixels is done as is noticeably better than the box filter. Although some high

c 0x The Author(s) c 0x The Eurographics Association and Blackwell Publishing Ltd. J. Manson & S. Schaefer / Analytic Rasterization of Curves with Polynomial Filters

Figure 6: Analytic rasterizations using different filters are shown. The first row uses radial triangles and the second row uses rings of quadratic curves. The columns show the filters: (a) box, (b) tent, (c) Mitchell-Netravali, (d) Lánczos 3, and (e) radial 3.

Fig.5 Fig.6 (top) Fig.6 (bottom) AGG 2.73 0.25 0.35 Cairo 5.35 0.57 2.34 Wavelet 3.84 0.42 3.14 Box 1.23 (0.60) 0.14 (0.07) 0.37 (0.17) Tent 2.36 (0.83) 0.27 (0.12) 0.75 (0.26) Q. B-spline 9.60 (3.29) 1.02 (0.31) 4.45 (1.26) Mitchell 21.2 (6.90) 2.26 (0.79) 37.0 (11.4) Lánczos 2 26.3 (7.64) 2.71 (0.96) 27.6 (7.54) Lánczos 3 48.7 (16.0) 5.37 (1.88) 115. (37.7) Radial 2 21.2 (5.70) 2.31 (0.78) 17.1 (5.02) Figure 7: We demonstrate rasterization of rational Bézier Radial 3 42.9 (14.1) 4.64 (1.68) 45.8 (15.6) curves of varying sizes in a 128 × 64 pixel image. Table 1: Times to rasterize various images, measured in mil- liseconds. AGG, Cairo, and wavelet rasterization all use a box filter. Serial times are followed by parallel times using four processors in parentheses. These are an important class of curves because they include all circular and elliptical arcs. We show an Apollonian gasket composed of rational quadratic Bézier curves that we evalu- ate exactly using a box filter in Figure7. frequencies still pass in the top image, the center of the cir- We present rasterization timings for the patterns in Fig- cle is much closer to a uniform color. A disadvantage of the ure5 (128 2 pixels) and Figure6 (64 2 pixels) in Table1. Fig- tent filter is that low frequencies are attenuated too much, ure5 contains 1024 lines in 256 quads, Figure6 (top) con- which is visible as blurriness. The Mitchell-Netravali filter tains 96 lines in 32 triangles, and Figure6 (bottom) contains (c) appears slightly better than the tent filter. The Lánczos 3 32 concentric rings made out of a total of 128 non-rational (d) and radial (e) filters both have a radius of 3, but (e) is the quadratic curves and 64 radial lines. We ran tests on an In- only filter that is not a tensor product. In (d) it is easy to see tel Core i7 870. The first row contains the times taken by the square fall-off of aliasing in the bottom picture compared Anti-Grain Geometry (AGG), which is a highly optimized, to the circular fall-off in (e). high-quality software rasterizer. The second contains tim- Our method is not restricted to polynomial curves and can ings for Cairo, which is a rasterizer used in several large theoretically be applied to any boundary defined by paramet- software projects. Both AGG and Cairo use box filtering and ric curves. Closed-form expressions are not guaranteed for approximate curved boundaries by polygons, for which we all curves but do exist for rational quadratic Bézier curves. used their default tolerances to subdivide curves. The third

c 0x The Author(s) c 0x The Eurographics Association and Blackwell Publishing Ltd. J. Manson & S. Schaefer / Analytic Rasterization of Curves with Polynomial Filters

Figure 9: In the image on the left, curves are approximated 1 by polygons within a tolerance of 2 of a pixel, while the image on the right is calculated exactly.

provement in image quality, but takes only twice as long to compute as a box filter and remains competitive in time with AGG, which uses a box filter. High-order filters are expen- Figure 8: Speedup for different numbers of threads on a sive to compute, but may be acceptably fast for final, pro- four core Intel Core i7 870. The ideal speedup is shown as duction renders. a dashed black line, and the speedup for different filters is Figure8 shows the speedups we achieve rendering Fig- shown as solid lines of different colors. ure 11 with a parallel implementation of our algorithm us- ing OpenMP to split calculations between different numbers of threads on a four core system. The image contains 1,577 row contains timings for wavelet rasterization [MS11] us- cubic curves that we rasterized into a 316 × 613 pixel grid. ing the authors’ implementation, which analytically raster- Speedups vary based on filter width. Some filters like the box izes piecewise polynomial curves using a box filter. The re- filter are simple enough that the overhead of parallelization maining times are from our method using different filters. prevents ideal scaling. Nevertheless, with four cores we still We use a serial implementation of our algorithm to compare achieve a 2.4× speedup. As the size of the filter increases, with the other methods and include times for our parallel im- Equation2 requires more operations and our speedup ap- plementation running on four processors in parentheses. The proaches the perfect scaling relationship. In the case of a Mitchell-Netravali and Lánczos 2 filters are both cubic ten- quadratic B-spline filter, we achieve a 3.5× speedup over sor product filters, but have a different number of zero terms. our serial implementation. The Radial 2 filter has the same support but has fewer coef- A common approach to handling curved boundaries is to ficients compared to the cubic tensor product filters because approximate curves by line segments. However, this form we use a filter of cubic total degree. of approximation produces its own aliasing artifacts, even The other methods that we compare against rasterize poly- when performing analytic filtering. For example, Figure9 is gons using a box filter, so our box filter produces the same composed of quadratic curves. On the left, we subdivided output as them for Figure5 and Figure6 (top). AGG and curves into line segments so that they are within 0.5 pixels Cairo approximate quadratic and cubic curves as polygons, of the actual curve. On the right, we show curves that are so we show the time for these approximate rasterizations in rasterized with exact formulas for quadratics. In both cases, bold. Comparing against AGG, we see that the times to ras- we use our method for analytic rasterization so that the dif- terize shapes are similar, even though we compute an ana- ferences are only due to approximating curves by line seg- lytic rasterization of quadratic curves rather than a polygonal ments. Notice that a black ring appears in the left image and approximation. Cairo is slower than AGG and our method, that the aliasing patterns appear polygonal rather than round. because it is more generic and is designed for more compli- It is also possible that a topological problem can occur when cated rendering operations. subdividing curves into line segments because, even if in- put curves do not intersect, the line segments approximating Unlike the other three methods, our technique can analyt- those curves may intersect. Determining the level of subdivi- ically filter images using higher order filters. As the order of sion required to prevent line segments from intersecting can the filter increases, so does the computation time, which is be complicated and expensive. approximately linear in the area sampled by the filter. The tent filter is interesting because it provides a significant im- We show examples of SVG files that contain cubic curves

c 0x The Author(s) c 0x The Eurographics Association and Blackwell Publishing Ltd. J. Manson & S. Schaefer / Analytic Rasterization of Curves with Polynomial Filters

Figure 11: An image rasterized using a box filter (left), Mitchell-Netravali filter (center), and radial filter of radius 3 (right). A zoomed-in section of the image is shown below each high-resolution image to show differences in pixel val- ues.

different filters on a detailed vector image without Moiré ar- tifacts that is made of 1,577 cubic curves.

4. Conclusions and Future Work With the processing power of video cards and the variety of display devices increasing in tandem, accurate rasterization of shapes is both more desirable and achievable. In this pa- per, we have revisited the theory behind rasterization, and Figure 10: A vector graphic image of an icon with linear described a new approach for finding analytic solutions for gradients and cubic Bézier curves. On top we show the vec- pixel colors using a variety of filters when rasterizing several tor image, with rasterizations at 642 resolution using box, types of curves that are commonly used in vector graphics. tent, quadratic B-spline, and Mitchell-Netravali filters be- Rasterization is a complex subject and remains an inter- low. esting topic for research. There are a couple of extensions to our method that may be useful. The curves and color gradi- ents described in our paper are closed under affine transfor- mations, but rasterizing three-dimensional scenes adds com- in Figures1, 10, and 11. Figure1 shows a vector image that plicated occlusions and requires a projective transformation. is scaled by irrational values. There are 60 butterflies, and For example, Gouraud shading defines linear color functions each butterfly contains 452 cubic curves that form two col- over triangles, but Gouraud shaded triangles have color func- ored shapes so that there are 27,120 cubic curves in total. tions that are rational with respect to screen coordinates after Figure 10 shows an example of an icon made from 108 cubic projection. Closed-form expressions of Equation1 may ex- curves that incorporates linear gradients and text. We show ist for rational functions, but are certainly not polynomial. 2 the input vector image on the top left, and show a 64 pixel Rasterization of textured triangles is even more difficult. It rasterization from Inkscape and from our implementation of could also be useful to apply our method to higher dimen- box, tent, quadratic B-spline, and Mitchell-Netravali filters. sions, for example, to calculate motion blur by integrating Note that many renderers, including Adobe Acrobat, have over a three-dimensional domain. problems rendering the curved boundary between the lin- ear color gradients correctly. This problem is visible in the Acknowledgements Inkscape image as a bright halo. Hence, even the vector in- put may appear to have artifacts depending on your choice Work was supported by NSF CAREER award IIS 1148976 of viewing software. Finally, Figure 11 shows the effect of and the NSF Graduate Research Fellowship Program.

c 0x The Author(s) c 0x The Eurographics Association and Blackwell Publishing Ltd. J. Manson & S. Schaefer / Analytic Rasterization of Curves with Polynomial Filters

References [HC06]H UANG R.,CHAE S.-I.: Implementation of an openvg rasterizer with configurable anti-aliasing and multi-window scis- [AGJ12]A UZINGER T., GUTHE M.,JESCHKE S.: Analytic anti- soring. In International Conference on Computer and Informa- aliasing of linear functions on polytopes. Computer Graphics tion Technology (2006), pp. 179–185.2 Forum (Proceedings of EUROGRAPHICS) 31, 2 (2012), 335– 344.2 [HW07]H ANNIEL I.,WEIN R.: An exact, complete and efficient computation of arrangements of bézier curves. In Symposium on [App68]A PPEL A.: Some techniques for shading machine ren- Solid and Physical Modeling (2007), pp. 253–263.3 derings of solids. In AFIPS (1968), pp. 37–45.2 [JC99]J OUPPI N. P., CHANG C.-F.: Z3: An economical hard- LINN IEEE [Bli05]B J. F.: How to solve a quadratic equation? ware technique for high-quality antialiasing and transparency. Comput. Graph. Appl. 25 , 6 (2005), 76–79.4 In SIGGRAPH/Eurographics Workshop on Graphics Hardware [Bli07]B LINN J. F.: How to solve a cubic equation, part 5: Back (1999), pp. 85–93.2 to numerics. IEEE Comput. Graph. Appl. 27, 3 (2007), 78–89.4 [JP00]J ONES T. R., PERRY R. N.: Antialiasing with line [CA00]C HEN M.,ARVO J.: A closed-form solution for the irra- samples. In Eurographics Workshop on Rendering Techniques diance due to linearly-varying luminaries. In Eurographics Work- (2000), pp. 197–206.2 shop on Rendering Techniques (2000), pp. 137–148.3 [Kal07]K ALLIO K.: Scanline edge-flag algorithm for antialias- [CA01]C HEN M.,ARVO J.: Simulating non-lambertian phe- ing. In Theory and Practice of Computer Graphics (2007), nomena involving linearly-varying luminaires. In Eurographics pp. 81–88.2 Workshop on Rendering Techniques (2001), pp. 25–38.3 [LA06]L AINE S.,AILA T.: A weighted error metric and opti- [Cat74]C ATMULL E.E.: A subdivision algorithm for computer mization method for antialiasing patterns. Computer Graphics display of curved surfaces. PhD thesis, 1974. The University of Forum 25, 1 (2006), 83–94.2 Utah.3 [LB05]L OOP C.,BLINN J.: Resolution independent curve ren- [Cat78]C ATMULL E.: A hidden-surface algorithm with anti- dering using programmable graphics hardware. ACM Transac- aliasing. In SIGGRAPH (1978), pp. 6–11.2 tions on Graphics 24, 3 (2005), 1000–1009.3 [Cat84]C ATMULL E.: An analytic visible surface algorithm for [LCSW05a]L IN Z.,CHEN H.-T., SHUM H.-Y., WANG J.: Op- independent pixel processing. In SIGGRAPH (1984), pp. 109– timal polynomial filters. Journal of Graphics Tools 10, 1 (2005), 115.2 27–38.2 [CJ88]C ORTHOUT M.,JONKERS H.: A new point containment [LCSW05b]L IN Z.,CHEN H.-T., SHUM H.-Y., WANG J.: Pre- algorithm for B-regions in the discrete plane. In Theoretical foun- filtering two-dimensional polygons without clipping. Journal of dations of computer graphics and CAD (1988), pp. 297–306.3 graphics, GPU, and game tools 10, 1 (2005), 17–26.2 [Coo86]C OOK R. L.: Stochastic sampling in computer graphics. [McC95]M CCOOL M. D.: Analytic antialiasing with prism ACM Transactions on Graphics 5, 1 (1986), 51–72.2 splines. In SIGGRAPH (1995), pp. 429–436.2 [Doa04]D OAN K.: Antialiased rendering of self-intersecting [Mit87]M ITCHELL D. P.: Generating antialiased images at low polygons using polygon decomposition. In Pacific Graphics sampling densities. In SIGGRAPH (1987), pp. 65–72.2 (2004), pp. 383–391.2 [MN88]M ITCHELL D. P., NETRAVALI A. N.: Reconstruction [Duf89]D UFF T.: Polygon scan conversion by exact convolution. filters in computer-graphics. ACM Computer Graphics 22, 4 In International Conference On Raster Imaging and Digital Ty- (1988), 221–228.4 pography (1989), pp. 154–168.2,3 [MS11]M ANSON J.,SCHAEFER S.: Wavelet rasterization. Com- [DW85]D IPPÉ M.A.Z.,WOLD E. H.: Antialiasing through puter Graphics Forum 30, 2 (2011), 395–404.3,7 stochastic sampling. In SIGGRAPH (1985), pp. 69–78.2 [NH08]N EHAB D.,HOPPE H.: Random-access rendering of [EDP∗11]E BEIDA M.S.,DAVIDSON A.A.,PATNEY A., general vector graphics. In SIGGRAPH Asia (2008), pp. 135:1– KNUPP P. M., MITCHELL S.A.,OWENS J. D.: Efficient max- 135:10.3 imal poisson-disk sampling. ACM Transactions on Graphics 30, 4 (2011), 49:1–49:12.2 [QMK06]Q IN Z.,MCCOOL M.D.,KAPLAN C. S.: Real-time texturemapped vector glyphs. In Symposium on Interactive 3D [Fat11]F ATTAL R.: Blue-noise point sampling using kernel den- Graphics and Games (2006), pp. 125–132.3 sity model. ACM Transactions on Graphics 28, 3 (2011), 48:1– 48:10.2 [QMK08]Q IN Z.,MCCOOL M.D.,KAPLAN C.: Precise vector textures for real-time 3D rendering. In Symposium on Interactive [FF97]F ABRIS A.E.,FORREST A. R.: Antialiasing of curves by 3D Graphics and Games (2008), pp. 199–206.3 discrete pre-filtering. In SIGGRAPH (1997), pp. 317–326.3 [War69]W ARNOCK J.E.: A hidden surface algorithm for com- [GBAM11]G RIBEL C.J.,BARRINGER R.,AKENINE-MÖLLER puter generated halftone pictures. PhD thesis, 1969. The Uni- T.: High-quality spatio-temporal rendering using semi-analytical versity of Utah.2 visibility. In SIGGRAPH (2011), pp. 54:1–54:12.2 [Wei10]W EI L.-Y.: Multi-class blue noise sampling. ACM [GM09]G AMITO M.N.,MADDOCK S. C.: Accurate multidi- Transactions on Graphics 29, 4 (2010), 79:1–79:8.2 mensional poisson-disk sampling. ACM Transactions on Graph- ics 29, 1 (2009), 8:1–8:19.2 [WREE67]W YLIE C.,ROMNEY G.,EVANS D.,ERDAHL A.: Half-tone perspective drawings by computer. In AFIPS (1967), [GT92]G ISH W., TANNER A.: Hardware antialiasing of lines pp. 49–58.2 and polygons. In Symposium on Interactive 3D graphics (1992), pp. 75–86.2 [GT96]G UENTER B.,TUMBLIN J.: Quadrature prefiltering for high quality antialiasing. ACM Transactions on Graphics 15, 4 (1996), 332–353.2

c 0x The Author(s) c 0x The Eurographics Association and Blackwell Publishing Ltd.