Normal quotes
This commit is contained in:
parent
5e10794a24
commit
18011c595a
352 changed files with 6040 additions and 6040 deletions
46
36-03.md
46
36-03.md
|
|
@ -6,9 +6,9 @@
|
|||
|
||||
A couple of run-length slice implementation details yet remain. First is
|
||||
the matter of how error-term turnover is detected. This is done in much
|
||||
the same way as it is with standard Bresenham’s: The error term is
|
||||
the same way as it is with standard Bresenham's: The error term is
|
||||
maintained as a negative valve and advances for each step; when the
|
||||
error term reaches 0, it’s time to add an extra pixel to the current
|
||||
error term reaches 0, it's time to add an extra pixel to the current
|
||||
run. This means that we only have to test for carry after advancing the
|
||||
error term to determine whether or not to add an extra pixel to each
|
||||
run. (Actually, the code in this chapter tests for the error term being
|
||||
|
|
@ -16,9 +16,9 @@ greater than zero, but the assembly code in the next chapter will use
|
|||
the very efficient carry approach.)
|
||||
|
||||
The second and more difficult detail is balancing the runs so that
|
||||
they’re centered around the ideal line, and therefore draw the same
|
||||
pixels that standard Bresenham’s would draw. If we just drew full-length
|
||||
runs from the start, we’d end up with an unbalanced line, as shown in
|
||||
they're centered around the ideal line, and therefore draw the same
|
||||
pixels that standard Bresenham's would draw. If we just drew full-length
|
||||
runs from the start, we'd end up with an unbalanced line, as shown in
|
||||
Figure 36.5. Instead, we have to split the initial pixel plus one full
|
||||
run as evenly as possible between the first and last runs of the line,
|
||||
and adjust the initial error term appropriately for the initial
|
||||
|
|
@ -33,18 +33,18 @@ can scale up this halved error term for the initial run by two times,
|
|||
and thereby make it an integer.
|
||||
|
||||
The other trick here is that if an odd number of pixels are allocated
|
||||
between the first and last partial runs, we’ll end up with an odd pixel,
|
||||
between the first and last partial runs, we'll end up with an odd pixel,
|
||||
since we are unable to draw a half-pixel. This odd pixel is accounted
|
||||
for by adding half a pixel to the error term.
|
||||
|
||||
That’s all there is to run-length slice line drawing; the partial first
|
||||
That's all there is to run-length slice line drawing; the partial first
|
||||
and last runs are the only tricky part. Listing 36.1 is a run-length
|
||||
slice implementation in C. This is not an optimized implementation, nor
|
||||
is it meant to be; this listing is provided so that you can see how the
|
||||
run-length slice algorithm works. In the next chapter, I’ll move on to
|
||||
run-length slice algorithm works. In the next chapter, I'll move on to
|
||||
an optimized version, but for now, Listing 36.1 will make it much easier
|
||||
to grasp the principles of run-length slice drawing, and to understand
|
||||
the optimized code I’ll present in the next chapter.
|
||||
the optimized code I'll present in the next chapter.
|
||||
|
||||
\
|
||||
**Figure 36.5** *Balancing run-length slice lines: a) unbalanced; b)
|
||||
|
|
@ -52,7 +52,7 @@ balanced.*
|
|||
|
||||
**LISTING 36.1 L36-1.C**
|
||||
|
||||
/* Run-length slice line drawing implementation for mode 0x13, the VGA’s
|
||||
/* Run-length slice line drawing implementation for mode 0x13, the VGA's
|
||||
320x200 256-color mode. Not optimized! Tested with Borland C++ in
|
||||
the small model. */
|
||||
|
||||
|
|
@ -72,7 +72,7 @@ balanced.*
|
|||
int WholeStep, InitialPixelCount, FinalPixelCount, i, RunLength;
|
||||
char far *ScreenPtr;
|
||||
|
||||
/* We’ll always draw top to bottom, to reduce the number of cases we have to
|
||||
/* We'll always draw top to bottom, to reduce the number of cases we have to
|
||||
handle, and to make lines between the same endpoints draw the same pixels */
|
||||
if (YStart > YEnd) {
|
||||
Temp = YStart;
|
||||
|
|
@ -85,7 +85,7 @@ balanced.*
|
|||
/* Point to the bitmap address first pixel to draw */
|
||||
ScreenPtr = MK_FP(SCREEN_SEGMENT, YStart * SCREEN_WIDTH + XStart);
|
||||
|
||||
/* Figure out whether we’re going left or right, and how far we’re
|
||||
/* Figure out whether we're going left or right, and how far we're
|
||||
going horizontally */
|
||||
if ((XDelta = XEnd - XStart) < 0)
|
||||
{
|
||||
|
|
@ -96,7 +96,7 @@ balanced.*
|
|||
{
|
||||
XAdvance = 1;
|
||||
}
|
||||
/* Figure out how far we’re going vertically */
|
||||
/* Figure out how far we're going vertically */
|
||||
YDelta = YEnd - YStart;
|
||||
|
||||
/* Special-case horizontal, vertical, and diagonal lines, for speed
|
||||
|
|
@ -158,16 +158,16 @@ balanced.*
|
|||
InitialPixelCount = (WholeStep / 2) + 1;
|
||||
FinalPixelCount = InitialPixelCount;
|
||||
|
||||
/* If the basic run length is even and there’s no fractional
|
||||
/* If the basic run length is even and there's no fractional
|
||||
advance, we have one pixel that could go to either the initial
|
||||
or last partial run, which we’ll arbitrarily allocate to the
|
||||
or last partial run, which we'll arbitrarily allocate to the
|
||||
last run */
|
||||
if ((AdjUp == 0) && ((WholeStep & 0x01) == 0))
|
||||
{
|
||||
InitialPixelCount--;
|
||||
}
|
||||
/* If there’re an odd number of pixels per run, we have 1 pixel that can’t
|
||||
be allocated to either the initial or last partial run, so we’ll add 0.5
|
||||
/* If there're an odd number of pixels per run, we have 1 pixel that can't
|
||||
be allocated to either the initial or last partial run, so we'll add 0.5
|
||||
to error term so this pixel will be handled by the normal full-run loop */
|
||||
if ((WholeStep & 0x01) != 0)
|
||||
{
|
||||
|
|
@ -186,7 +186,7 @@ balanced.*
|
|||
RunLength++;
|
||||
ErrorTerm -= AdjDown; /* reset the error term */
|
||||
}
|
||||
/* Draw this scan line’s run */
|
||||
/* Draw this scan line's run */
|
||||
DrawHorizontalRun(&ScreenPtr, XAdvance, RunLength, Color);
|
||||
}
|
||||
/* Draw the final run of pixels */
|
||||
|
|
@ -218,16 +218,16 @@ balanced.*
|
|||
InitialPixelCount = (WholeStep / 2) + 1;
|
||||
FinalPixelCount = InitialPixelCount;
|
||||
|
||||
/* If the basic run length is even and there’s no fractional advance, we
|
||||
/* If the basic run length is even and there's no fractional advance, we
|
||||
have 1 pixel that could go to either the initial or last partial run,
|
||||
which we’ll arbitrarily allocate to the last run */
|
||||
which we'll arbitrarily allocate to the last run */
|
||||
if ((AdjUp == 0) && ((WholeStep & 0x01) == 0))
|
||||
{
|
||||
InitialPixelCount--;
|
||||
}
|
||||
/* If there are an odd number of pixels per run, we have one pixel
|
||||
that can’t be allocated to either the initial or last partial
|
||||
run, so we’ll add 0.5 to the error term so this pixel will be
|
||||
that can't be allocated to either the initial or last partial
|
||||
run, so we'll add 0.5 to the error term so this pixel will be
|
||||
handled by the normal full-run loop */
|
||||
if ((WholeStep & 0x01) != 0)
|
||||
{
|
||||
|
|
@ -247,7 +247,7 @@ balanced.*
|
|||
RunLength++;
|
||||
ErrorTerm -= AdjDown; /* reset the error term */
|
||||
}
|
||||
/* Draw this scan line’s run */
|
||||
/* Draw this scan line's run */
|
||||
DrawVerticalRun(&ScreenPtr, XAdvance, RunLength, Color);
|
||||
}
|
||||
/* Draw the final run of pixels */
|
||||
|
|
|
|||
Loading…
Reference in a new issue