BACKGROUND OF THE INVENTION
This invention relates to a line-draw method and apparatus for generating, storing and displaying lines in a display system.
A portion of the disclosure of this patent document contains material which is subject to copyright protection. The copyright owner has no objection to the facsimile reproduction by anyone of the patent document or the patent disclosure, as it appears in the Patent and Trademark Office patent file or records, but otherwise reserves all copyright rights whatsoever.
In display systems that draw lines, each pixel (point) on the line is located and addressed by an X-axis coordinate and a Y-axis coordinate defined relative to an XY-axes system where an X-axis and an orthogonal Y-axis form a matrix of addressable pixels. A pixel is drawn by determining the X-axis and Y-axis coordinates for the pixel and a line is drawn by determining the X-axis and Y-axis coordinates for all the pixels on the line that are used to draw the line.
By way of background, a number of line-draw methods are described by Newman and Sproull in PRINCIPLES OF INTERACTIVE COMPUTER GRAPHICS, Second Edition, McGraw-Hill Book Company, 1979. One such well-known method is Bresenham's Algorithm which draws a line a pixel at a time.
The Bresenham method operates such that for each new pixel to be drawn, a new iteration of the algorithm changes one of the X-axis or Y-axis coordinate values relative to the values for the previous pixel by +1 or -1. The other coordinate value of the new pixel may or may not change, depending on the value of an error term, e. The error term represents the distance, measured perpendicular to the axis of greatest movement, between the exact path of the line and the location of the actual pixels used to draw the line.
Bresenham's method may be applied to a line with any orientation. Irrespective of how the line is actually oriented relative to the coordinate system, the Bresenham method operates essentially the same as if the line were rotated into the upper right-hand quadrant of an XY-axes system. For a line which is located in the upper right-hand quadrant of an orthogonal system and which is also positioned radially from the origin and running between the 45' line and the X-axis, then the X-axis increment of the line, .DELTA.x, changes faster than the Y-axis increment, .DELTA.y. In such an example, where the X-axis is the axis of greatest change (that is, 0.ltoreq..DELTA.y.ltoreq..DELTA.x), the error term e is measured parallel to the y axis.
Assuming an orientation where the X-axis is the axis of greatest change, each iteration of the algorithm adds the slope of the line, .DELTA.y/.DELTA.x, to the error term e. Before this addition, the sign of e is used to determine whether to increment the y coordinate of the current pixel. A positive e value indicates that the exact path of the line lies above the current pixel so that the y coordinate is incremented, and 1 is subtracted from e. If e is negative, the y coordinate value is left unchanged.
The Bresenham algorithm is expressed by the following PASCAL program of TABLE 1, which requires neither divisions nor multiplications and in which all variables are integers:
Bresenham's algorithm avoids generating duplicate pixels and also avoids multiplications and divisions so that it is well suited to implementation in either hardware or software.
When implemented in software, the Bresenham algorithm typically employs an inner loop such that X-axis and Y-axis coordinates for a single pixel are generated for every iteration of the inner loop.
An example of a typical inner loop of well-optimized Bresenham code for a Motorola 68020 processor drawing a line that is more horizontal than vertical is given in TABLE 2. Only the inner loop is shown, since the inner loop dominates performance in drawing long lines. In the display system, it is assumed that the display buffer has eight planes and is organized such that the processor can access a single pixel with a byte operation.
The Bresenham method and other line-draw methods are inefficient in that they require one test of the error term for each pixel to be generated, that is, they generate one pixel at a time. For a large number of pixels in a line, the length of time required to draw the line approaches an amount that is directly related to the number of pixels in the line. In many embodiments where line drawing speed is an important parameter of the display system, the Bresenham algorithm is too slow.
Accordingly, and in accordance with the above background, there is a need for improved line-draw methods and apparatus which are capable of improved line-draw speeds.
SUMMARY OF THE INVENTION
The present invention is a line-draw method and apparatus that draws lines at fast speeds. Lines are drawn a pixel at a time and a number of algorithms are employed to determine the pixels to be drawn. Lines to be drawn are categorized by their directions (orientations relative to axes) and by their lengths.
The direction (orientation) of a line is described relative to an XY-axes system which has an X-axis and an orthogonal Y-axis and relative to a DE-axes system which has a D-axis and an orthogonal E-axis. The DE-axes system is rotated 45 degrees about a common origin relative to the XY-axes system and hence is termed the diagonal system. Different line-draw methods are provided for axial lines and for lines in different length categories. Each method is particularly suited for the axial alignment or length of the line. For axial lines, any well-known axial line-draw method is employed. Typically, length categories are short, medium and long.
For short lines, a table look-up method is employed to determine the pixels to be drawn. The look-up table is implemented directly as part of the executable code or is implemented as a separate data store. In either implementation, the coordinate values for pixels are obtained quickly. For longer length lines and as the length of the line to be drawn increases, the number of pixels to be stored in the look-up table increases dramatically, that is, the number of lines of code (for the executable code embodiment) or the memory size (for the data store embodiment) increases dramatically. At some line length (medium length and above), the cost may render the table look-up method unacceptable for practical systems.
For lines of varying length, such as medium and long length lines, a multi-pixel segment method (burst method) is employed. Burst methods are line-draw methods which draw lines using a plurality of multi-pixel segments to draw the lines where each segment is characterized as having a number (U) of unconditional pixels which are always drawn and an actual number (A) of conditional pixels which are drawn. The actual number (A) is any number up to a maximum number (C) of conditional pixels which can be drawn. In order to determine the actual number (A) of pixels drawn, an error term is tested to determine if a conditional-pixel condition is satisfied. The conditional-pixel condition is tested by comparing an error term with a threshold once for each conditional pixel. Up to A+1 tests, but not more than C tests of the error term are made per segment. If the conditional-pixel condition is satisfied (error threshold is exceeded), the conditional pixel is drawn and if not satisfied, the conditional pixel is not drawn.
The pixels for each segment of a line are determined sequentially in three parts, namely beginning, middle and end parts. Each beginning and end part is formed of one segment and the middle part is formed of one or more segments where each segment includes a number of pixels. The segment length, SL, for any particular segment is defined as the number of unconditional pixels which are always drawn and the number of conditional pixels which are actually drawn when conditional-pixel conditions are satisfied.
A line, L, is represented as a series of segments, S, including the segments S1, S2, S3, . . . , S(n-1), Sn where S1 is the beginning segment, S2, S3, . . . , S(n-1) are the middle segments and Sn is the end segment.
The pixels, whether conditional or unconditional, used to form each segment are selected as a sequence of horizontal, vertical or diagonal pixels relative to the XY-axes or relative to the DE-axes coordinate systems.
If the line to be drawn is more horizontal than diagonal, closer to the X-axis than to the D-axis or E-axis, segments of horizontal pixels along the X-axis are used. If the line is more vertical than diagonal, closer to the Y-axis than to the D-axis or to the E-axis, segments of vertical pixels along the Y-axis are used. If the line is more diagonal than horizontal or vertical, closer to the D-axis or E-axis than to either the X-axis or Y-axis, segments of diagonal pixels along the D-axis or E-axis are used.
The closest axis (X, Y, D, E) to any given line to be drawn is determined to be the major axis (X or D, or Y or E) and the other orthogonal axis (Y or E, or X or D) is the minor axis. Each line has a projection onto the axes, that is, a major axis projection, da, and a minor axis projection, db. These projections da and db together with the axes system, XY-axes or DE-axes, uniquely determine the direction and length of a line.
The average segment length (ASL) of a line is da/db. The number of segments required to draw a line is equal to db+1, including the beginning, middle and end segments. The total number of middle segments used to draw a line is equal to db-1. In order to draw a line, the length of each segment forming the line must be determined, that is, the length of the beginning and end segments and the lengths of all the middle segments are determined.
In order to determine which conditional pixels are to be drawn, a determination of the lengths of any segment must be made. For each segment, conditional-pixel conditions (error terms compared against a threshold) are used to choose between drawing the segment with a number of pixels equal to the "floor" length in pixels or with a number of pixels equal to the "ceiling" length in pixels. The "floor" length is the greatest integer not greater than some value and the "ceiling" is the smallest integer not less than that value where, for beginning and end segments, the value is one-half the average segment length (ASL/2) and for middle segments the value is the average segment length (ASL). The conditional-pixel condition is evaluated once for each conditional pixel drawn.
In the multi-pixel segment methods, the error terms are manipulated only once per conditional pixel and not for the unconditional pixels, and hence multiple pixels for a segment are determined and drawn more rapidly than when error terms are manipulated once for every pixel. The larger the number of unconditional pixels per segment, the less time spent determining the conditional-pixel condition and hence the faster the line can be drawn.
When the multi-pixel segment method (the burst method) is embodied in computer code for a line draw program, the determination of the unconditional and the conditional pixels to be drawn for each segment is implemented within a segment loop (outer loop). To draw a line, the segment loop is executed once for each segment of the line.
In order that a line-draw program be able to draw any line of arbitrary direction and length, the computer program includes a complete set of segment loops. Since any particular segment loop may not be able to draw all lines, different segment loops within the complete set draw different ones of the lines.
Lines of arbitrary direction and length are characterized as having arbitrary Average Segment Length, ASL (where ASL is equal to da/db). Each segment loop within the complete set of segment loops typically can draw only a range of Average Segment Lengths. However, the complete set of segment loops for a line-draw program is chosen to include a complete set of Average Segment Lengths such that any line of arbitrary direction and length (that is, any arbitrary Average Segment Length) may be drawn.
The range that Average Segment Length (ASL) can have is limited such that for some Maximum Line Length (MLL), [ASL.ltoreq. MLL]. In a single orothogonal axes system (XY-axes system), ASL is limited such that [1.ltoreq.ASL .ltoreq.(MLL)/2]. In a double orothogonal axes system (XY-axes and DE-axes system),. ASL is limited such that [2.ltoreq.ASL .ltoreq.(MLL)/2].
Multi-pixel segment methods are characterized as having either a fixed maximum number of conditional pixels or as having a variable maximum number of conditional pixels. When such fixed or variable maximum conditional number of pixels are embodied in computer code, evaluation of the actual number of conditional pixels, when the maximum number is variable, can be implemented as a conditional-pixel loop (inner loop). When the maximum number of conditional pixels is fixed, no inner loop is required. Accordingly, line-draw methods are characterized as single loop (segment loop only) or double loop (segment loop and conditional-pixel loop).
For single loop line-draw methods (segment loop only), the line is drawn with a single segment loop in which a number U of unconditional pixels and an actual number A of conditional pixels are drawn where the actual number A is up to C conditional pixels where C is the maximum number of conditional pixels which can be drawn (where A is determined as a function of the conditional-pixel conditions).
The segment loop or loops chosen to draw a line are selected from the complete set of segment loops available in the computer program based upon the average segment length (ASL) for the line such that,
where since U and C are integers,
U.ltoreq.floor[ASL]
and where:
floor[ASL]=floor of average segment length (ASL) ceiling[ASL]=ceiling of average segment length (ASL) Average Segment Length (ASL)=da/db
The condition (U).ltoreq.ASL.ltoreq.(U+C) is sufficient to guarantee that every segment of the line with segment length SL also satisfies the condition,
since,
floor[ASL]<SL <ceiling[ASL]
For single loop burst line-draw methods, the number of unconditional pixels (U) is at most one-half the length of the longest line which can be drawn.
For double-loop burst line-draw methods, the line is drawn with a double loop in which the outer loop draws U unconditional pixels and up to C conditional pixels where C is of arbitrary size and where the C conditional pixels are determined one per iteration of the inner loop depending upon the conditional-pixel condition determined by the inner loop. For a double loop method, C is unlimited algorithmically but is limited in actual implementations in some arbitrary manner, for example, by the size of fields in the computer system.
The loop structures of line-draw methods are of interest because such structures relate to the speed with which lines can be drawn. Such speed, of course, affects the performance of the display system and the user satisfaction with the display system when lines are being drawn.
The multi-pixel segments (burst) methods of the present invention are faster than Bresenham's method since, in the present invention, each segment loop execution typically draws a segment with multiple pixels whereas Bresenham's method only draws a single pixel per segment loop execution.
In accord with the above summary, it is an object of the present invention to provide an improved display system which draws lines with a fast speed.
Other objects, features, and advantages of the present invention will become more apparent in the light of the following detailed description thereof, as illustrated in the drawings.
BRIEF DESCRIPTION OF THE DRAWINGS
FIG. 1 depicts a block diagram representation of a display system in accordance with the present invention.
FIG. 2 depicts an XY-axes coordinate system for drawing lines. .
FIG. 3 depicts a block diagram of the line-draw methods executed by the FIG. 1 system.
FIG. 4 depicts a medium-length line drawn from coordinates (1,1) to coordinates (16,7) where the X-axis is the Major Axis.
FIG. 5 depicts a long-length line drawn from coordinates (4,26) to coordinates (18,5) where the E-axis is the Major Axis.
FIG. 6 depicts a long-length line drawn from coordinates (5,27) to coordinates (3,2) where the Y-axis is the Major Axis.
FIG. 7 depicts a long-length line drawn from coordinates ( 1,1 ) to coordinates (31,13) where the X-axis is the Major Axis.
FIG. 8 depicts a short-length line drawn from coordinates (2,2) to coordinates (3,5).
DESCRIPTION OF THE PREFERRED EMBODIMENT(S)
Overall System-FIG. 1
FIG. 1 depicts a block diagram representation of a display system 10 in accordance with the present invention. Typically, the system 10 is a conventional computer system having a processor (CPU) 11, a memory 12, a display 14, and a keyboard 15.
In the FIG. 1 system, application computer programs 18 are stored in the memory 12 and are executed in the processor 11 under control of a software operating system 17 also stored in memory 12. The operation of such a computer system is well known.
In many application programs executable by the system 10, there is a need to draw lines. Such lines are drawn by a line-draw program and such a line-draw program together with a display system is one embodiment of the present invention. The line draw program is an application program 18, or part thereof, stored in memory 12 and executed by the processor 11.
The application program performs a line-draw method in the apparatus of FIG. 1 to generate and store lines in the memory 12. From the memory 12, the stored lines are displayed in display 14. In line-draw display system of FIG. 1, each pixel (point) on the line is located and addressed by an X-axis coordinate and a Y-axis coordinate defined relative to orthogonal X and Y axes which form a matrix of addressable pixels. A pixel is drawn by determining the X-axis and Y-axis coordinates for the pixel and a line is drawn by determining the X-axis and Y-axis coordinates for all the pixels on the line that are used to define the line.
While a preferred embodiment of the invention employs computer program executing in a general purpose computer as described, a special purpose line-draw processor (engine) 16, as shown in FIG. 1, is also within the scope of the present invention. For example, when the line-draw engine 16 is employed in the FIG. 1 system, the processor 11 is not required to execute the line-draw method since this operation is performed by the special purpose engine 16 which executes the methods of the present invention.
Coordinate System- FIG. 2
In FIG. 2, an XY-axes coordinate system is depicted where the X-axis is horizontal, the Y-axis is vertical, and the D-axis is a diagonal midway between the positive X-axis and positive Y-axis and E-axis is a diagonal midway between the negative X-axis and positive Y-axis. The DE-axes form an orthogonal coordinate system rotated 45 degrees about a common origin relative to the XY-axes.
In FIG. 2, a line 19 to be drawn into the memory 12 and/or to be displayed on the display 14 in accordance with the XY-axes coordinate system of FIG. 2 has a beginning xy coordinate given by (x1, y1) and ending coordinate (x2, y2).
The manner in which the line 19 is drawn changes as a function of the length and orientation of the line 19. If line 19 is a short line, then the line is drawn by a table look-up method. If the line is a medium length line, then line 19 is drawn in accordance with a medium length algorithm. If line 19 is a long length line, then the line is drawn in accordance with a long line algorithm. The most efficient algorithm (short, medium or long) for drawing the line is selected as a function of the length of the line and its orientation.
In general, any line such as line 19 can be represented as a series of shorter horizontal, vertical, or diagonal segments where each segment can be one or more pixels in length. In FIG. 2, line 19 is to be drawn from a first coordinate (x1,y1) to the last coordinate (x2,y2), where x2>x1 and y2>y1. In FIG. 2, (x2-x1)>(y2-y1), so that line 19 is more horizontal than vertical. For line 19, the horizontal lengths in pixels of the middle segments are either the floor of or the ceiling of (x2-x1)/(y2-y1). Error terms are used to choose between drawing each middle segment with a number of pixels equal to the "floor" length or with a number of pixels equal to the "ceiling" length. The pixel lengths of the beginning and end segments for line 19 are either the floor or the ceiling of [(x2-x1)/(y2-y1)]/2. Again, error terms are tested to choose between drawing each beginning and end segment with a number of pixels equal to the "floor" length or with a number of pixels equal to the "ceiling" length.
Since unconditional pixels can be drawn without manipulating the error term, these pixels are drawn rapidly.
A fast algorithm for drawing lines into a bitmap located in memory 12 using a Motorola 68020 microprocessor for processor 11 is given, in assembly language form, in the following TABLE 3 for a single segment loop method. While the Motorola 68020 microprocessor is typical, the algorithm of TABLE 3 applies equally well to any microprocessor or other processor. Using the TABLE 3 method, the greatest performance increases are for long lines which the 68020 processor, for example, can draw twice as fast as the standard Bresenham algorithm.
In TABLE 3, only the inner loop is shown, since the inner loop dominates performance in drawing long lines.
The assembly code of TABLE 3 draws the same pixels as Bresenham's code of TABLE 2 above. Bresenham's code of TABLE 2 draws a single pixel in the inner loop while TABLE 3 draws multiple pixels in the inner loop.
Multi-pixel Segment Loops
In TABLE 4, a complete computer program is listed capable of drawing any line of arbitrary length and orientation (arbitrary Average Segment Length). In the computer program of TABLE 4, multi-pixel segment loops are implemented in various forms. In TABLE 4, the segment loops are of the following categories.
Example
An example of the Single Segment Loop appears in TABLE 4, Lines 346:365, where C=1 (hence either 0 or 1 unconditional pixel is drawn) as follows:
Example
An example of the Single Segment Loop With Modified Unconditional Loop appears in TABLE 4, Lines 479:509, where U=4n+1 (4 unconditional pixels are drawn for each of "n" executions of the unconditional loop and 1 remainder pixel is drawn where ULS equals 4) and C=1 (either 0 or 1 conditional pixels are drawn) as follows:
Example
An example of the Double Segment Loop appears in TABLE 4, Lines 224:235 as follows:
Line-Draw Method-FIG. 3
FIG. 3 depicts a flow chart of the line-draw method executed by the FIG. 1 system. TABLE 4 is the C-language code of a software embodiment corresponding to the FIG. 3 flow chart. The code of TABLE 4 is compiled and executed in the processor of FIG. 1. In FIG. 3, the numbers appearing opposite boxes correspond to the code line numbers in TABLE 4.
(Lines 1:44 TABLE 4). In FIG. 3, set up conditions are established (lines 1:44 of TABLE 4) including defining a short line length (SHORT.sub.-- LENGTH) from 0 to 2 pixels and a medium line length (MEDIUM.sub.-- LINE) from 3 to 20 pixels so that a long line is 21 or more pixels. SHORT.sub.-- LENGTH is the cutoff pixel between the short-length and medium-length algorithms. This value determines the number of cases (nine in the example described) explicitly handled by the short-length algorithm. MEDIUM.sub.-- LENGTH is the cutoff point between the medium-line algorithm and the long-line algorithm. These values can be adjusted for specific embodiments of the code.
(Lines 45:47 TABLE 4). In FIG. 3, dx and dy are computed from which line length and orientation are determined.
(Line 48 TABLE 4). A short line determination is made.
(Lines 49:111 TABLE 4). If a short line, the short line method DRAW SHORT is performed.
The short line method transforms the dx and dy values to an address for addressing a table of short lines. In the example described in connection with TABLE 4, the short line is defined to be of length of 0, 1, or 2 pixels. These pixel lengths represent nine different lines which are defined by nine cases in TABLE 4, namely, case 0, case 4, case 8, case 1, case 5, case 9, case 2, case 6, and case 10. Depending on the values of dx and dy for a particular short line, one of the nine cases in TABLE 4 is executed to draw the short line. For example, with dx=2, dy=0, a three pixel horizontal line is drawn. For another example, with dx=1, dy=1, a two pixel diagonal line is drawn. Similar lines are drawn for each of the seven cases.
(Line 112 TABLE 4). If not a short line, the vertical line test is performed.
(Lines 113:119 TABLE 4). If a vertical line, the vertical line method DRAW VERT is performed.
(Line 120 TABLE 4). If not a vertical line, the horizontal line test is performed.
(Lines 121:127 TABLE 4). If a horizontal line, the horizontal line method DRAW HORZ is performed.
(Line 128 TABLE 4). If not a horizontal line, the diagonal line test is performed.
(Lines 129:135 TABLE 4). If a diagonal line, the diagonal line method DRAW DIAG is performed.
(Lines 136:197 TABLE 4). If not a short line, vertical line, horizontal line or diagonal line (not an axial line), then setup occurs for a medium or long line.
The following common parameters are computed for both the medium-line and long-line methods.
The error adjustment term `errAdjust` has two effects:
It enables the medium and long line algorithms to draw the same pixels as Bresenham's algorithm. Without this term, some pixels might be chosen differently when the primary direction is diagonal.
It makes the vectors `reversible`. (The same pixels are chosen for the vector regardless of the ordering of the endpoints.)
The above parameters, along with the starting position, completely describe the path of the line. The principal direction of the line is determined. There are 16 possible directions for the line, but since the algorithm is symmetric about the x-axis, only the following eight cases need be considered:
1. always move right, sometimes move right and up/down
2. always move right and up/down, sometimes move right
3. always move right and up/down, sometimes move up/down
4. always move up/down, sometimes move right and up/down
5. always move up/down, sometimes move left and up/down
6. always move left and up/down, sometimes move up/down
7. always move left and up/down, sometimes move left
8. always move left, sometimes move left and up/down
The inclusion of diagonal directions implies that two pixels are always drawn in the major direction before moving in the minor direction for the middle of the line. This relationship makes the line drawing algorithms more efficient by allowing them to be optimized for the major direction.
(Line 198 TABLE 4). A medium line determination is made.
(Lines 199:247 TABLE 4). If a medium line, the medium line method DRAW MEDIUM is performed.
Medium length lines are drawn in three parts: beginning, middle, and end. Although parameters are the same as in Bresenham's algorithm, there are the following important differences:
1. The use of a diagonal primary direction (d-axis) implies that two pixels are always drawn in the major direction before moving in the minor direction in the `middle loop`. This makes the `middle loop` faster because two pixels are drawn before any decisions are made. However, the beginning and end of the line may still consist of a single pixel, so these are drawn separately.
2. Bresenham's algorithm decrements a counter in the major direction to detect the terminating condition while the present method decrements a counter in the minor direction. Since the minor direction is advanced at most half as often as the major direction, and on average about a quarter as often, the present method is considerably faster. Also, the conditional branch which decides whether to continue to advance in the major direction can now perform double duty as loop control. This feature alone makes the `middle loop` equivalent to an unrolled Bresenham loop, but without the code space required by actually unrolling the loop. Of course, the loop of the present method is actually much faster than an unrolled Bresenham loop because of the `two pixel` effect described above.
3. Unlike Bresenham's algorithm, there are no branches in the `middle loop` other than the two loop controls. This makes the code of the present method compact and efficient.
(Line 248:603 TABLE 4). If not a medium line, the long line method DRAW LONG is performed.
The long line algorithm draws long lines by breaking them up into horizontal, vertical, or diagonal segments. This choice is reflected by the values of nextA, nextAB, da and db.
The general algorithm is as follows:
1. Draw the beginning segment of the line.
2. Draw all middle segments of the line. An appropriate loop is chosen to match the segment length.
3. Draw the end segment of the line.
Every segment (including the beginning and end segments) consists of a fixed number of unconditional pixels which are always drawn and one conditional pixel which may optionally be drawn depending on the value of the error term at that point in the line.
The length of the middle segment without the conditional pixel is as follows:
nMidPixels=da div db
The lengths of the beginning and end segments without the conditional pixel are as follows:
nStartPixels=nEndPixels=nMidPixels div 2
The vectors drawn by this algorithm are `reversible` (that is, the same pixels are drawn regardless of the ordering of the end points). This result is implemented with the `errAdjust` term to bias the conditional tests within the drawing loops. The loop to draw the beginning segment does several things at once:
1. Draws all unconditional pixels in the beginning segment.
2. Computes the number of unconditional pixels in the beginning and end segments, which is used to compute the number of unconditional pixels in each middle segment. These values are given as follows:
nMidPixels=(int)(da/db)
nEndPixels=(int)(nMidPixels/2)
3. Computes the error term for the unconditional pixels in the beginning and end segments. These values are needed when the conditional pixel of the end segment is drawn, and are used to compute the error term for the unconditional pixels in each middle segment. These values are given as follows:
The advantages of using this loop instead of a divide to compute nMidPixels and nEndPixels are as follows:
1. The loop is needed to draw the beginning segment of the line anyway; the main difference is that an extra add instruction is required to keep count in this loop (`nEndPixels++`).
2. On average, the loop is executed twice, so the extra add along with the other computations (below) take many fewer ticks than a divide for most processors.
3. The loop overlaps the computation with memory operations, which can hide the ticks required for the extra instructions.
In the embodiment of TABLE 4, the fast long-line and medium-line algorithms for drawing solid lines are based upon the following target computer system.
The pixmap memory in memory 12 of FIG. 1 is organized as 8 bits (one byte) per pixel, with consecutive bytes in memory representing consecutive pixels in increasing x direction in the pixmap. One theoretical embodiment of the long-line algorithm implies infinite code size to draw lines of arbitrary length when those lines approach nearly horizontal, vertical, or diagonal. Since infinite code size is not possible in any practical system, this limitation is overcome by employing unconditional loops with unconditional loop size, ULS, when the length of individual segments within the line exceed some arbitrary length.
In the embodiment of TABLE 4, ULS is arbitrarily chosen as 4 although any finite ULS is possible. A ULS which is a power of 2 is desireable for optimum performance. The references to Div ULS and Mod ULS and in TABLE 4 to "Mod4", "Div4", "case 0" through "case 3" entries of "switch" statements, and the number of sequential pixels drawn in each of the case statements result from this choice of ULS 4.
In the embodiment of TABLE 4, for clarity no clipping occurs, but, of course, the same long-line and medium-line algorithms can be used for the middle sections of clipped lines with the same performance advantages for non-clipped lines, but for clipped lines care must be taken for clipped endpoints. ##SPC1##
In TABLE 5, a trace of the execution of the program of TABLE 4 is shown when the medium-length line of FIG. 4 is drawn from XY coordinates (1,1) to (16,7) using the medium-length line algorithm.
In TABLE 6, a trace of the execution of the program of TABLE 4 is shown when the long-length line of FIG. 7 is drawn from XY coordinates (1,1) to (31,13) using the long-length line algorithm.
Performance Analysis Of Line-Draw Methods
This analysis compares the performance of the three following line- draw methods:
1. Bresenham's Method
2. Double Loop Burst Method (medium lines)
3. Single Loop Burst Method (long lines)
For simplicity and clarity, this analysis is restricted to the middle loops of all of three methods ignoring any special code to draw pixels near the beginning and ends of the lines. For long lines, this simplifying assumption is meaningful.
The performance of each of these methods can be characterized by the time it takes to execute three components of the code:
T.sub.-- --Code to draw the pixel and advance the pixel address.
T.sub.-- decide --code to manipulate the decision variable.
T.sub.-- loop --Code to continue or terminate the loop.
Each of the three methods executes these three components of code at different rates per pixel. The equations for each of the three methods can be expressed in terms of the component times for each of these three components resulting in a total time, T.sub.-- total, per pixel:
The terms R.sub.-- pixel, R.sub.-- decide, and R.sub.-- loop are the ratios indicating how often each piece of code is executed per pixel. For example, a ratio of 0.5 means that the code is executed once for every two pixels. The following table shows the ratios for each of the three line drawing methods. These ratios are averaged over lines with arbitrary slope and the results are indicated in TABLE 7.
The times T.sub.-- pixel, T.sub.-- decide, and T.sub.-- loop can be computed for a given CPU, and are approximately the same for each of the three line drawing methods. The following table shows the times for a Motorola 68020. These times are based on drawing an 8-bit pixel with a byte write operation.
The approximate execution times per pixel for each of the methods on a Motorola 68020 are
The times only represent the inner loop, not the ends or setup, and are only approximate because the times T.sub.-- pixel, T.sub.-- decide, and T.sub.-- loop are not constant for each of the methods. Nevertheless the times are substantially the same and hence this analysis indicates that the multi-pixel segment burst methods of the present invention are far superior to Bresenham's Method.
While the invention has been particularly shown and described with reference to preferred embodiments thereof, it will be understood by those skilled in the art that the foregoing and other changes in form and details may be made therein without departing from the spirit and scope of the invention.