CGPresentation Week5 (FrameBuffer&LineDrawingAlgorithms)
CGPresentation Week5 (FrameBuffer&LineDrawingAlgorithms)
Week 5
Working:
• This memory area holds the set of color values for the screen points. These
stored color values are then retrieved from the refresh buffer and used to control
the intensity of the electron beam as it moves from spot to spot across the
screen. In this way, the picture is “painted” on the screen one scan line at a time,
as demonstrated
Also, other kinds of pixel information, besides color, are stored in buffer
locations, so all the different buffer areas are sometimes referred to collectively
as the “frame buffer.”
Home television sets and printers are examples of other systems using raster-scan
methods.
• Another property of video monitors is aspect ratio, which is now often defined as the number of
pixel columns divided by the number of scan lines that can be displayed by the system.
• The number of bits per pixel in a frame buffer is sometimes referred to as either the depth of the
buffer area or the number of bit planes.
• A frame buffer with one bit per pixel is commonly called a bitmap, and a frame buffer with multiple
bits per pixel is a pixmap, but these terms are also used to describe other rectangular arrays, where
a bitmap is any pattern of binary values and a pixmap is a multicolor pattern.
• At a minimum there is
one memory bit for
each pixel.
• This amount of
memory is called a bit
plane. The picture is
built up in the frame
buffer one bit at a time
• A framebuffer stores
the color
representation for
every pixel on the
screen. Its size will
depend upon the
screen resolution.
Presentation By: Ms.Ifrah Mansoor
N-bit planes and Lookup Table
Algorithms are:
• The Naïve Line Drawing Algorithm
• DDA (Digital Differential Analyzer) Algorithm
• Bresenham’s Line Algorithm
Step-01:
Calculate ΔX, ΔY and m from the given input. These parameters are
calculated as-
• ΔX = X2 – X1
• ΔY =Y2 – Y1
• m = ΔY / ΔX
Find the number of steps or points in between the starting and ending
coordinates.
• Keep repeating Step-03 until the end point is reached or the number
of generated new points (including the starting and ending points)
equals to the steps count.
• Solution-
Given-
• Starting coordinates = (X1, Y1) = (5, 6)
• Ending coordinates = (X2, Y2) = (8, 12)
Step-02:
Calculate the number of steps.
• As |ΔX| < |ΔY| = 3 < 6, so number of steps = ΔY = 6
Presentation By: Ms.Ifrah Mansoor
2. The DDA Algorithm
• Practice Problem for
DDA:
Step-03:
• As M > 1, so case-03 is
satisfied.
• Now, Step-03 is
executed until Step-04 is
satisfied.
• Disadvantages of DDA:
• There is an extra overhead of using round off( ) function.
• Using round off( ) function increases time complexity of the algorithm.
• Resulted lines are not smooth because of round off( ) function.
• The points generated by this algorithm are not accurate.
• Successive addition of floating points increment causes calculated pixels to drift away
from the true line.
Presentation By: Ms.Ifrah Mansoor
Line Drawing Algorithms
3. The Bresenhem’s Algorithm
• In this method, next pixel selected is that one who has the least
distance from true line.
The line is best approximated by those pixels that fall the least distance from the
path between P1',P2'
Presentation By: Ms.Ifrah Mansoor
3. The Bresenhem’s Algorithm
• Hence, the Bresenhems algorithm uses a decision parameter (Pk) which
calculates the distance between true line and scan converted pixels and selects
those pixels who have nearest distance from the true line.
Calculate ΔX and ΔY from the given input. These parameters are calculated as-
• ΔX = X2 – X1
• ΔY =Y2 – Y1
Step-02:
Keep repeating Step-03 until the end point is reached or number of iterations equals
to (ΔX-1) times.
Calculate the points between the starting coordinates (9, 18) and ending coordinates
(14, 22)
Solution-
Given-
•Starting coordinates = (X1, Y1) = (9, 18)
•Ending coordinates = (X2, Y2) = (14, 22)
Step-02:
Thus,
• Pk+1 = Pk + 2ΔY – 2ΔX = 3 + (2 x 4) – (2 x 5) = 1
• Xk+1 = Xk + 1 = 9 + 1 = 10
• Yk+1 = Yk + 1 = 18 + 1 = 19
Similarly, Step-03 is executed until the end point is reached or number of iterations
equals to 4 times.
(Number of iterations = ΔX – 1 = 5 – 1 = 4)
Presentation By: Ms.Ifrah Mansoor
3. The Bresenhem’s Algorithm
Practice Problem for Bresenhem
Algorithm:
Step-04:
Step-03 is executed until the end point
is reached or number of iterations
equals to 4 times.
void line() { }
else {
glColor3f(1.0, 0.0, 0.0);
steps = abs(dy);
glPointSize(2.0);
}
int x1, y1, x2, y2; float xInc = (float)dx / (float)steps;
cout << "Enter starting point (x, y)\n"; float yInc = (float)dy / (float)steps;
cout << "Enter x1: "; float x = x1, y = y1;
glutDisplayFunc(line);
glutMainLoop();
return 0;
}
glutDisplayFunc(line);
glutMainLoop();
return 0;
} Presentation By: Ms.Ifrah Mansoor
The Bresenhem’s Algorithm
Output: