resman
Veteran Member
Nothing new here, in fact this is from projects 30+ years ago that I never had a chance to complete satisfactorily due to time constraints.
Everything is posted on GitHub: https://github.com/dschmenk/Bresen-Span
First up is a span based Bresenham line implementation. Being able to fill horizontal or vertical spans of pixels at a time instead of the simpler pixel at a time was a performance win once upon a time. Calculating the span lengths before iterating through the line always seemed more difficult than necessary. So I spent time simplifying, clarifying and ensuring it hit the exact same pixels as the pixel-at-a-time implementation. There is a C version and an 8086 assembly version using function pointers to write the pixel spans so that the generic line routine can be used with many different backends. As an example, there is a triangle filling demo that uses the line drawer to save the edges of a triangle into a left and right edge array, then use the horizontal span routine to fill the scan lines of the edge array. Or, optionally, just draw the edges of the triangle.
Second is an anti-aliased line drawer using Wu's algorithm (and probably independently discovered by anyone who ever tried to implement an AA line routine). I still may not be completely happy with the precision of the resulting line, but it looks pretty good for near horizontal/vertical lines. Only a C version exists, but a 8086 assembly version would be pretty straight forward.
Lastly, to play with all of this, there is tiny library to use VGA mode 13h (320x200 @ 8BPP) that programs a 3-3-2 RGB color cube and uses dithering to improve the result a little. Lines can be draw with a dithered pattern brush, or the closest solid match to the 3-3-2 RGB palette. The TESTLINE.EXE demo program will time the pixel-at-a-time line drawer and the span-at-a-time line drawer with both the dithered pattern lines or solid line depending on the disable dithering '-d0' flag passed in on the command line. The triangle filling demo is FILLTRI.EXE with two flags: '-d0' disables dithering and '-f0' disables filling.
The best reference to investigate these algorithms and many others would be Michael Abrash's "Black Book" of Graphics Programming: http://www.drdobbs.com/parallel/graphics-programming-black-book/184404919
P.S. I recently acquired a VGA card for my original Compaq Deskpro. This seemed like a good opportunity to revisit that 30 year old itch and scratch it a bit. I have much faster machines with VGAs installed, but like the old saying: "It's more fun to drive a slow car fast than a fast car slow". I hope you enjoy my excursion into graphics history.
Everything is posted on GitHub: https://github.com/dschmenk/Bresen-Span
First up is a span based Bresenham line implementation. Being able to fill horizontal or vertical spans of pixels at a time instead of the simpler pixel at a time was a performance win once upon a time. Calculating the span lengths before iterating through the line always seemed more difficult than necessary. So I spent time simplifying, clarifying and ensuring it hit the exact same pixels as the pixel-at-a-time implementation. There is a C version and an 8086 assembly version using function pointers to write the pixel spans so that the generic line routine can be used with many different backends. As an example, there is a triangle filling demo that uses the line drawer to save the edges of a triangle into a left and right edge array, then use the horizontal span routine to fill the scan lines of the edge array. Or, optionally, just draw the edges of the triangle.
Second is an anti-aliased line drawer using Wu's algorithm (and probably independently discovered by anyone who ever tried to implement an AA line routine). I still may not be completely happy with the precision of the resulting line, but it looks pretty good for near horizontal/vertical lines. Only a C version exists, but a 8086 assembly version would be pretty straight forward.
Lastly, to play with all of this, there is tiny library to use VGA mode 13h (320x200 @ 8BPP) that programs a 3-3-2 RGB color cube and uses dithering to improve the result a little. Lines can be draw with a dithered pattern brush, or the closest solid match to the 3-3-2 RGB palette. The TESTLINE.EXE demo program will time the pixel-at-a-time line drawer and the span-at-a-time line drawer with both the dithered pattern lines or solid line depending on the disable dithering '-d0' flag passed in on the command line. The triangle filling demo is FILLTRI.EXE with two flags: '-d0' disables dithering and '-f0' disables filling.
The best reference to investigate these algorithms and many others would be Michael Abrash's "Black Book" of Graphics Programming: http://www.drdobbs.com/parallel/graphics-programming-black-book/184404919
P.S. I recently acquired a VGA card for my original Compaq Deskpro. This seemed like a good opportunity to revisit that 30 year old itch and scratch it a bit. I have much faster machines with VGAs installed, but like the old saying: "It's more fun to drive a slow car fast than a fast car slow". I hope you enjoy my excursion into graphics history.