10
Volume 18 (1999 ), number 1 pp. 69–78 COMPUTER forum GRAPHICS Approximate Line Scan-Conversion and Antialiasing Jim X. Chen and Xusheng Wang Department of Computer Science, George Mason University, USA [email protected] Abstract This paper presents an approximate multiple segment line scan-conversion method — the Slope Table Method. The statistics show that the new method can increase the percentage of multiple segment lines (i.e., lines with more than one segment) in an N × N raster area from about 39% to more than 99%. In software implementation for scan-conversion and antialiasing of randomly generated lines, this method is on average more than 6 times faster than Gupta’s antialiasing line algorithm. Compared with other line scan-conversion methods, the method may choose pixels which are not the closest to the line (i.e., error pixels). Here the paper demonstrates that the visual effect is acceptable in most applications with the error pixels. Keywords: Slope Table, GRL (Group Representative Line), multiple segment, scan-conversion, antialiasing 1. Introduction The property that a line may be divided into several identical segments was studied in scan-conversion and compaction 1, 10, 11, 12, 15, 17 . All these methods try to find the best pixels to approach the accurate line. However, as we know 23 , the percentage of one-segment lines in an N ×N raster area is more than 60%, so the percentage of the profitable lines using the multiple segment property is less than 40%. The advantage of the multiple segment property is limited. In this paper, we use a Slope Table Method to improve the multiple segment property of a line. This method is an approximation and needs an additional N element read-only memory (ROM) for an N × N raster area, but it can increase the percentage of lines with more than one segment in a raster area up to 99%. Such a big change on the multiple segment property brings improvements for line scan-conversion and other line drawing applications, such as antialiasing. The new method has two major shortcomings: the ad- ditional memory needed and the error pixels generated. The additional memory needed is 1K for a 1024 × 1024 raster area, so it is not a problem. The error pixels need to be studied. The paper will analyse the error pixels’ er- ror magnitude and distribution in detail. Actually, with N element additional memory, only about 11% of the lines in an N × N raster area have larger than 0.5 pixel error, and the lengths of all these lines are longer than N/2 pixels. When a line is antialiased, the visual effect of the error can be corrected. Moreover, when this method is applied to animations, the lines and polygon edges are moving, and the error perceived by our eyes can be ignored. Here we first briefly introduce the Slope Table method and analyse its properties. Then we present the applica- tions of the method in line compaction, scan-conversion, and antialiasing. Our major contribution includes: a) in- troducing the Slope Table method to improve the num- ber of lines with multiple segments; b) applying multiple segment line scan-conversion to antialiasing; c) using the Slope Table method to save the pixel patterns of all possible lines in hardware. Theoretically, our scan- conversion method on average could reach 14 times speedup over existing methods. Software implementa- tion shows more than 6 times speedup over Gupta’s line antialiasing algorithm 18 for randomly generated (3 pixel wide) lines. c The Eurographics Association and Blackwell Publishers Ltd 1999. Published by Blackwell Publishers, 108 Cowley Road, Oxford OX4 1JF, UK and 350 Main Street, Malden, MA 02148, USA. 69

Approximate Line Scan-Conversion and Antialiasing

Embed Size (px)

Citation preview

Page 1: Approximate Line Scan-Conversion and Antialiasing

Volume 18 (1999 ), number 1 pp. 69–78 COMPUTER forumGRAPHICS

Approximate Line Scan-Conversion and Antialiasing

Jim X. Chen and Xusheng Wang

Department of Computer Science, George Mason University, USA

[email protected]

Abstract

This paper presents an approximate multiple segment line scan-conversion method — the Slope Table Method.

The statistics show that the new method can increase the percentage of multiple segment lines (i.e., lines

with more than one segment) in an N × N raster area from about 39% to more than 99%. In software

implementation for scan-conversion and antialiasing of randomly generated lines, this method is on average

more than 6 times faster than Gupta’s antialiasing line algorithm. Compared with other line scan-conversion

methods, the method may choose pixels which are not the closest to the line (i.e., error pixels). Here the

paper demonstrates that the visual effect is acceptable in most applications with the error pixels.

Keywords: Slope Table, GRL (Group Representative Line), multiple segment, scan-conversion, antialiasing

1. Introduction

The property that a line may be divided into several

identical segments was studied in scan-conversion and

compaction1, 10, 11, 12, 15, 17. All these methods try to find

the best pixels to approach the accurate line. However,

as we know23, the percentage of one-segment lines in an

N×N raster area is more than 60%, so the percentage of

the profitable lines using the multiple segment property

is less than 40%. The advantage of the multiple segment

property is limited.

In this paper, we use a Slope Table Method to improve

the multiple segment property of a line. This method is

an approximation and needs an additional N element

read-only memory (ROM) for an N × N raster area,

but it can increase the percentage of lines with more

than one segment in a raster area up to 99%. Such

a big change on the multiple segment property brings

improvements for line scan-conversion and other line

drawing applications, such as antialiasing.

The new method has two major shortcomings: the ad-

ditional memory needed and the error pixels generated.

The additional memory needed is 1K for a 1024× 1024

raster area, so it is not a problem. The error pixels need

to be studied. The paper will analyse the error pixels’ er-

