3 4 Computer Graphics (CST307) - Lect 3 - 4
3 4 Computer Graphics (CST307) - Lect 3 - 4
Lect 3: Introduction
Dr. Satyendra Singh Chouhan
MNIT Jaipur
Color image generation
Each pixel contains more than one type of element
E.g., 3 phosphor dots representing3 primary color ( R G
B)
When excited, 3 colors combine to produce the desire
output
Color Image generation
Each element capable of
generating different shades
of the color
3 shades combined
together gives the
sensation of the desired
color
How to implement
Direct Coding – individual color information for each R G
and B components of a pixel stored directly in the
corresponding frame buffer location
Large frame buffer size to store all possible color values
All possible combinations of RGB values
Also called color gamut
Another way
Color Look Up Table
Separate look up table
(Portion of memory)
With each entry (row) of
table contains a specific
RGB combination
Frame buffer location
contains pointer to entry in
the table
Color Image generation
CLT assumption
Only require a small fraction of the whole color gamut.
We know it a-priori
If this assumption is not valid then this method is not
much of use
Recap
In the previous lecture, we got introduction of
the CG
Basic understanding of a graphic based system
Today we will introduce the Graphics software
(basic)
Generic Architecture Revisited
Generic Architecture Revisited
We discussed the color values stored in the frame
buffer
How these values are obtained?
Generic Architecture Revisited
We discussed the color values stored in the frame
buffer
How these values are obtained?
Display Processor computes these value in stages
Generic Architecture Revisited
We discussed the color values stored in the frame
buffer
How these values are obtained?
Display Processor computes these value in stages
These stages together are known as Graphic pipeline
Object Representation (1st Stage)
Defining objects that will be part of image on
display (1st stage)
Object Representation (1st Stage)
Defining objects that will be part of image on
display (1st stage)
Object Representation (1st Stage)
Defining objects that will be part of image on
display (1st stage)
y mx y
x
m
|m|<1 |m|>1
Scan Converting A Line
On raster system, lines are plotted with
pixels, and step size (horizontal & vertical
direction) are constrained by pixel
separation.
Scan Converting A Line
We must sample a line at discrete positions
and determine the nearest pixel to the line
at each sampled position.
DDA (Digital Differential Analyzer) Algorithm
Algorithm is an incremental scan conversion
method.
Based on calculating either x or y
If |m|<1, (x 1)
y mx
y K 1 yk m
DDA Algorithm
If |m|>1, (y 1)
y
x
m
1
xK 1 xk
m
If (x 1)
y m x
y K 1 yk m
inline int round (const float a) { return int (a + 0.5); }
void lineDDA (int x0, int y0, int xEnd, int yEnd)
{
int dx = xEnd - x0, dy = yEnd - y0, steps, k;
float xIncrement, yIncrement, x = x0, y = y0;
if (fabs (dx) > fabs (dy))
steps = fabs (dx);
else
steps = fabs (dy);
xIncrement = float (dx) / float (steps);
yIncrement = float (dy) / float (steps);
yk+1
} dupper
d2
y
}dd 1
lower
yk
xk+1
Now compute d_upper and d_lower as
Substituting for y the first equation we get
Substituting for y the first equation we get
pk = 2 Δy xk - 2 Δxyk + 2 Δy +Δx(2c-1)
Because Δx(2C-1) is a constant with Δx and C being
constants for a given line with end points we can replace
Δx(2C-1) with a constant say ‘b’.
pk = 2 Δy xk - 2 Δxyk + b
Let pk+1 be the next decision parameter. We do this to
find a recursive relation between pk and pk+1. i.e.
wherever there is k replace that with k+1 in the previous
equation to obtain pk+1
pk+1 = pk +2 Δy - 2Δx(yk+1 - yk )
Now the sign of pk is to be checked.
Case(i):
If pk <=0 the lower pixel (xk+1, yk) is to be plotted, i.e.
next x is xk+1 and next y is yk.
Therefore yk+1 = yk. Now the previous equation for pk+1
reduces to
Case(i):
If pk <=0 the lower pixel (xk+1, yk) is to be plotted, i.e.
next x is xk+1 and next y is yk.
Therefore yk+1 = yk. Now the previous equation for pk+1
reduces to
pk+1 = pk +2 Δy
Case(ii):
If pk >0 the upper pixel (xk+1, yk+1) is to be plotted,
Therefore next y is yk,+1 now substituting for yk+1 in the
equation for pk+1 we get
pk+1 = pk +2 Δy - 2Δx
The initial decision parameter p0 is computed as below (use
the following eq.)
pk = 2 Δy xk - 2 Δxyk + 2 Δy +Δx(2c-1)
c= y0 – (Δy/Δx) x0
p0 = 2 Δy x0 - 2 Δxy0 + 2 Δy +Δx(2 y0 – 2(Δy/Δx) x0 -1)
p0 = 2 Δy x0 - 2 Δxy0 + 2 Δy +Δx(2 y0 – 2(Δy/Δx) x0 -1)
p0= 2 Δy -Δx
If the point on the theoretical line is equidistant from either
of the possible pixel locations then either of the pixels
could be plotted.
Now the algorithm steps can be summarized as follows for
the case when |m|<=1
Input the two end points
Compute P0
Check cases depending on the sign of P0
Continue with the next decision parameters till the end
of the line is reached
Bresenham’s Algorithm
Bresenham’s Line Algorithm
n Example: Digitize the line with endpoint
(20,10) and (30,18)
P0=2ΔY –ΔX
Pk+1 = Pk + 2ΔY
or
= Pk + 2(ΔY – ΔX(
Trivial Situations: Do not need Bresenham
m 0 horizontal line
m 1 line y x
m vertical line