




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





























































































Output Primitives : Points and Lines – Line-Drawing algorithms – Loading frame Buffer – Line
function – Circle-Generating algorithms – Ellipse-generating algorithms.
Attributes of Output Primitives : Line Attributes – Curve attributes – Color and Grayscale
Levels – Area-fill attributes – Character Attributes.
2D Geometric Transformations: Basic Transformations – Matrix Representations –
Composite Transformations – Other Transformations. 2D Viewing: The Viewing Pipeline –
Viewing Co-ordinate Reference Frame – Window-to-Viewport Co-ordinate Transformation - 2D
Viewing Functions – Clipping Operations.
Text: Types of Text – Unicode Standard – Font – Insertion of Text – Text compression – File
formats. Image: Image Types – Seeing Color – Color Models – Basic Steps for Image Processing
Device Independent Color Models – Image Processing software – File Formats – Image Output on
Monitor and Printer.
Audio: Introduction – Acoustics – Nature of Sound Waves – Fundamental Characteristics
of Sound – Microphone – Amplifier – Loudspeaker – Audio Mixer – Digital Audio – Synthesizers
CODECs – Audio Recording Systems – Audio and Multimedia – Voice Recognition and Response
Video: Analog Video Camera – Transmission of Video Signals – Video Signal Formats –
Television Broadcasting Standards – PC Video – Video File Formats and CODECs – Video
Editing – Video Editing Software. Animation: Types of Animation – Computer Assisted
Animation – Creating Movement – Principles of Animation – Some Techniques of Animation –
Animation on the Web – Special Effects – Rendering Algorithms. Compression: MPEG-1 Audio
Output Primitives : Points and Lines – Line-Drawing algorithms – Loading frame Buffer – Line
function – Circle-Generating algorithms – Ellipse-generating algorithms.
Attributes of Output Primitives : Line Attributes – Curve attributes – Color and Grayscale
Levels – Area-fill attributes – Character Attributes.
Computer Graphic is the discipline of producing picture or images using a computer which
include modeling, creation, manipulation, storage of geometric objects, rendering, converting a
scene to an image, the process of transformations, rasterization, shading, illumination, animation
of the image, etc.
Computer Graphics has been widely used in graphics presentation, paint systems,
computer-aided design (CAD), image processing, simulation, etc. From the earliest text character
images of a non-graphic mainframe computers to the latest photographic quality images of a high
resolution personal computers, from vector displays to raster displays, from 2D input, to 3D input
and beyond, computer graphics has gone through its short, rapid changing history. From games to
virtual reality, to 3D active desktops, from unobtrusive immersive home environments, to
scientific and business, computer graphics technology has touched almost every concern of our
life. Before we get into the details, we have a short tour through the history of computer graphics
Introduction
The basic elements constituting a graphic are called output primitives. Each output
primitive has an associated set of attributes, such as line width and line color for lines. The
programming technique is to set values for the output primitives and then call a basic function that
will draw the desired primitive using the current settings for the attributes. Various graphics
systems have different graphics primitives.
For example GKS defines five output primitives namely, polyline (for drawing contiguous
line segments), polymarker (for marking coordinate positions with various symmetric text
symbols), text (for plotting text at various angles and sizes), fill area (for plotting polygonal areas
with solid or hatch fill), cell array (for plotting portable raster images). At the same time GRPH
has the output primitives namely Polyline, Polymarker, Text, Tone and have other secondary
primitives besides these namely, Line and Arrow
Points and Lines
In a CRT monitor, the electron beam is turned on to illuminate the screen phosphor at the
selected location. Depending on the display technology, the positioning of the electron beam
changes. In a random-scan (vector) system point plotting instructions are stored in a display list
and the coordinate values in these instructions are converted to deflection voltages the position the
∆y=m ∆x
Similiarly,we can obtain the x interval ∆x to the corresponding ∆y as
∆x= ∆y/m
Rasterization
Rasterization is the process of converting a vertex representation to a pixel representation;
rasterization is also called scan conversion. Included in this definition are geometric objects such
as circles where you are given a center and radius.
The digital differential analyzer (DDA) which introduces the basic concepts for
rasterization.
Bresenham's algorithm which improves on the DDA.
Scan conversion algorithms use incremental methods that exploit coherence. An
incremental method computes a new value quickly from an old value, rather than computing the
new value from scratch, which can often be slow. Coherence in space or time is the term used to
denote that nearby objects (e.g., pixels) have qualities similar to the current object.
1. Digital Differential Analyzer (DDA) Algorithm
In computer graphics, a hardware or software implementation of a digital differential
analyzer (DDA) is used for linear interpolation of variables over an interval between start and end
point.
DDAs are used for rasterization of lines, triangles and polygons. In its simplest
implementation the DDA algorithm interpolates values in interval [(x start
, y start
), (x end
, y end
)] by
computing for each x i
the equations x i
= x i−
+1, y i
= y i−
− x start
and Δy
= y end
− y start
Digital Differential Analyzer (DDA) Algorithm:-
x
slope of the line
y
In this algorithm, the line is sampled at unit intervals in one coordinate and find the corresponding
values nearest to the path for the other coordinate. For a line with positive slope less than one, x >
y (where x = x2-x1 and y = y2-y1).
Hence we sample at unit x=1 intervals and compute each successive y values as
y k+
=y k
+ m
y= m x+b*
For lines with positive slope greater than one, y > x. Hence we sample at unit y intervals and
compute each successive x values as
k+
k
+1/m
Since the slope, m, can be any real number, the calculated value must be rounded to the nearest
integer.
( xi , yi )
( xi , Round( yi ))
positive slope left to right positive slope right to left all points are joint together
For a line with negative slope, if the absolute value of the slope is less than one, we make unit
increment in the x direction and calculate y values as
y k+
=y k
- m
For a line with negative slope, if the absolute value of the slope is greater than one, we make unit
decrement in the y direction and calculate x values as
k+
k
+1/m
[Note :- for all the above four cases it is assumed that the first point is on the left and second point
is in the right.]
DDA Line Algorithm
void myLine(int x1, int y1, int x2, int y2)
int length,i;
double x,y;
double xincrement;
double yincrement;
length = abs(x2 - x1);
if (abs(y2 - y1) > length) length = abs(y2 - y1);
xincrement = (double)(x2 - x1)/(double)length;
yincrement = (double)(y2 - y1)/(double)length;
Bresenham's algorithm chooses the integer y corresponding to the pixel center that is
closest to the ideal (fractional) y for the same x ; on successive columns y can remain the same or
increase by 1. The general equation of the line through the endpoints.
Since we know the column, x , the pixel's row, y , is given by rounding this quantity to the
nearest integer.
The slope ( y 1
− y 0
) / ( x 1
− x 0
) depends on the endpoint coordinates only and can be
precomputed, and the ideal y for successive integer values of x can be computed starting
from y 0
and repeatedly adding the slope.
In practice, the algorithm can track, instead of possibly large y values, a small error value
between −0.5 and 0.5: the vertical distance between the rounded and the exact y values for the
current x. Each time x is increased, the error is increased by the slope; if it exceeds 0.5, the
rasterization y is increased by 1 (the line continues on the next lower row of the raster) and the
error is decremented by 1.0.
In the following pseudocode sample plot(x,y) plots a point and abs returns absolute value:
function line(x0, x1, y0, y1)
int deltax := x1 - x
int deltay := y1 - y
real error := 0
real deltaerr := abs (deltay / deltax) // Assume deltax != 0 (line is not vertical),
// note that this division needs to be done in a way that preserves the fractional part
int y := y
for x from x0 to x
plot(x,y)
error := error + deltaerr
if error ≥ 0.5 then
y := y + 1
error := error - 1.
Generalization
The version above only handles lines that descend to the right. We would of course like to
be able to draw all lines. The first case is allowing us to draw lines that still slope downwards but
head in the opposite direction. This is a simple matter of swapping the initial points if x0 > x1.
Trickier is determining how to draw lines that go up. To do this, we check if y 0
≥ y 1
; if so, we step
y by - 1 instead of 1.
Lastly, we still need to generalize the algorithm to drawing lines in all directions. Up until
now we have only been able to draw lines with a slope less than one. To be able to draw lines with
a steeper slope, we take advantage of the fact that a steep line can be reflected across the line y=x to
obtain a line with a small slope. The effect is to switch the x and y variables throughout, including
switching the parameters to plot. The code looks like this:
function line(x0, x1, y0, y1)
boolean steep := abs(y1 - y0) > abs(x1 - x0)
if steep then
swap(x0, y0)
swap(x1, y1)
if x0 > x1 then
swap(x0, x1)
swap(y0, y1)
int deltax := x1 - x
int deltay := abs(y1 - y0)
real error := 0
real deltaerr := deltay / deltax
int ystep
int y := y
if y0 < y1 then ystep := 1 else ystep := - 1
for x from x0 to x
if steep then plot(y,x) else plot(x,y)
error := error + deltaerr
if error ≥ 0.5 then
y := y + ystep
error := error - 1.
The function now handles all lines and implements the complete Bresenham's algorithm.
if y0 < y1 then ystep := 1 else ystep := - 1
for x from x0 to x1 with increment inc REM changed
if steep then plot(y,x) else plot(x,y)
REM increment here a variable to control the progress of the line drawing
error := error - deltay
if error < 0 then
y := y + ystep
error := error + deltax
Simplification
It is further possible to eliminate the swaps in the initialisation by considering the error
calculation for both directions simultaneously:
function line(x0, y0, x1, y1)
dx := abs(x1-x0)
dy := abs(y1-y0)
if x0 < x1 then sx := 1 else sx := - 1
if y0 < y1 then sy := 1 else sy := - 1
err := dx-dy
loop
setPixel (x0,y0)
if x0 = x1 and y0 = y1 exit loop
e2 := 2*err
if e2 > - dy then
err := err - dy
x0 := x0 + sx
end if
if e2 < dx then
err := err + dx
y0 := y0 + sy
end if
end loop
In this method, developed by Jack Bresenham, we look at just the center of the pixels. We
determine d1 and d2 which is the "error", i.e., the difference from the "true line."
Steps in the Bresenham algorithm:
Now the y coordinate on the mathematical line at pixel position xi+1 is calculated as
y = m(xi+1) + b
And the distances are calculated as
d1 = y - yi= m(xi+1) + b - yi
d2 = (yi+1) - y = yi +1 - m(xi +1) - b
Then
d1 - d2 = 2m(xi+1) - 2y + 2b - 1
Now define pi = dx(d1 - d2) = relative error of the two pixels.
Note: pi < 0 if yi pixel is closer, pi >= 0 if yi+1 pixel is closer. Therefore we only need to know
the sign of pi.
ith m = dy/dx and substituting in for (d1 - d2) we get
pi = 2 * dy * xi - 2 * dx * yi + 2 * dy + dx * (2 * b - 1) (1)
Let C = 2 * dy + dx * (2 * b - 1)
Now look at the relation of p's for successive x terms.
pi+1 = 2dy * xi+1 - 2 * dx * yi+1 + C
pi+1 - pi = 2 * dy * (xi+1 - xi) - 2 * dx * ( yi+1 - yi)
with xi+1 = xi + 1 and yi+1= yi + 1 or yi
pi+1 = pi + 2 * dy - 2 * dx(yi+1 - yi)
Now compute p1 (x1,y1) from (1) , where b = y - dy / dx * x
p1 = 2dy * x1 - 2dx * y1 + 2dy + dx(2y1 - 2dy / dx * x1 - 1)
= 2dy * x1 - 2dx * y1 + 2dy + 2dx * y1 - 2dyx1 - dx
= 2dy - dx
if pi < 0, plot the pixel (xi+1, yi) and next decision parameter is pi+1 = pi + 2dy
else and plot the pixel (xi+1, yi+1) and next decision parameter is pi+1 = pi + 2dy - 2dx
Bresenham Algorithm for 1st octant :
Note: Only integer Addition and Multiplication by 2.
Notice we always increment x by 1.
For a generalized Bresenham Algorithm must look at behavior in different octants.
3.Parallel line algorithms
Take advantage of multiple processors.
Given n p
processors, subdivide the line path into n p
Bresenham segments.
For a line with slope 0 m 1 and leftpoint ( x 0 , y 0 ) the distance to the right endpoint
(left endpoint for next segment) is
Each processor then calculates the pixel positions over its assigned subinterval
using the starting decision parameter value for that subinterval and the starting
coordinates (x k
,y k
Another way to set up parallel algorithms on raster systems is to assign each
processor to a particular group of screen pixels. Assign each processor to 1 pixel
within some screen region. This approach can be adapted to line display by
assigning 1 processor to each of the pixels within the limits of the line coordinates
extends (bounding rectangle) and calculating the pixel distances from the line path.
The no: of pixels within the bounding box of the line is ∆x * ∆y. Perpendicular
distance d from the line to a pixel with coordinates (x,y) is calculated as,
d = Ax + By + C
where, A = - ∆y / line length
B = ∆x / line length
C = x 0
∆y – y 0
∆x / line length
With line length = √(∆x
2
+ ∆y
2
Once the constants A,B,C are calculated, the processor needs to perform 2
multiplications and 2 additions to compute the pixel distance d. A pixel is plotted
if d < a specified line thickness parameter. Instead of partitioning the screen
intosingle pixels, we can assign to each processor either a scanline or a column of
pixels depending on the line slope
When straight line segments and other coordinate extends are scan converted for
display with a raster system, frame buffer positions must be calculated.
Scan conversion algorithms generate pixel positions at successive unit intervals.
This allows using incremental methods to calculate frame buffer addresses
Suppose the frame buffer array is addressed in row major order and that pixel
positions vary from (0,0) at the lower left screen corner to (x max
,y max
) at the top
right corner. For a bi-level system (1 bit per pixel) the frame buffer bit address for
pixel position (x,y) is calculated as
addr(x,y) = addr(0,0) + y(x max
+1) + x
Moving across the scan line calculate the frame buffer address for the pixel
at(x+1,y) as the following offset from the address for position (x,y)
addr(x +1,y) = addr(x,y) + 1
Stepping diagonally up to the next scanline from (x,y) we get the frame buffer
address of (x+1,y+1) with the calculation
addr(x +1,y+1) = addr(x,y) + x max
where the constant x max
A procedure for specifying straight-line segments can be set up in a number of different
forms. In PHIGS, GKS, and some other packages, the two-dimensionalline function is where
parameter n is assigned an integer value equal to the number of coordinate positions to be input,
and wcpoints is the array of input world coordinate values for line segment endpoints.
This function is used to define a set of n – 1 connected straight line segments. Because
series of connected line segments occur more often than isolated line segments in graphics
applications, polyline provides a more general line function. To display a single straight-line
segment, we set n - = 2 and list the x and y values of the two endpoint coordinates.As an example
of the use of polyline, the following statements generate two connected line segments, with
endpoints at (50, 103, (150, 2501, and (250,100):
wcPoints[ll .x = SO;
wcPoints[ll .y = 100;
wcPoints[21 .x = 150;
wc~oints[2l.y = 250;
wc~oints[3l.x = 250;
wcPoints[31 .y = 100;
polyline ( 3 , wcpoints);
Coordinate references in the polyline function are stated as absolute coordinate values.
This means that the values specified are the actual point positions in the coordinate system in use.
Some systems employ line (and point) functions with relative coordinate specifications. In
this case, coordinate values are stated as offsets from the last position referenced (called the current
position).
For example, if location (3,2) is the last position that has been referenced in an application
program, a relative coordinate specification of (2, - 1) corresponds to an absolute position of (5,1).
An additional function is also available for setting the current position before the line routine is
summoned. With these packages, a user lists only the single pair of offsets in the line command.
This signals the system to display a line starting from the current position to a final position
determined by the offsets.
The current position is then updated to this final line position. A series of connected lines
is produced with such packages by a sequence of line commands, one for each line section to be
Midpoint circle algorithm:-
To simplify the function evaluation that takes place on each iteration of our circle drawing
algorithm, we can use Midpoint circle algorithm The equation of the circle can be expressed as a
function as given below
f circle
( x , y ) = x
2
+ y
2
- r
2
If the point is inside the circle then f(x,y)<0 and if it is outside then f(x,y)>0 and if the point
is in the circumference of the circle then f(x,y)=0.Thus the circle function is the decision parameter
in the midpoint algorithm.Assume that we have just plotted (xk,yk), we have to decide whether to
point
3 2
4
1
5
8
(xk+1, yk) or (xk+1, yk - 1) nearer to the circle.
Now we consider the midpoint between the points and define the decision parameter as
k
= f circle
(x k
+1, y k
𝟏
𝟐
Similarly
=( x k
2
+( y k
𝟏
𝟐
2
2 and
k+
= f circle
(x k+
+1, y k+
𝟏
𝟐
Now by subtracting the above two equations we get
k+
k
+2( x k
+1 )+( y k+
2
- y k
2
)-( y k+
- y k
where yk+1 is either yk or yk+1 depending on the sign of pk.
Algorithm
x 0
y 0
= r
position, starting at i = 0, perform the following test: if p i
< 0, the next point is
( x i
) and
p i +
= p i
If p i
≥ 0, the next point is ( x i
+1, y i
pi +1 = pi + 2 xi +1 + 1 – 2 yi +
where 2 x i +
= 2 x i
= 2 y i
Midpoint Algorithm
Properties of ellipse
Ellipse – A modified circle whose radius varies from a maximum value in one direction
(major axis) to a minimum value in the perpendicular direction (minor axis).
The sum of the two distances d 1
and d 2
, between the fixed positions F 1
and F 2
(called the
foci of the ellipse) to any point P on the ellipse, is the same value, i.e.
d 1
+ d 2
= constant
Expressing distances d 1
and d 2
in terms of the focal coordinates F 1
= ( x 1
, x 2
) and F 2
= ( x 2
y 2
),wehave:
Cartesian coordinates:
Polar coordinates:
Mid Point Ellipse Algorithm
Symmetry between quadrants
Not symmetric between the two octants of a quadrant
Thus, we must calculate pixel positions along the elliptical arc through one quadrant and
then we obtain positions in the remaining 3 quadrants by symmetry
Decision parameter: