Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Unit 1

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 134

Computer Graphics & Multimedia (ETIC-428)

(UNIT 1)

Dr. Nitish Pathak


Associate Professor (IT)
Computer Graphics & Multimedia (ETCS-211) Syllabus
UNIT- I
Introduction, Applications areas, Components of Interactive
Computer Graphics System. Overview of Input devices, Output
devices, Raster scan CRT displays; random scan CRT displays. DDA
and Bresenham’s Line Drawing Algorithms, Bresenham’s and Mid-
Point Circle Drawing Algorithms. Homogeneous Coordinate System
for 2D and 3D, Various 2D, 3D Transformations (Translation,
Scaling, Rotation, Shear).

UNIT- II
Clipping Algorithms, Sutherland-Cohen line Clipping Algorithm
Bezier Curves, B-Spline Curves. Parallel Projection, Perspective
Projection, Illumination Model for diffused Reflection, Ambient light,
Specular Reflection Model, Reflection Vector.

2
Computer Graphics & Multimedia (ETCS-211)
UNIT- III
Shading Models, Flat shading, Gourard Shading, Phong Model.
Visible surface detection, Back Face Detection, Depth Buffer (Z-
Buffer, A-Buffer) Method. Overview of multimedia: Classification,
basic concepts of sound/audio MIDI: devices, messages, software,
Authoring tools, Video and Animation: controlling animation, display
and transmission of animation

UNIT -IV
Data Compression: storage space, coding requirements, Basic
compression techniques: run length code, Huffman code, Lempel-Ziv
JPEG: Image preparation, Lossy sequential DCT, expanded lossy
DCT, Lossless mode, Hierarchical mode. MPEG, Media
synchronization, Media Integration, Production Standards.

3
Computer Graphics & Multimedia (ETCS-211)

Text Books:
[T1] Donald Hearn and M.Pauline Baker, “Computer Graphics C version”,
Second Edition, Pearson Education.
[T2] Ralf Steinmetz & Klara Nahrstedt, “Multimedia Computing Communication &
Applications”, Pearson Education.
 
Reference Books:
[R1] C, Foley, VanDam, Feiner and Hughes, “Computer Graphics Principles &
practice”, 2nd Edition
[R2] R. Plastock and G. Kalley, Schaum’s Series, “Theory and Problems of
Computer Graphics”, McGraw Hill, 2nd edition.
[R3] Fred Halsall, “Multimedia Communications Applications, Networks, Protocols
& Standards”, Pearson Education.
[R4] David F. Rogers, “Procedural elements for computer graphics”, McGraw- Hill.

4
Learning objectives of Lecture-1

In this lecture, we’ll cover the following topics:


• What is Computer Graphics ?
• Why is computer graphics important?
• Types of Computer Graphics
• What are Graphics Primitives?
• Architecture of a Graphics System
• Applications of Computer Graphics
• Question Answer based on this lecture

5
What is Computer graphics ?
Images that are generated by a computer are called computer
graphics. Examples are photographs, drawings, line art, graphs,
diagrams. Graphics often combine text, illustration, and colour. In other
words we can say that
It is the creation and manipulation of graphic images by means of a
computer.
 Computer graphics started as a technique to enhance the display of
information generated by a computer.
 This ability to interpret and represent numerical data in pictures has
significantly increased the computer’s ability to present information
to the user in a clear and understandable form.
 Large amount of data are rapidly converted into bar charts, pie
charts, and graphs.

6
Typical graphics system comprises of a host
computer with support of graphical devices and fast
processor, large memory, frame buffer, display
devices (color monitors), input devices (mouse,
keyboard, joystick, touch screen, trackball etc.),
output devices (LCD panels, laser printers, color
printers. Plotters etc.) and other interfacing devices
such as, video I/O, TV interface etc.

7
Four major areas of Computer Graphics are:
(i) Display of information,
(ii) Design/Modeling,
(iii) Simulation and
(iv) User Interface.

8
Types of Computer Graphics
Two Types of Computer Graphics:
1. Interactive Graphics
2. Non-Interactive/ Passive Graphics
Interactive Computer Graphics
-It involves two way communication between computer and
user.
-User is given control over the image by providing an input
device that takes the user request to the computer.
-Example: Flight simulator used to train pilots.
Advantages: Fuel saving, safety.
Another example is video game controller.