ror magnitude and distribution in detail. Actually, with

N element additional memory, only about 11% of the

lines in an N ×N raster area have larger than 0.5 pixel

error, and the lengths of all these lines are longer than

N/2 pixels. When a line is antialiased, the visual effect of

the error can be corrected. Moreover, when this method

is applied to animations, the lines and polygon edges

are moving, and the error perceived by our eyes can be

ignored.

Here we first briefly introduce the Slope Table method

and analyse its properties. Then we present the applica-

tions of the method in line compaction, scan-conversion,

and antialiasing. Our major contribution includes: a) in-

troducing the Slope Table method to improve the num-

ber of lines with multiple segments; b) applying multiple

segment line scan-conversion to antialiasing; c) using

the Slope Table method to save the pixel patterns of

all possible lines in hardware. Theoretically, our scan-

conversion method on average could reach 14 times

speedup over existing methods. Software implementa-

tion shows more than 6 times speedup over Gupta’s line

antialiasing algorithm18 for randomly generated (3 pixel

wide) lines.

c© The Eurographics Association and Blackwell Publishers Ltd

1999. Published by Blackwell Publishers, 108 Cowley Road,

Oxford OX4 1JF, UK and 350 Main Street, Malden, MA

02148, USA. 69

Page 2: Approximate Line Scan-Conversion and Antialiasing

70 J. X. Chen and X. Wang / Approximate Line Scan-Conversion and Antialiasing

2. The Slope Table Method and its Error Analysis

2.1. The Slope Table Method

To improve the multiple segment property, here we

present an approximate method which can increase the

proportion of the multiple segment lines in a raster area.

Because the method is mainly based on the slopes of

the lines, it’s called the Slope Table Method. Dorst16

studied the slopes of lines and mentioned that lines with

different slopes may result in the same scan-converted

pixel patterns. Dorst stays with the accurate pixel pat-

terns while we introduce an approximation to improve

the number of segments in lines. Here, we assume that

y = dy

dxx + C is a line with end points (x0, y0) and

(xn, yn), where 0 ≤ dy

dx≤ 1, x0 ≤ x ≤ xn, y0 ≤ y ≤ yn,

dx = xn−x0, dy = yn−y0, and C is a constant. All other

cases can be handled by symmetry.

In an N × N raster plane, we can divide all lines

into n groups according to their slopes. Then we select

a line which has the largest number of segments in

each group to represent all lines in that group. Such

a representative line in a group is called the Group

Representative Line (GRL). Given a line, we calculate

its slope, determine which group the slope belongs, and

draw its GRL instead of the original line. Because the

GRL has the largest number of segments in the group,

drawing it should take the least amount of time. Of

cause, an additional memory buffer is needed to save n

GRLs. This buffer is called the Slope Table. The GRL

will be shifted to one of the corresponding end point of

the original line to start scan-conversion.

We save the horizontal pixel length Q and the vertical

pixel length P of the first segment of each GRL in the

Slope Table (Figure 1). Note that the number of line

segments in the approximate line may be non-integer.

The slope group i and n−i−1 are symmetrical (Qn−i−1 =

Qi and Pn−i−1 = Qi−Pi). So only half (n/2) of the GRLs

are needed, the Slope Table will have only n elements.

If we select n = N, the Slope Table takes 1K element

memory in a 1024× 1024 raster area.

Because there are more than one line in each group

and the slopes of the lines in a group may be different,

there may be error pixels when these lines are replaced

by a GRL. The error of a line is expressed by the pixel

distance between the end points of the line and its GRL

(pixel error: e). One end point of the line is shifted to

overlap with the corresponding GRL. We use the pixel

deviation between the other end points of the two lines

to express the error. The larger the group number n is,

the smaller the error. Actually, n slope groups just divide

the boundary line x = N − 1 of the raster area into n

segments. The line x = N − 1 consists of N pixels. We

can select n = N, and cut the line x = N − 1 into N

segments just in the middle of two adjacent pixels, as

Q 0

Q i

Q P

Q 0 -P 0

Q i -P i

Q N 2

- 1 -

Framebuffer K=1

K=.5

K=0

Slope Table

(0,0) Q 0

Q i

P 0

P i

P

(Q i ,P i )

-

P i is the length in y direction of the first segment

dy

dx

Q i is the number of pixels in the first segment

(1K byte ROM)

Q N 2 - 1 - N

2 - 1 -

N 2 -1 -

N 2

-1 -

Figure 1: The Slope Table Method and its memory storage

# of seg. # of lines % # of Pixels %

m ≤ 1 1023 0.19 52343 0.01

1 < m ≤ 2 6385 1.22 1744167 0.49

2 < m ≤ 3 9309 1.77 2939521 0.82

3 < m ≤ 4 12031 2.29 4681147 1.31

m>4 496051 94.52 349021221 97.37

Total 524799 100.0 358438399 100.0

Table 1: Statistics on lines with different number of seg-

ments (m) (error pixel < 1)

shown in Figure 1. This ensures that the N longest lines

(x = N − 1, y = 0 to N − 1) in an N × N area have

at most 0.5 pixel error and all other lines have at most

dx/(N − 1) pixel error.

With the Slope Table method, all lines will be replaced

by their GRLs. Given the group number n = N, Table 1

presents the statistics on the number of lines (and all

pixels in the lines) having different segments (m) in a

1024 × 1024 raster area. Here we have only considered

lines with integer end points. In fact, the Slope Table

method works with floating point end points as well.

From the statistics, we can obtain the following: the

percentage of lines with number of segments larger than

one is over 99.8%. The percentage of lines with number

of segments larger than four is also over 94%.

c© The Eurographics Association and Blackwell Publishers Ltd 1999

Page 3: Approximate Line Scan-Conversion and Antialiasing

J. X. Chen and X. Wang / Approximate Line Scan-Conversion and Antialiasing 71

0 1 1 0

Q =5, P =2, the length of the pixel pattern=4

Figure 2: Pixel pattern of the first segment

2.2. The Pixel Storage Property

The Slope Table method has not only improved the

multiple segment property, but also brought in a new

property: the pixel arrangements of the first segments

(of all GRLs) can be saved for scan-converting any lines

in an N ×N raster area. This is hard to imagine before.

As we know, there exist N(N + 1)/2 − 1 possible lines

in an N × N raster area. If N = 1024, the number of

the lines is 524799, and the number of pixels in all these

lines reaches 358438399. If so many pixel shapes (bits)

are saved in uncompressed form, at least 44M byte (8

bits/byte) space is needed. It is too costly, if possible.

Butler, Gay, and Bresenham had a trade-off method

which saved lines shorter than 17 bits9.

Saving the pixel patterns of the first segments of all

n/2 Slope Table entries is enough to draw all lines

(Figure 2). The pixel storage memory needed in a 1024×1024 raster area is 25149 bits. If measuring the memory

in bytes (8 bits), only 3361 bytes are needed.

With the GRL’s pixel patterns saved and ready, we

will never need to calculate the pixel positions of a

line during scan-conversion. This is completely different

from the traditional line scan-conversion method. We

will never care about finding the pixel addresses for

line scan-conversion. Instead, we just need to calculate

the line’s slope, and use it to obtain the horizontal pixel

length Q, the vertical pixel length P , and the pixel pattern

of the first segment from the Slope Table. Figure 3 gives

the new structure of the Slope Table which includes the

pixel patterns of the first segments.

2.3. Error Analysis

The Slope Table method may choose error pixels. The

error is a very important factor which will determine

whether this new method is practical. Based on the

definition of the Slope Table method, we can see that

the magnitude of an error mainly depends on the length

of a line and the slope group number n which divides

the boundary line x = N − 1 into n segments. In an

Q 0 P 0

Q i P i

Slope Table Pixel Pattern Buffer

P n/2-1 Q n/2-1

(1K byte ROM) (3.3K byte ROM)

Figure 3: Structure of the Slope Table with Pixel Patterns

Maximum Error e # of lines % Min dx

e=0 34719 6.62 1

0<e ≤ 0.1 130832 24.93 37

0.1<e ≤ 0.2 113162 21.56 109

0.2<e ≤ 0.3 85524 16.30 215

0.3<e ≤ 0.4 59658 11.37 319

0.4<e ≤ 0.5 41646 7.93 419

0.5<e ≤ 0.6 29086 5.54 513

0.6<e ≤ 0.7 17096 3.26 630

0.7<e ≤ 0.8 8742 1.67 732

0.8<e ≤ 0.9 3674 0.70 832

0.9<e ≤ 1.0 660 0.12 926

<0.5 465541 88.71

Total 524799 100.0

Table 2: Error Statistics on lines with n = N (error pixel

< 1)

N × N raster area, the maximum (pixel) error of a line

is at most (in distance in y axis direction):

e = dxN

n(N − 1)(1)

The longer the line (dx) is, the bigger the maximum

error could be. The maximum error possibly appears

when dx = N − 1, and its value is N/n. The larger the

group number n is, the smaller the maximum error will

be, but more memory will be needed. When n = N, the

maximum error of a line is dx/(N − 1) which is less

than 1. When n = 2N, the maximum error of a line is

dx/2(N−1) which is less than 0.5. Table 2 lists the pixel

error statistics and their distributions among the lines in

a 1024× 1024 raster area when n = N.

Table 2 shows that the percentage of lines with pixel

c© The Eurographics Association and Blackwell Publishers Ltd 1999

Page 4: Approximate Line Scan-Conversion and Antialiasing

72 J. X. Chen and X. Wang / Approximate Line Scan-Conversion and Antialiasing

errors less than half of the maximum error is about

89%. The column “Min dx” gives the horizontal length

of the shortest line in different error groups. It tells us

that only the longer lines could have larger pixel errors.

The effect of the error on our eyes is not only related

to the size of the error (which is measured by a portion

of a pixel), but also the resolution (i.e., number of pixels

per inch) of the raster plane. If there are two same size

raster planes with different resolutions, when the same

pixel error standard is selected for both planes (suppose

1 pixel error is selected, i.e., n = N), the higher resolu-

tion raster plane will produce better visual impression.

Therefore, how to select the error standard or the slope

group depends on the resolution.

3. Line Compaction and Theoretical Speedup for Line

Scan-Conversion

Line compaction was discussed by Earnshaw17,

