| 2-D Graphics Primitives - Writeup Phil Katz and Stephen St.Vincent |
|
Lab description Lab summary: The purpose of this lab was to create a generalized graphics library in either C or C++. We chose to write our library in C. The first task was to create an Image structure capable of reading image files (PPMs, specifically), storing them in memory, and writing to PPM files. This task was accomplished relatively easily. The next task was to create various image primitives. These were: Point; Line; Circle; and Ellipse. All of these built upon the Pixel primitive defined in C. We implemented Bresenham's algorithm ( http://en.wikipedia.org/wiki/Bresenham%27s_algorithm) to perform line-drawing. One important note was that this did not cover vertical and horizontal lines, which were implemented separately (see question 3 below). Circles and ellipses were drawn by creating and algorithm to draw the portion of a cicle that lies in one octant (half a quadrant) of the Cartesian plane, then rotating and reflecting to achieve a full circle. Again, special care was taken to ensure that these shapes did not exceed their radii. So, for example, a circle of defined radius 20 will span 19 pixels (inclusive). On a 3.0 GHz Intel Pentium 4, our algorithm was able to draw 300,550 lines per second with 102.9 pixels per line. Before we inlined most of our library functions, we were achieving values around 100,000 lines per second (with comparable pixels/line). This massive speedup shows the power and usefulness of inlining small but frequently-used functions. Questions:
|