9
2. Non-Interactive Graphics / Passive Graphics
-In this type of computer graphics, user has no
control over the images.
-Images are displayed with the help of a static stored
program and according to the instructions that are
written in the program. Example: screensavers.

10
Why is computer graphics important?
• The importance of computer graphics lies in its applications.

• Before the advent of computer graphics, designers built expensive


prototypes and time-consuming clay models. Now, designers can
interactively view and modify models of their shapes using a
computer.

• Computer graphics has also expanded the boundaries of art and


entertainment. Movies such as Jurassiac Park make extensive use
of computer graphics to create images that test the bounds of
imagination.

• Virtual reality is fast becoming an vital tool in education. Flight


simulators are used to train pilot for extreme conditions. The
development of computer graphics has made possible virtual
reality, a artificial reality that exists only inside a computer.

11
Applications of Computer Graphics
✔ Computer Aided Design (CAD)
✔Entertainment (animation, games, etc.)
✔ Computer Art
✔ Presentation Graphics
✔ Education and Training
✔ Geographic Information Systems (GIS)
✔ Visualization (Scientific Vis., Inform. Vis.)
✔ Medical Visualization
✔ Image Processing
✔ Graphical User Interfaces  

12
Typical applications areas:
• GUI’s,
• Plotting in business,
• Plotting in science and technology,
• Scientific Visualization
• Office automation
• Desktop publishing,
• Web/business/commercial publishing and advertisements,
• Simulation studies,
• Simulators
• Multimedia,
• Entertainment (movie, TV, Advt. Etc. )
• Virtual reality

13
Contd.....
• Medical imaging is another application where computer
graphics has proven valuable. Recent advances in imaging
technology such as magnetic resonance imaging allow
physicians to take 3D X-rays of the human body.
Interactive computer graphics allows the physician to
interpret this large volume of data in new and useful ways.

14
Certain compilers, such as, Visual C/C++, Visual Basic,
Borland C/C++, Borland Pascal, Turbo C, Turbo
Pascal, Gnu C/C++, Java provide their own graphical
libraries, API, support and help for programming 2-
D/3-D graphics.

15
What are Graphics Primitives?
• In graphics, primitives are basic elements, such as lines,
circle, curves, and polygons, which can be combined to
create more complex graphical images.

• In programming, primitives are the basic operations supported


by the programming language.

• A primitive is the smallest 'unit of processing' available to a


programmer of a given machine, or can be an atomic element of
an expression in a language.

16
Differences between 2D Shapes and 3D Shapes:

Based on 2D Shapes 3D Shapes


A 2D shape has two dimensions- A 3D shape has three dimensions-
Dimensions
length and breadth. length, breadth and height.

Mathematical
X-axes, Y-axes. X-axes, Y-axes and Z-axes.
Axes used
2D shapes are used to give simple 3D shapes are used to give
View
view of an object. architectural view of an object.
In 2D shapes, all the edges are In 3D shapes, some of the edges are
Edges visible
clearly visible. hidden.
2D shapes are easy to explain due to In 3D shapes, only outer dimensions
Explanation
the visibility of all its edges. can be explained.
It is easy to draw details in 2D Detailing becomes difficult in 3d
Detailing
shapes. shapes.
Circle, Square, Rectangle or any
Examples Cylinder, Prism, tube, Cuboid, etc.
other polygon, etc.

Drawing It is easy to draw 2D Shapes. 3D shapes are complex in drawing.

17
Pixel (picture element)
A pixel is the smallest piece of information in an
image.
▪ Pixels are normally arranged in a regular 2D grid, and
are often represented using dots or squares.

18
Pixel (picture element)
▪ Each pixel is a sample of an original image, where
more samples typically provide a more accurate
representation of the original.
▪ The intensity of each pixel is variable; in color
systems, each pixel has typically three or four
components such as red, green, and blue, or cyan,
magenta, yellow, and black.

19
Five elements for Computer Graphics System

20
Components of Interactive Computer Graphics System

21
Graphics Devices
• Input Devices
• Display devices
The Input Devices are the hardware that is used to transfer
input to the computer. The data can be in the form of text,
graphics, sound, and text. Output device display data from the
memory of the computer. Output can be text, numeric data,
line, polygon, and other objects.

22
These I/P Devices include:

• Keyboard
• Mouse
• Trackball
• Spaceball
• Joystick
• Light Pen
• Digitizer
• Touch Panels
• Voice Recognition
• Image Scanner

23
24
25
26
27
Display Devices

• RASTER SCAN CRT DISPLAYS


• RANDOM SCAN CRT DISPLAYS

CGM, UNIT I RASTER SCAN AND RANDOM SCAN CRT DISPLAYS. 28


• Cathode-ray tube (CRT), Vacuum tube that produces images when its
phosphorescent surface is struck by electron beams. CRTs can be
monochrome (using one electron gun) or colour (typically using three
electron guns to produce red, green, and blue images that, when
combined, render a multicolour image).

• A cathode-ray tube is a device that uses a beam of electrons in order to


produce an image on a screen. Cathode-ray tubes, also known
commonly as CRTs, are widely used in a number of electrical devices
such as computer screens, television sets, radar screens, and
oscilloscopes used for scientific and medical purposes.

• CRTs do NOT have pixels. Only fixed count displays, LCD, Plasma,


OLED have pixels. A CRT is an analog device, a vacuum tube. On a
monochrome screen there is a uniform phosphor coating and the image
is “painted” line by line on the screen.
• CRT displays have so much radiation that can cause health issues
especially in the eyes.

29
CRT- Cathode Ray Tube & How IT Works In Computer Graphics

30
31
Refresh CRT

Vertical
Focusing
deflecting
system Phosphor
plates
Base coated
screen

Electron
Electron beam
gun Horizontal
Connector
deflecting
Pins
plates

CGM, UNIT I RASTER SCAN AND RANDOM SCAN CRT DISPLAYS. 32


Difference between Raster Scan
and Random Scan systems
RASTER SCAN RANDOM SCAN

It is a point plotting device. It is a line drawing device.


It sweeps in a particular order. It draws the image in any order.
It is well suited for realistic display It is used for line drawing
of scenes containing shading and applications and cannot display
color patterns. realistic shaded scenes.
It is used for photos. That is why It is used for text, logos,
Photoshop is a raster editing letterheads.
program.
Raster Scan Displays
• The most common type of monitor employing a CRT is raster scan display.

• In Raster scan display the electron beam is swept across the screen one row
at a time from top to bottom.
•Raster: A rectangular array of points or dots
•Pixel: One dot or picture element of the raster. Its intensity range for pixels
depends on capability of the system
•Scan line: A row of pixels
•Picture elements are stored in a memory called frame buffer
•A special memory is used to store the image with scan-out synchronous to
the raster. We call this the frame buffer
Disadvantage
Raster system produces jagged lines that are plotted as discrete points

CGM, UNIT I RASTER SCAN AND RANDOM SCAN CRT DISPLAYS. 34


35
Raster Scan Displays cont..

CGM, UNIT I RASTER SCAN AND RANDOM SCAN CRT DISPLAYS. 36


Raster Scan Displays
It is the most common method of displaying images on
the CRT screen.
The electron beam sweeps across the screen, one row at
a time from top to bottom.
The image is displayed by how each pixel is intensified.
The image to be displayed is stored in the frame buffer in
the form of intensity values for each pixel.
Raster Scan Displays
Horizontal retrace: After sweeping across each row
(scan line), the electron beam returns to the left of the
screen to start displaying the next scan line or row. This
is called horizontal retrace.
Vertical retrace: the electron beam returns to the top
left corner of screen to begin the next frame when it
completes one frame. This is called vertical retrace.
Raster Scan Displays cont..
• Refresh Rate
– Usually 30~75 Hz

CGM, UNIT I RASTER SCAN AND RANDOM SCAN CRT DISPLAYS. 39


Raster Scan Displays
Raster Scan Displays
These intensity values are then retrieved from the
refresh buffer and painted on the screen one row
at a time.
In simple black and white systems, only one bit
per pixel is needed to control the intensity of
screen points.
◦ 1 indicates electron beam is turned on
◦ 0 indicates electron beam is turned off
Raster Scan Displays
For color systems there are 24 bits per pixel.
Therefore, color systems have larger sized frame
buffer (3 MB).
For black and white system frame buffer is called
bitmap and for color systems it is called pixmap.
Raster Scan Displays
Raster Scan Displays
Refresh rate: it means how many times the screen is
redrawn or refreshed in one second. Refresh rate in
the raster scan systems is between 60 to 80 Hz per
second.
Random Scan Displays
In these systems, the electron beam does not
sweep each and every row, however, it is
directed only to the parts of the screen where a
picture is to be drawn.
Also known as vector displays.
Draws one line at a time.
Parts of the picture can be displayed in any
order.
Random Scan Display cont...

46
Random scan systems
Random scan systems
In these systems, the refresh buffer does not store
the intensity values of the picture, but a set of line
drawing commands.
Refresh buffer is also called display file.
The system cycles through the set of commands in
the display file to display a picture.
Refresh rate in random scan systems is 30 to 40 times
per second.
Important Properties of
Display Devices
1. Resolution
Resolution of a display device is defined as the number of
pixels on the entire screen of the device.
For example, 1024 X 768 resolution means,
The screen has 1024 pixels in each line and
The screen has 768 horizontal lines.
2. Persistence
It is the property of phosphor that is how long they continue to
emit light.
Persistence is defined as the time it takes the emitted light to
decay to one-tenth of its original intensity.
Computer monitors have persistence of 10-60 microseconds.
Lower persistence phosphor requires higher refresh rates to
maintain a picture on the screen without flicker.
Color CRT Monitors

2 Basic
Techniques
for Color
Display

Beam
Shadow Mask
Penetration
Method
Method

51
Beam-Penetration Method
•Used with random scan monitors
•The screen has two layers of phosphor: usually red and
green
•The displayed color depends on how far the electron beam
penetrates through the two layers.
•A beam of slow electrons excites only the outer of the
red layer, a beam of fast electrons penetrates through
the red layer and excites the inner green layer, and at
intermediate beam speeds, combinations of the two
colors are emitted to show other colors (yellow &
orange)

52
Beam-Penetration Method

53
Beam-Penetration Method

54
Shadow-Mask Method cont..
•The Shadow mask is known as the delta-delta shadow-mask.
•The 3 electron beams are deflected and focused as a group onto
the shadow mask, which contains a series of holes aligned with
the phosphor-dot patterns.
•The 3 beams pass through a hole in the shadow mask and
activate a dot triangle, which appears as a small color spot on the
screen.

•A second arrangement of the 3 electron guns is in-line


Where the corresponding red-green-blue color dots on the screen
are aligned along one scan – line instead of a triangular pattern.

55
Shadow-Mask Method
– Used with raster scan monitors
– Three electron guns
– A metal shadow mask to differentiate the beams

56
Shadow-Mask Method cont..

57
58
Controlling Colors in Shadow mask
•Different colors can be obtained by varying the intensity levels
of the three electron beams.
•Example: Simply turning off the red and green guns, we get
only the color coming from the blue phosphor.

•Yellow = Green + Red


•Magenta = Blue + Red
•Cyan = Blue + Green

•White is produced when all the 3 guns possess equal amount


of intensity.

MAIT, CSE, CGM, UNIT I RASTER SCAN AND RANDOM SCAN


CRT DISPLAYS.
59
Computer Graphics & Multimedia
UNIT 1

DDA LINE DRAWING ALGORITHMS


DDA LINE DRAWING ALGORITHMS

61
DDA LINE DRAWING ALGORITHMS

62
DDA LINE DRAWING ALGORITHMS

63
DDA LINE DRAWING ALGORITHMS

64
DDA LINE DRAWING ALGORITHMS

65
Example:-
Calculate the points between the starting point (5, 6) and ending point (8,
12).
Solution-
 Given-
Starting coordinates = (X0, Y0) = (5, 6)
Ending coordinates = (Xn, Yn) = (8, 12)
 
Step-01:
 
Calculate ΔX, ΔY and M from the given input.
ΔX = Xn – X0 = 8 – 5 = 3
ΔY =Yn – Y0 = 12 – 6 = 6
M = ΔY / ΔX = 6 / 3 = 2

Step-02:
 
Calculate the number of steps.
As |ΔX| < |ΔY| = 3 < 6, so number of steps = ΔY = 6
 
CGM Lab : Experiment 2 DDA 66
Step-03:
 
As M > 1, so case-03 is satisfied.
Now, Step-03 is executed until Step-04 is satisfied.

Xp Yp Xp+1 Yp+1 Round off (Xp+1, Yp+1)