Pitteway25, and Bresenham3. Based on both run-lengths

and repeated patterns (multiple segments of a line), a

line can be treated in a compressed form for storage

or transmission. Because the repeated patterns of the

lines in an N×N raster plane are limited, the compress-

ible efficiency from the repeated patterns is also limited.

However, if the Slope Table method is used in line com-

paction, as the number of multiple segment lines are

increased significantly, the compressible efficiency from

the repeated patterns will also be improved significantly.

The disadvantage is that the compressed lines may not

be the perfect lines. Fortunately, the error, as discussed,

is controllable for different applications.

Here we focus on the compressible efficiency from the

repeated patterns instead of that from the run-lengths.

This is easier for us to explain in our work. The ef-

ficiency from the run-lengths still exists in the Slope

Table method. (In fact, the run-lengths and the repeated

patterns can be integrated together. Here we omit the

details to shorten the paper.) Under the assumption that

all possible lines in a raster area have the same possibility

to appear, Table 3 gives the statistics on the number of

the pixels in the first segment of lines with the repeated

patterns. We compare the number of pixels needed to

be represented in the uncompressed format, the accurate

multiple segment method, and the Slope Table method.

From the row Efficiency, the accurate multiple segment

method mentioned in Earnshaw’s paper17 can at most

compress the space of the total lines in a 1024 × 1024

raster area 1.37 times, but the Slope Table method can

compress the space 13.83 times. It’s about 10 times more

efficient than Earnshaw’s method for n = 1024.

Furthermore, theoretically, if copying segments (pix-

els) takes very little time for scan-conversion, we need

only consider the time for handling the pixels in the first

# of Segments Uncompressed Accurate Slope Table

m=1 217,302,562 217,302,562 51,320

m=2 54,307,428 27,153,714 1,281,724

m=3 24,249,318 8,083,106 1,201,402

m=4 13,496,136 3,374,034 1,343,770

m>4 48,558,156 5,293,130 22,001,128

Total # of pixels 357,913,600 261,206,546 25,879,344

Efficiency 1.000 1.370 13.830

Table 3: Compressible Efficiency from Repeated Patterns

in a 1024× 1024 Raster Area

segment. As shown in Table 3, our new methods could

be 13.83 times faster than scan-converting all pixels by

pixel address accrual. This is impossible to achieve at

present because currently the memory access time is

close to finding the memory addresses by pixel accrual.

In other words, no matter how much we can speed up

finding the pixel addresses, the scan-conversion will take

pretty much the same amount of time. However, this

speedup is reasonable for certain applications, such as

scan-converting an antialiased line, which takes a signif-

icant amount of time to calculate the intensities of the

pixels in the first segment but very little time for copying.

Also, if future memory access time is much reduced, our

method will be able to speed up scan-converting single

pixel lines (without antialiasing) significantly.

The statistics are under the assumption that all pos-

sible lines in a raster area have the same possibility to

appear. This may not be a valid assumption because

in practical applications shorter lines appear more fre-

quently. The statistics analysis shows that in general the

longer the line is, the larger the speedup13. The average

speedup can be expressed as follows: m = 132dx + 1. So

on average every 32 pixels in the length of a line (dx) will

contribute to one more time speedup. Even if the max-

imum length of lines is very small, m is always greater

than 1, so it always shows speedup. For example, if we

only have lines which are shorter than 10 pixels, we still

have about 1.3 times speedup. In any event, since the

first segments of the lines are saved and scan-conversion

can be implemented in hardware, our method will not

be slower if there is not much speedup. Of course, some

lines have only one segment, and there is no speedup at

all (m = 1).

The number of segments (and thus the possible

speedup) is related to not only the length of a line,

but also the slope of a line13. Although certain lines

with different slopes and lengths have no speedup, there

are many lines do have many segments, and thus can be

exploited.

c© The Eurographics Association and Blackwell Publishers Ltd 1999

Page 5: Approximate Line Scan-Conversion and Antialiasing

J. X. Chen and X. Wang / Approximate Line Scan-Conversion and Antialiasing 73

Algorithms # of CMPs # of ADDs # of INCs Total

Bresenham’s 2dx dx 1.5dx 4.5dx

Algorithm 1 dx+2dx/m 2dx+dx/m 3.5dx/m 3dx+6.5dx/m

Table 4: Complexity expressions for the line algorithms

Algorithms CMPs ADDs INCs Total (cycles) Speedup

Bresenham’s 715827200 357913600 536870400 1610611200 1.000

Algorithm1 409672288 742231343 90577704 1242481335 1.296

Table 5: Computer simulated number of CPU cycles for

a 1024× 1024 area

4. Software Line Scan-conversion with the Slope Table

Method

Here we apply the Slope Table into the multiple segment

line scan-conversion. Given a line with two end points

(and therefore the slope of the line), we first get the hor-

izontal pixel length Q and the vertical pixel length P of

the first segment of the GRL from the Slope Table, and

then use the Q and P to calculate and scan-convert the

first segment. While scan-converting the first segment,

when one pixel is drawn, it is immediately drawn to ev-

ery identical positions in the successive segments. When

the first segment is drawn, all other successive segments

are also scan-converted. Here we use Bresenham’s line

algorithm to calculate the first segment. As discussed in

