12.07.2015 Views

wu'ed in haste; fried, stewed at leisure

wu'ed in haste; fried, stewed at leisure

wu'ed in haste; fried, stewed at leisure

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

of the block is programmable, but must be a power of two. The more <strong>in</strong>tensity levels,the better. Wu says th<strong>at</strong> 32 <strong>in</strong>tensities are enough; on my system, eight and even fourlevels looked pretty good. I found th<strong>at</strong> gamma correction, which gives l<strong>in</strong>early spaced<strong>in</strong>tensity steps, improved antialias<strong>in</strong>g quality significantly. Fortun<strong>at</strong>ely, we can programthe palette with gamma-corrected values, so our draw<strong>in</strong>g code doesn't have todo any extra work.List<strong>in</strong>g 42.1 isn't very fast, so I implemented Wu antialias<strong>in</strong>g <strong>in</strong> assembly, hard-codedfor mode 13H. The implement<strong>at</strong>ion is shown <strong>in</strong> full <strong>in</strong> List<strong>in</strong>g 42.6. High-speed graphicscode and fast VGAs go together like peanut butter and jelly, which is to say verywell <strong>in</strong>deed; the assembly implement<strong>at</strong>ion ran more than twice as fast as the C codeon my 486. Enough said!LISTING 42.6 L42-6.ASM; C near-callable function to draw an antialiased l<strong>in</strong>e from; (XO.YO) to (X1,YI). <strong>in</strong> mode 13h. the VGA's standard 320x200 256-color; mode. Uses an antialias<strong>in</strong>g approach published by Xiaol<strong>in</strong> Wu <strong>in</strong> the July; 1991 issue of Computer Graphics. Requires th<strong>at</strong> the palette be set up so; th<strong>at</strong> there are NumLevels <strong>in</strong>tensity levels of the desired draw<strong>in</strong>g color,; start<strong>in</strong>g <strong>at</strong> color BaseColor (100% <strong>in</strong>tensity) and followed by (NumLevels-1); levels of evenly decreas<strong>in</strong>g <strong>in</strong>tensity, with color (BaseColor+NumLevels-1); be<strong>in</strong>g 0% <strong>in</strong>tensity of the desired draw<strong>in</strong>g color (black). No clipp<strong>in</strong>g is; performed <strong>in</strong> DrawWuL<strong>in</strong>e. Handles a maximum of 256 <strong>in</strong>tensity levels per; antialiased color. This code is suitable for use <strong>at</strong> screen resolutions,; with l<strong>in</strong>es typically no more than 1K long; for longer l<strong>in</strong>es, 32-bit error; arithmetic must be used to avoid problems with fixed-po<strong>in</strong>t <strong>in</strong>accuracy.; Tested with TASM.; C near-callable as:; void DrawWuL<strong>in</strong>e(<strong>in</strong>t XO. <strong>in</strong>t YO, <strong>in</strong>t X1. <strong>in</strong>t Y1. <strong>in</strong>t Basecolor.<strong>in</strong>t NumLevels. unsigned <strong>in</strong>t 1ntensityBit.s);SCREEN-WIDTH-IN-BYTES equ 320 ;# of bytes from the start of one scan l<strong>in</strong>e; to the start of the nextSCREEN-SEGMENT equ OaOOOh ;segment <strong>in</strong> which screen memory resides; Parameters passed <strong>in</strong> stack frame.parms strucdw 2 dup (?) ;pushed BP and return addressX0 dw ? ;X coord<strong>in</strong><strong>at</strong>e of l<strong>in</strong>e start po<strong>in</strong>tYO dw ? ;Y coord<strong>in</strong><strong>at</strong>e of l<strong>in</strong>e start po<strong>in</strong>tX1 dw ? ;X coord<strong>in</strong><strong>at</strong>e of l<strong>in</strong>e end po<strong>in</strong>tY1 dw ? ;Y coord<strong>in</strong><strong>at</strong>e of l<strong>in</strong>e end po<strong>in</strong>tBaseColor dw ? ;color # of first color <strong>in</strong> block used for;antialias<strong>in</strong>g. the 100% <strong>in</strong>tensity version of the;draw<strong>in</strong>g colorNumLevels dw ? ;size of color block, with BaseColor+NumLevels-I; be<strong>in</strong>g the 0% <strong>in</strong>tensity version of the draw<strong>in</strong>g color; (maximum NumLevels - 256)IntensityBits dw ?:log base 2 of NumLevel s: the # of bits used to; describe the <strong>in</strong>tensity of the draw<strong>in</strong>g color.; 2**IntensityBits--NumLevels; (maximum IntensityBits - 8)parms endsWu'ed <strong>in</strong> Haste; Fried, Stewed <strong>at</strong> Leisure 787

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!