5 6 5.5 7 (6, 7)

6 8 (6, 8)

6.5 9 (7, 9)

7 10 (7, 10)

7.5 11 (8, 11)

8 12 (8, 12)

CGM Lab : Experiment 2 DDA 67


OUTPUT:-

CGM Lab MAIT : Experiment 2 DDA 68


DDA LINE DRAWING ALGORITHMS

69
DDA LINE DRAWING ALGORITHMS

70
MAIT, CSE, CGM, UNIT 1 DDA LINE DRAWING ALGORITHMS 71
Experiment – 3
Digital Differential Analyzer Algorithm
Digital differential analyzer (DDA) is used for linear interpolation of variables over an interval between given start, end points and
for rasterization of lines, triangles and polygons. Using DDA Algorithm, Write a C-Program to draw a line segment between two
given points?

Aim: To implement DDA Algorithm for drawing a line segment between two given end points A (x1, y1) and B(x2, y2).

Algorithm:
1. Start.
2. Declare variables x,y,x1,y1,x2,y2,k,dx,dy,s,xi,yi and also declare gdriver=DETECT, mode.
3. Initialize the graphic mode with the path location in TurboC3 folder.
4. Input the two line end-points and store the left end-points in (x1,y1).
5. Load (x1, y1) into the frame buffer; that is, plot the first point. put x=x1,y=y1.
6. Calculate dx=x2-x1 and dy=y2-y1.
7. If abs (dx) > abs (dy), do s=abs(dx).
8. Otherwise s= abs(dy).
9. Then xi=dx/s and yi=dy/s.
10. Start from k=0 and continuing till k<s,the points will be
i. x=x+xi.
ii.Y=y+yi.
11. Plot pixels using putpixel at points (x,y) in specified colour.
12. Close Graph and stop.

CGM Lab : Experiment 2 DDA 72


Procedure-
 
Given-
Starting coordinates = (X0, Y0)
Ending coordinates = (Xn, Yn)
 
The points generation using DDA Algorithm involves the following steps-
 

Step-01:
 
Calculate ΔX, ΔY and M from the given input.
These parameters are calculated as-
ΔX = Xn – X0
ΔY =Yn – Y0
M = ΔY / ΔX
 

CGM Lab : Experiment 2 DDA 73


Step-02:
 
Find the number of steps or points in between the starting and
ending coordinates.
 
if (absolute (ΔX) > absolute (ΔY))
Steps = absolute (ΔX);
else
Steps = absolute (ΔY);
Step-03:
 
Suppose the current point is (Xp, Yp) and the next point is (Xp+1,
Yp+1).
Find the next point by following the below three cases-

CGM Lab : Experiment 2 DDA 74


Step-04:
 
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.
 

CGM Lab : Experiment 2 DDA 75


Bresemhan's line algorithm 

76
Bresemhan's line algorithm 

77
Bresemhan's line algorithm 

78
Bresemhan's line algorithm 

79
Bresemhan's line algorithm 

80
Bresemhan's line algorithm 

81
82
83
84
Scan Conversion
Output Primitives
• Basic geometric structures used to describe scenes.
• Can be grouped into more complex structures
• Example : Point, straight line segments, circles and other conic
sections, polygon color areas and character strings
• Construct the vector picture
Rasterization
The process of determining the appropriate pixels for representing
picture or graphic object
Scan conversion
It is the final step of rasterization . It converts picture definition into a
set of pixel-intensity values for storage in the frame buffer.

CSE, CGM, UNIT 1 DDA LINE DRAWING ALGORITHMS 85


Scan Conversion cont..

Scan Converting a Point


A mathematical point (x,y) needs to be scan converted to
a pixel at location (x´, y´).

With a CRT monitor, the electron beam is turned on to


illuminate the screen phosphor at the selected location.

MAIT, CSE, CGM, UNIT 1 DDA LINE DRAWING ALGORITHMS 86


Scan Conversion cont..
Scan Converting a Line
Line drawing is accomplished by calculating intermediate positions
along the line path between two specified endpoint positions.
Cartesian equation:
y = mx + c
Where
m – slope
c – y-intercept y2
y1

x1 x2

MAIT, CSE, CGM, UNIT 1 DDA LINE DRAWING ALGORITHMS 87