Appendix A Algorithm 1 , the complexity expressions of

the two algorithms are listed in Table 4.

From the total number of CPU cycles in Table 4,

we can see that when Algorithm 1 is at least as fast as

Bresenham’s algorithm, we have:

(4.5dx)− (3dx+ 6.5dx/m) ≥ 0 (2)

m ≥ 13

3≈ 4.33 (3)

This means that the speedup only happens when m >

4. The maximum software speedup is at most 1.5 times.

Under the assumption of equal possibility for all lines,

Table 1 tells us that at least 94% of the lines meet such

a condition.

To calculate the statistics on speedup of the new

method, we use a software simulator to count the total

number of instructions (CPU cycles) of Bresenham’s line

algorithm and that of our new algorithm over all lines

in a 1024 × 1024 raster area. Table 5 is the summary

which shows that the new method could have about

1.296 times speedup when n = 1024.

Algorithms # of CMPs # of ADDs # of INCs # of CALs Total

Gupta’s 2dx 2dx 1.5dx 3dx(*10) 35.5dx

Alg. 2 dx+2dx/m 2dx+2dx/m 3.5dx/m 3dx(*10)/m 3dx+37.5dx/m

Table 6: Complexity expressions for antialiasing line al-

gorithms (CMP, ADD, INC: 1 CPI; CAL: 10 CPI)

Alg.s CMPs ADDs INCs CALs Total Speedup

Gupta’s 715827200 715827200 536870400 1075315197 12721676770 1.000

Alg2 410197087 769160285 90577704 77638032 2046315396 6.217

Table 7: Computer simulated number of CPU cycles for

a 1024× 1024 area

5. Software Antialiasing in Line Scan- conversion with

the Slope Table Method

Line antialiasing methods are important techniques to

handle the “jagged” lines and polygon edges14, 21, 25. Fu-

ture graphics will require high quality images (lines and

polygon edges) with antialiasing. This section will dis-

cuss the application of the Slope Table method in an-

tialiasing. Here we only introduce the improvement on

the existing antialiasing methods after using the Slope

Table method.

In Gupta’s antialiasing method, the distance from

each pixel (to be intensified) to the exact mathematically

specified line is used to determine the intensity of the

pixel. When the scan-converted discrete line has multiple

segments, the identical pixel positions in different seg-

ments always have the same distance to the line. So these

pixels must have the same intensity in antialiasing. As

we know, the calculation of the pixel intensity always

takes the most amount of time when scan-converting

a line with antialiasing. Using the multiple point copy

method in Algorithm 1 , only the pixel intensities of the

first segment of a line need to be calculated. For the suc-

cessive segments, we can directly use the results of the

first segment. This way the whole line scan-conversion

with antialiasing takes less amount of time. The thicker

the line, the less time will be needed. If texture mapping

is applied, this method can be integrated to copy the

textured pixels. At least the texels (texture pixels) can

be intensified by the distances which are repeating in

multiple segments.

As discussed in Appendix B Algorithm 2 , the complex-

ity expressions of the Gupta’s and our new antialiasing

line algorithm are listed in Table 6. (CPI stands for CPU

clock cycle per instruction.)

If Algorithm 2 is at least as fast as Gupta’s algorithm,

c© The Eurographics Association and Blackwell Publishers Ltd 1999

Page 6: Approximate Line Scan-Conversion and Antialiasing

74 J. X. Chen and X. Wang / Approximate Line Scan-Conversion and Antialiasing

Worst cases Random generated lines

Figure 4: Screen snapshots of approximate scan-conversion by Slope Table method

we have:

(35.5dx)− (3dx+ 37.5dx/m) ≥ 0 (4)

m ≥ 37.5

32.5≈ 1.154 (5)

We see that Algorithm 2 will be faster than Gupta’s

algorithm when m > 1. Again, the results in Table 1

shows that 99% lines have more than one segment.

So the Slope Table method can speed up Gupta’s an-

tialiasing method significantly. Table 7 gives the statistics

which show that the new method can speed up Gupta’s

method about 6 times.

On the pixel error of the Slope Table method, the error

can be mostly corrected because the pixel intensities in

the first segment can be calculated accurately. If the

width of the line is even number of pixels, the problem

can be better corrected because we will be able to choose

the paired pixels above and below the line.

6. Conclusion

We have presented a new approximate method, the

Slope Table method, to scan-convert lines. Our method

and idea can be integrated with exiting scan-conversion

hardware and software methods, including run-lengths

and multi-step scan-conversions. We are currently im-

plementing the method in hardware.

On performance and speedup, our method will not

be able to speed up single line scan-conversion because

writing to memory takes a significant amount of time.

However, we can achieve speedup on scan-converting

antialiased lines. This method is suitable for antialiasing

because only the intensities of the pixels of the first seg-

ment need to be calculated and can be directly copied to

the successive segments. If texture mapping is involved,

the method can be modified to shade the intensities of

texels. The actual speedup depends on the width of the

antialiased line, and the assumptions about line lengths

and slopes.

On pixel error, the method is an approximate method

that allows at most one pixel’s error. The shorter the line,

the smaller the error. In most cases the scan-converted

lines are identical to the lines generated by Bresenham’s

algorithm. The errors can be seen when printed on paper

by high resolution printer, as shown in Figure 4. Here

we have two snapshots which demonstrate the worst-

case situations, and randomly generated lines. The black

pixels represent the approximate pixels chosen, and the

white pixels represent the original line scan-converted

by Bresenham’s algorithm. The worst cases are at the

right-hand side of the screen approaching the ends of a

few very long lines. The left-hand side of the lines are

much more accurate.

On antialiased line, because the intensities of the pixels

are mostly accurate, the results are much better. Our eyes

c© The Eurographics Association and Blackwell Publishers Ltd 1999

Page 7: Approximate Line Scan-Conversion and Antialiasing

J. X. Chen and X. Wang / Approximate Line Scan-Conversion and Antialiasing 75

Antialising with Gupta’s algorithm Antialiasing with the Slope Table method (6 times faster)

Figure 5: Screen snapshots of antialiased lines by Gupta’s and Slope Table method

cannot tell the difference between the lines generated by

our method or Gupta’s method. Figure 5 is a comparison

of the results from Gupta’s algorithm and our algorithm,

which is 6 times faster.

On scan-converting connected lines (wireframe poly-

gons), there is no error at the connecting points of the

lines when we choose n = 2N. When n = N for a

1024 × 1024 area, all lines shorter than 512 pixels are

connected correctly. The pixel error at the connecting

points of longer lines are less than a pixel and hard to

see. For antialiased lines, the error can be corrected.

Acknowledgement

We are very grateful to the reviewers for their detailed

comments and help. During the progress of this work,

Dr. Bresenham’s and Dr. Pitteway’s comments have en-

couraged the research and shaped the course of our

effort.

References

1. E. Angel and D. Morrison, “Short Note: Speeding

Up Bresenham’s Algorithm,”, IEEE CG&A, 11, pp.

16-17 (1991).

2. J. E. Bresenham, “Algorithm for Computer Control

of Digital Plotter”, IBM Syst. J., 4, pp. 25-30 (1965).

3. J. E. Bresenham, “Incremental Line Compaction”,

Comput. J. , 25(1), pp. 116-120 (1982).

4. J. E. Bresenham, D. G. Grice, and S. C. Pi, “Run

Length Slice Algorithms for Incremental Lines”,

IBM Technical Disclosure Bulletin , 22-8B(1), pp.

3744-3747 (1980).

5. J. E. Bresenham, “Run Length Slice Algorithms

for Incremental Lines”, Fundamental Algorithms for

Computer Graphics , R. A. Earnshaw, Ed., NATO

ASI Series, F17, Springer-Verlag, New York, pp.

59-104 (1985).

6. J. E. Bresenham, “Ambiguities in Incremental Line

Rastering”, IEEE CG&A, 7(5), pp. 31-43 (May

1987).

7. J. E. Bresenham, “Tutorial: Pixel-Processing Fun-

damentals”, IEEE CG&A, 16(1), pp. 74-82 (1996).

8. R. Brons, “Linguistic Methods for the Description

of Straight Line on a Grid”, Comput. Gr. Image

Process., 9, pp. 183-195 (1979).

9. N. D. Butler, A. C. Gay, and J. E. Bresenham,

“Line Generation in a Display System”, United

States Patent: 4996653 , (February 1991).

10. C. M. A. Castle and M. L. V. Pitteway, “An

Application of Euclid’s Algorithm to Drawing

Straight Lines”, Fundamental Algorithms for Com-

c© The Eurographics Association and Blackwell Publishers Ltd 1999

Page 8: Approximate Line Scan-Conversion and Antialiasing

76 J. X. Chen and X. Wang / Approximate Line Scan-Conversion and Antialiasing

puter Graphics , R. A. Earnshaw, Ed., NATO ASI

F17, Springer-Verlag, New York, pp. 134-139

(1985).

11. C. M. A. Castle and M. L. V. Pitteway, “An Efficient

Structural Technique for Encoding best-fit Straight

Lines”, Comput. J., 30, pp. 168-175 (1987).

12. J. X. Chen, “Multiple Segment Line Scan-

Conversion”, Computer Graphics Forum , 16(5), pp.

257-268 (1997).

13. J. X. Chen, and X. Wang, “Approximate Line

Scan-Conversion and its Hardware Design”, Tech-

nical Report , TR98-3, George Mason University,

(http://www.cs.gmu.edu:8080/).

14. F. C. Crow, “The Aliasing Problem in Computer-

Generated Shaded Images”, Communications of the

ACM , 20(11), pp. 799-805 (1977).

15. L. Dorst, and A. W. M. Smeulders, “Discrete Rep-

resentation of Straight Lines”, IEEE Trans. Pattern

Anal. Machine Intell., PAMI-6(4), pp. 450-463 (July

1984).

16. L. Dorst, and R. P. W. Duin, “Spirograph Theory: A

Framework for Calculations on Digitized Straight

Lines”, IEEE Trans. Pattern Anal. Machine Intell.,

PAMI-6(5), pp. 632-639 (September 1984).

17. R. A. Earnshaw, “Line Tracking for Incremental

Plotters”, Comput. J., 23(1), pp. 47-52 (1980).

18. J. D. Foley, A. van Dam, S. K. Feiner, and J. F.

Hughes, Computer Graphics: Principles and Prac-

tice, Second Edition in C, Addison Wesley (1996).

19. P. L. Gardner, “Modifications of Bresenham’s Al-

gorithm for Display”, IBM Tech. Disclosure Bull .

18, pp. 1595-1596 (1975).

20. G. W. Gill, “N-Step Incremental Straight-Line Al-

gorithms”, IEEE CG&A, 5, pp. 66-72 (1994).

21. S.R. Gupta, and R. Sproull, “Filtering Edges

for Gray-Scale Displays”, Computer Graphics

(Siggraph-ACM),, 15(3), pp. 1-5 (1981).

22. Intel Corporation, Pentium Processor Family User’s

Manual, Volumn 3: Architecture and Programming

Manual , (1994).

23. D. Knuth, The Art of Computer Programming: Vol-

ume 2: Seminumerical Algorithms , 2nd Ed. Addison-

Wesley, New York, (section 4.5.2, Theorem D), pp.

324-325 (1973).

24. M. D. McIlory, “A Note on Discrete Representation

of Lines”, AT&T Tech. J., 64(2), pp. 481-490 (1985).

25. M. L. V. Pitteway and A. Green, “Bresenham’s Al-

gorithm with Run Line Code Shortcut”, Comput.

J., 25, pp. 114-115 (1982).

26. M. L. V. Pitteway and D. J. Watkinson, “Bresen-

ham’s Algorithm with Grey Scale”, Communications

of the ACM , 23(11), pp. 625-626 (1980).

27. J. G. Rokne, B. Wyvill, et al., “Fast Line Scan-

Conversion”, ACM Trans. on Graphics , 9(4), pp.

376-388 (October 1990).

28. G. B. Regiori, “Digital Computer Transformations

for Irregular Line Drawings”, Tech. Rep., Dept. of

EE and ES. New York Univ., pp. 403-422 (April

1972).

29. R. F. Sproull, “Using Program Transformations to

Derive Line-Drawing Algorithms”, ACM trans. Gr.,

1(10), pp. 259-273 (1982).

30. Tran-Thong, “A Symmetric Linear Algorithm for

Line Segment Generations”, Computer & Graphics ,

6(1), pp. 15-17 (January 1982).

31. X. Wu and J. G. Rokne, “Double-Step Incremental

Generation of Lines and Circles”, Comput. Vision,

Gr. Image Process . 37(3), pp. 331-344 (1987).

Appendix A: Algorithm 1 - multiple segment line

scan-conversion with the Slope Table

1: Alg1_multisegment(int x0,int xn,int y0,int yn)

2: { /* Scan-convert a line: */

3: /* (x0,y0)--(xn,yn) for 0<=slope<=1 */

4: int dx,dy,incrE,incrNE,d,x,y,x1,Q,P,xm,ym;

5:

6: dx=xn-x0; dy=yn-y0;

7: /* get Q & P from the Slope Table */

8: SlopeTable(dx,dy,&Q,&P);

9: d=2*P-Q; incrE=2*P; incrNE=2*(P-Q);

10: x=x0; y=y0;

11: x1=x+Q;

12: /* scan-convert the 1st segment, */

13: /* copy to successive segments */

14: while (1) { /* multi-point copy */

15: xm=x; ym=y;

16: do {

17: writepixel(xm,ym);

18: xm+=Q; ym+=P;

19: } while (xm<=xn);

20: x++;

21: if (x==x1) break; /* exit */

22: if (d<=0)

23: d+=incrE;

24: else {

25: d+=incrNE;

26: y++;

27: }

28: }

29: }

This algorithm is very similar to Bresenham’s line

algorithm except the additional do-loop (from line 15

to 19) for copying the point to the successive segments.

Now let’s analyse the complexity of the new algorithms,

c© The Eurographics Association and Blackwell Publishers Ltd 1999

Page 9: Approximate Line Scan-Conversion and Antialiasing

J. X. Chen and X. Wang / Approximate Line Scan-Conversion and Antialiasing 77

Algorithms # of CMPs # of ADDs # of INCs Total

Bresenham’s 2dx dx 1.5dx 4.5dx

Algorithm 1 dx+2dx/m 2dx+dx/m 3.5dx/m 3dx+6.5dx/m

Table 8: Complexity expressions for the line algorithms

and compare it to that of Bresenham’s line algorithm.

Here the comparison is theoretical algorithm analysis

and software simulation. The results here are important

for our antialiasing method and hardware design.

The comparisons among the initializing operations

(from line 6 to 11) are ignored because they are almost

the same and the instructions are only executed once.

To simplify our specifications, some notations are used

in the following analysis. They are:

CMP: Logic Comparison and Loop condition Test

ADD: Addition and Subtract

INC: Increment, Decrement, and Assignment.

Bresenham’s algorithm has one main loop which runs

dx times, where dx is the number of pixels of the line.

In one pass of the loop, it has 2 CMPs, 1 ADD, and

1.5 INCs. (The move in y direction depends on the logic

testing result, so 0.5 INC is added to the total number

of instructions. The same consideration will be given to

our new algorithm.) It includes all together 2dx CMPs,

dx ADDs and 1.5dx INCs.

Algorithm 1 has one main loop, but it runs only Q

times (actually the lines from 22 to 27 only run Q − 1

times), where Q is the number of pixels in the first

segment. Suppose m is the total number of segments of

a line, Q = dx/m. In the main loop, it has 2 CMPs,

1 ADD, 3.5 INCs and one do-loop. The do-loop runs

m times and each pass includes 1 CMP and 2 ADDs.

Totally, the complexity is dx+2dx/m CMPs, 2dx+dx/m

ADDs, and 3.5dx/m INCs.

Different machines will take different amount of time

to run and finish these algorithms, because the hard-

ware instructions take different number of CPU cycles.

Using the CPU clock Cycle Per Instruction (CPI) from

a book22 to our algorithms (i.e., CMP, ADD and INC

have each 1 CPU Cycle), we summarize the total com-

plexity in the column Total as shown in Table 8.

Appendix B: Algorithm 2 - multiple segment antialiasing

line scan-conversion with the Slope Table

Foley, et al’s book18 gave a version of Gupta’s algorithm

(on page 141) for antialiasing line scan-conversion. Here

we use the Slope Table method to approximate the

lines in a raster plane, and add the multiple point copy

method into Gupta’s algorithm. We get a new algorithm

Algorithms # of CMPs # of ADDs # of INCs # of CALs Total

Gupta’s 2dx 2dx 1.5dx 3dx(*10) 35.5dx

Alg. 2 dx+2dx/m 2dx+2dx/m 3.5dx/m 3dx(*10)/m 3dx+37.5dx/m

Table 9: Complexity expressions for antialiasing line al-

gorithms (CMP, ADD, INC: 1 CPI; CAL: 10 CPI)

(algorithm 2 ). Compared to Gupta’s algorithm, the main

loop of this new algorithm only runs Q times, and the

computation for all pixel intensities is thus reduced by

m − 1 times (m = dx/Q). The same method can be

applied into any other existing antialiasing algorithms,

and the improved algorithms should basically obtain

similar results.

Now let’s analyse the complexity of both Gupta’s

algorithm and algorithm 2 using the same notation in-

troduced in analysing algorithm 1 . First, we add a new

instruction CAL for calculating the pixel intensity in

addition to CMP, ADD and INC. One CAL actually

includes many operations such as multiply, addition, ap-

proximation, absolution and table look-up. We assume

that CAL is at least equal to 10 INCs.

Gupta’s algorithm has one main loop which runs dx

times. In one pass of the loop, it has 2 CMPs, 2 ADDs,

1.5 INCs and 3 CALs. It has totally 2dx CMPs, 2dx

ADDs, 1.5dx INCs and 3dx CALs.

Algorithm 2 also includes one main loop, but it runs

only Q times (Q = dx/m). The main loop has 2 CMPs, 2

ADDs, 3.5 INCs, 3 CALs and one do-loop. The do-loop

runs m times and each pass has 1 CMP and 2 ADDs.

It includes all together dx+ 2dx/m CMPs, 2dx+ 2dx/m

ADDs, 3.5dx/m INCs and 3dx/m CALs.

The complexity expressions of the two antialiasing

line algorithms are listed in Table 9. Here we assume

that CMP, ADD and INC have one CPU Cycle again,

and CAL equals 10 CPU Cycle. The total complexity

expressions are shown in the column Total.

Alg2_multisegment(int x0, int xn, int y0, int yn)

{ /* Scan-convert a line with antialiasing. */

int dx,dy,incrE,incrNE,d,x,y,x1;

int Q,P,xm,ym,two_v_dx;

float invDenom,two_dx_invDenom;

float intensity1,intensity2,intensity3;

dx=xn-x0; dy=yn-y0;

/* get Q & P from the Slope Table */

SlopeTable(dx,dy,&Q,&P);

d=2*P-Q; incrE=2*P; incrNE=2*(P-Q);

two_v_dx=0;

invDenom=1/(2*sqrt(Q*Q+P*P));

two_dx_invDenom=2*Q*invDenom;

x=x0; y=y0;

x1=x+Q;

c© The Eurographics Association and Blackwell Publishers Ltd 1999

Page 10: Approximate Line Scan-Conversion and Antialiasing

78 J. X. Chen and X. Wang / Approximate Line Scan-Conversion and Antialiasing

/* scan-convert the 1st segment, */

/* copy to successive segments */

while (1) {

intensity1=Filter(round(abs

(two_v_dx*invDenom)));

intensity2=Filter(round(abs

(two_dx_invDenom-two_v_dx*invDenom)));

intensity3=Filter(round(abs

(two_dx_invDenom+two_v_dx*invDenom)));

/* multi-point copy */

xm=x; ym=y;

do {

writepixel(xm,ym,intensity1);

writepixel(xm,ym+1,intensity2);

writepixel(xm,ym-1,intensity3);

xm+=Q; ym+=P;

} while (xm<=xn);

x++;

if (x==x1) break; /* exit */

if (d<=0) {

two_v_dx=d+Q;

d+=incrE;

}

else {

two_v_dx=d-Q;

d+=incrNE;

y++;

}

}

}

c© The Eurographics Association and Blackwell Publishers Ltd 1999