The Digital Differential
Analyzer (DDA) Algorithm
• Digital Differential Analyzer
– 0 < Slope <= 1
• Unit x interval = 1
y
2
y
1

x x
1 2

MAIT, CSE, CGM, UNIT 1 DDA LINE DRAWING ALGORITHMS 88


The DDA Algorithm cont..
• Digital Differential Analyzer
– 0 < Slope <= 1
• Unit x interval = 1

– Slope > 1 y
• Unit y interval = 1 2

y
1
x x
1 2

MAIT, CSE, CGM, UNIT 1 DDA LINE DRAWING ALGORITHMS 89


The DDA Algorithm cont..
• Digital Differential Analyzer
– 0 < Slope <= 1
• Unit x interval = 1

– Slope > 1 y
• Unit y interval = 1 1
y
2
– -1 <= Slope < 0
• Unit x interval = -1 x x
1 2

MAIT, CSE, CGM, UNIT 1 DDA LINE DRAWING ALGORITHMS 90


The DDA Algorithm cont..
• Digital Differential Analyzer
– 0 < Slope <= 1
• Unit x interval = 1

– Slope > 1 y
• Unit y interval = 1 1

– -1 <= Slope < 0 y


• Unit x interval = -1 2
x x
1 2
– Slope < -1
• Unit y interval = -1

MAIT, CSE, CGM, UNIT 1 DDA LINE DRAWING ALGORITHMS 91


The DDA Algorithm cont..
DDA ALGORITHM

1. START
2. Get the values of the starting and ending co-ordinates i.e. ,(xa,ya)
and (xb,yb).
3. Find the value of slope m

m=dy/dx=((yb-ya)/(xb-xa))
4. If ImI ≤ 1 then Δx=1,Δy=mΔx

xk+1=xk+1,yk+1=yk+m
5. If ImI ≥ 1 then Δy=1,Δx=Δy/m

xk+1=xk+1/m,yk+1=yk+1
6. STOP

MAIT, CSE, CGM, UNIT 1 DDA LINE DRAWING ALGORITHMS 92


The DDA Algorithm cont..

Desired line
(xi+1,round(yi+m))

(xi,yi) (xi+1,yi+m)

(xi,round(yi))

MAIT, CSE, CGM, UNIT 1 DDA LINE DRAWING ALGORITHMS 93


DDA Pseudo-code

// assume that slope is gentle


DDA(float x0, float x1, float y0, float y1)
{ float x, y;
float xinc, yinc; int numsteps;

numsteps = Round(x1) – Round(x0);


xinc = (x1 – x0) / numsteps;
yinc = (y1 – y0) / numsteps; x = x0;
y = y0; putpixel(Round(x),Round(y));

for (int i=0; i<numsteps; i++) { x += xinc;


y += yinc; putpixel(Round(x),Round(y));
}

MAIT, CSE, CGM, UNIT 1 DDA LINE DRAWING ALGORITHMS 94


DDA Example
• Suppose we want to draw a numsteps = 12 – 2 = 10 X1-X0= 10
line starting at pixel (2,3) and xinc = 10/10 = 1.0 Y1- y0= 5
ending at pixel (12,8). yinc = 5/10 = 0.5

// assume that slope is gentle M<=1 Iteration x y Round(x) Round(y)


DDA(float x0, float x1, float y0, float 0 2 3 2 3
y1)
{ 1 3 3.5 3 4
float x, y; 2 4 4 4 4
float xinc, yinc;
3 5 4.5 5 5
int numsteps;
4 6 5 6 5
numsteps = Round(x1) – Round(x0); 5 7 5.5 7 6
xinc = (x1 – x0) / numsteps;
6 8 6 8 6
yinc = (y1 – y0) /
numsteps; x = x0; 7 9 6.5 9 7
y = y0; 8 10 7 10 7
putpixel(Round(x),Round(y));
9 11 7.5 11 8
for (int i=0; i<numsteps; i++) { 10 12 8 12 8
x += xinc;
y += yinc; MAIT, CSE, CGM, UNIT 1 DDA LINE DRAWING ALGORITHMS 95
DDA Algorithm (continued)

Y_inc

X_inc

This DDA algorithm suffers from two reasons.


 Floating point calculations and rounding operations are expensive and time
consuming.
• Due to limited precision and Rounding operations calculated points will not
be displayed at its original point.

MAIT, CSE, CGM, UNIT 1 DDA LINE DRAWING ALGORITHMS 96


Question: Draw a line from P(1,1) to Q(5,9) using DDA algorithm.

Solution:
P(1,1) => x1 = 1, y1= 1
Q(5,9) => x2 = 5, y2 = 9

Now lets calculate the difference:


dx = x2 — x1 = 5 –1 = 4
dy = y2 — y1 = 9 -1 = 8

Now lets calculate total number of points to plot:


no Of Points ToPlot = max(abs(dx), abs(dy)) = max(|4|,|8|) = 8

Now, lets discuss why we go for a max here, because we want to draw line
as accurate as possible and accuracy can be given by more no of points.

Now lets calculate increment for both the coordinates.


xInc = dx/no Of Points To Plot = 4/8 = 0.5
yInc = dy/ no Of Points ToPlot = 8/8 = 1

MAIT, CSE, CGM, UNIT 1 DDA LINE DRAWING ALGORITHMS 97


Now, list all the points to be plotted:

MAIT, CSE, CGM, UNIT 1 DDA LINE DRAWING ALGORITHMS 98


PLOT OF GRAPH

MAIT, CSE, CGM, UNIT 1 DDA LINE DRAWING ALGORITHMS 99


Questions
Q-1Write the full form of DDA?
Q-2 Why DDA is called Digital Differential Analyser?
Q-2What is the difference between DDA algorithm and
Bresenham’s Algorithm ?
Q-3. Give disadvantages of DDA algorithm?
Q-4. Give disadvantages of DDA algorithm?

MAIT, CSE, CGM, UNIT 1 DDA LINE DRAWING ALGORITHMS 100


101
102
103
104
105
106
107
108
109
110
111
112
113
Questions based on lecture-3
Q-1 Types of computer graphics are
a. Vector and raster
b. Scalar and raster
c. Vector and scalar
d. None of these
Q-2 Vector graphics is composed of
a. Pixels
b. Paths
c. Palette
d. None of these
Q-3. Raster graphics are composed of
a. Pixels
b. Paths
c. Palette
d. None of these

114
Q-4Raster images are more commonly called
a. Pix map
b. bitmap
c. both a & b
d. none of these
Q-5. Pixel can be arranged in a regular
a. One dimensional grid
b. Two dimensional grid
c. Three dimensional grid
d. None of these
Q-6. The brightness of each pixel is
a. Compatible
b. Incompatible
c. Both a & b
d. None of these
Q-7. Each pixel has ________basic color components
a. Two or three
b. One or two
c. Three or four
d. None of these

115
Architecture of a Graphics System
The components of a raster system contains display
processor, display-processor memory, frame buffer, video
controller, and input/output devices.

116
Display Processor
Purpose: frees the CPU from the graphics routine
task.
Major task: digitizes a picture definition given in an
application program into a set of pixel values for
storage in the frame buffer.
This digitization process is called scan conversion.
Straight lines and other geometric objects are scan
converted into a set of discrete points, corresponding
to screen pixel locations.

117
Display Processor
Characters can be defined with rectangular pixel grids,or
they can be defined with outline shapes. The array size
for character grids can vary from about 5x7 to 9x12 or
more for higher quality displays.

118
Display Processor
A character grid is displayed by superimposing the
rectangular grid pattern into the frame buffer at a
specified coordinate position.

For characters that are defined as outlines, the shapes are


scanned converted into the frame buffer by locating the
pixels positions closest to the outline .

119
Frame Buffer
Each screen pixel corresponds to a particular entry in a 2D
array residing in memory. This memory is called a frame
buffer or a bit map.
The number of rows in the frame buffer equals to the
number of raster lines on the display screen.
The number of columns in this array equals to the number
of pixels on each raster line.
The term pixel is also used to describe the row and
the column location in the frame buffer array that
corresponds to the screen location. A 512x512 display
screen requires 262144 pixel memory locations.

120
Frame Buffer
Whenever we wish to display a pixel on the screen,
a specific value is placed into the corresponding
memory location in the frame buffer array.
Each screen pixel’s location and corresponding
memory’s location in the frame buffer is accessed by
nonnegative integer coordinate pair (x, y).
The x value refers to the column, the y value to
the row position.

121
Frame Buffer
The origin of this coordinate system is positioned
at the bottom-left corner of the screen or it is
positioned at the upper-left corner of the screen.

122
Video controller
Video controller is used to control the operation of the
display device (Monitor/Screen). Video controller
accesses the frame buffer to refresh the screen. In figure,
the basic refresh operations of the video-controller are
shown.

123
Video controller
Two registers are used to store the coordinates of
the screen pixels.
Initially, the x register is set to 0 and the y
register is set to the value for the top scan line.
The contents of the frame buffer at this pixel
position are then retrieved and used to set the
intensity of the CRT beam.
Then the x register is incremented by 1, and the
process is repeated for the next pixel on the top
scan line.

124
Video controller
This procedure is continued for each pixel along the
top scan line.
After the last pixel on the top scan line has been
processed, the x register is reset to 0 and the y
register is set to the value for the next scan line
down from the top of the screen.
Pixels along this scan line are then processed in
turn, and the procedure is repeated for each
successive scan line.

125
Video controller
After cycling through all pixels along the bottom
scan line (y=0), the video controller resets the
registers to the first pixels position on the top scan
line and the refresh process starts over.
The screen must be refreshed at a rate of at least
60 frames per second.

126
Input and Output Devices
The user of an interactive graphics system
communicates with the graphics program by means
of input devices such as keyboard, mouse,
joystick, light pen, graphics tablet (digitizer),
touch panels, voice systems, and scanners.
Typically, the primary output device in a graphics
system is a video monitor such as Cathode Ray
Tube (CRT) and Liquid Crystal Display (LCD). We
can obtain hard-copy output for our images in
several formats for presentations or archiving. Hard
copy devices include slides film, printers, and
plotters.
127
Computer display standard
Various computer display standards or display
modes have been used in the history of the
personal computer.
They are often a combination of
Display resolution: specified as the width and
height in pixels,
Color depth: measured in bits, and
Refresh rate: expressed in hertz.

128
Computer display standard
A computer image is usually represented as a
discrete grid of pixels.
The number of pixels determines the resolution of
the image. Typical resolutions range from
320x200 to 2000x1500
The color depth: is the number of distinct colors
that can be represented by a pixel depends on the
number of bits per pixel (bpp).
A 1 bpp image uses 1 bit for each pixel, so each
pixel can be either on or off.

129
Computer display standard
Each additional bit doubles the number of colors available,
so a 2 bpp image can have 4 colors, and a 3 bpp image can
have 8 colors:
▪ 1 bpp, 21 = 2 colors (monochrome) black and white
▪ 2 bpp, 22 = 4 colors
▪ 3 bpp, 23 = 8 colors
▪...
▪ 8 bpp, 28 = 256 colors
▪ 16 bpp, 216 = 65,536 colors (Highcolor )
▪ 24 bpp, 224 ≈ 16.7 million colors (Truecolor)

130
Computer display standard
For color depths of 15 or more bits per pixel, the
depth is normally the sum of the bits allocated to
each of the red, green, and blue components(RGB).
Highcolor, usually meaning 16 bpp, normally has
five bits for red and blue, and six bits for green,
as the human eye is more sensitive to errors in
green than in the other two primary colors.

131
Computer display standard
For applications involving transparency, the 16
bits may be divided into five bits each of red,
green, and blue, with one bit left for transparency.
A 24-bit depth allows 8 bits per component.
On some systems, 32-bit depth is available: this
means that each 24-bit pixel has an extra 8 bits to
describe its opacity (for purposes of combining
with another image).

132
Q-1. Raster Graphics Are Composed Of
a) Paths
b) Palette
c) Pixels
d) None Of These
Ans-pixels

Q-2. Raster Images Are More Commonly Called


e) Pix Map
f) Bitmap
g) Both A & B
h) None Of These
Ans-bitmap
Q-7. Types Of Computer Graphics Are
Scalar And Raster
Vector And Raster
Vector And Scalar
None Of These
Ans- Vector And Raster

133
Q-4. The Brightness Of Each Pixel Is
a) Compatible
b) Incompatible
c) Both A & B
d) None Of These
Ans- Incompatible

Q-5. Each Pixel Has ________basic Color Components


a) Two Or Three
b) One Or Two
c) Three Or Four
d) None Of These
ANS- Three Or Four

134

You might also like