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

COMPUTER GRAPHICS

3/5/17
Koushik Dutta
Department of Computer Science
Asutosh College, Kolkata
koushik.it.22@gmail.com
1
DISPLAY HARDWARE

Video Display Devices


Cathode Ray Tube (CRT)

3/5/17

Liquid Crystal Display (LCD)
Plasma panels
Thin-film electroluminescent display
Light-emitting diodes (LED)

Hard-Copy Devices
Ink-jet printer
Laser printer
Film recorder
Electrostatic printer
Pen plotter 2
CATHODE RAY TUBE (CRT)
The primary output device in a graphical system is the
video monitor. The main element of a video monitor is the

3/5/17
Cathode Ray Tube (CRT), shown in the following
illustration.
The operation of CRT is very simple:

1. The electron gun emits a beam of electrons (cathode rays).

2. The electron beam passes through focusing and deflection


systems that direct it towards specified positions on the
phosphor-coated screen.

3. When the beam hits the screen, the phosphor emits a small
spot of light at each position contacted by the electron beam.
3
4. It redraws the picture by directing the electron beam back
over the same screen points quickly.
CATHODE RAY TUBE (CRT)

3/5/17
4
LIQUID CRYSTAL DISPLAY (LCD)

3/5/17
5
LIGHT-EMITTING DIODE (LED)

3/5/17
6
RASTER GRAPHICS

3/5/17
7
FRAME BUFFER

3/5/17
8
FRAME BUFFER REFRESH

Refresh Rate

3/5/17
Usually 30~75 Hz

9
COLOR FRAME BUFFER

3/5/17
255 150 75 0
255 255
150 150
75 75
0 0
255 255
150 150
75 750 0
255 150 75 0
255 255
150 150
75 750 0
255 150 75 0
255 255
150 150
75 750 0
255 150 75 0
255 255
150 150
75 750 0 Blue channel
Green channel
255 150 75 0
Red channel
10
COLOR CRT

3/5/17
11
RASTER SCAN DISPLAY
CRT provide the raster-scan display, based on television
technology.

The electron beam is swept across the screen, one row at a time

3/5/17
from top to bottom. As the electron beam moves across each row,
the beam intensity is turned on and off to create a pattern of
illuminated spots.

Picture definition is stored in a memory area called the refresh


buffer or frame buffer.

Each screen point is referred to as a pixel or pel (shortened


forms of picture element).

Refreshing on raster-scan displays is carried out at the rate of


60 to 80 frames per second, although some systems are designed
for higher refresh rates. Sometimes, refresh rates are described
12
in units of cycles per second, or Hertz(Hz), where a cycle
corresponds to one frame.
3/5/17
13
RANDOM SCAN(VECTOR SCAN)
DISPLAY
Here CRT has the electron beam directed only to the parts of
the screen where a picture is to be drawn.

3/5/17
Random scan monitors draw a picture one line at a time and
for this reason are also referred to as vector displays.

The component lines of a picture can be drawn and refreshed


by a random-scan system in any specified order.

Refresh rate on a random-scan system depends on the


number of lines to be displayed.

Random-scan displays are designed to draw all the


component lines of a picture 30 to 60 times each second. High
quality vector systems are capable of handling approximately
14
100,000 "short" lines at this refresh rate.
RANDOM SCAN DISPLAY

Picture definition is now stored as a set of line drawing

3/5/17
commands in an area of memory referred to as the refresh
display file. Sometimes the refresh display file is called the
display list, display program, or simply the refresh buffer.

15
3/5/17
16
OUTPUT PRIMITIVES

Points

3/5/17
Lines
DDA Algorithm
Bresenhams Algorithm
Polygons
Scan-Line Polygon Fill
Inside-Outside Tests
Boundary-Fill Algorithm
Antialiasing

17
POINTS

Single Coordinate Position

3/5/17
Set the bit value(color code) corresponding to a specified
screen position within the frame buffer

y
setPixel (x, y)

x
18
Q:From
Whata is
geometry
a pixel? point of view,
A square or aapoint?
pixel is a point. Q: Where is (2,1)?

WHAT IS A PIXEL
3

3/5/17
2

19

0 1 2 3 4 5
But when we think about images, a pixel is a rectangle.
Q: Where is (2,1)? A. The center of a pixel

3/5/17
2

0
20

0 1 2 3 4
LINES

Intermediate Positions between Two Endpoints

3/5/17
DDA, Bresenhams line algorithms

Jaggies
= Aliasing

21
DRAW A LINE FROM 0,0 TO 4,2
How do we choose between 1,0 and 1,1? What would be a good heuristic?

3/5/17
(4,2)
2

(0,0)

0 22

0 1 2 3 4
LETS DRAW A TRIANGLE
(0,2) (4,2)

3/5/17
2

(2,0)
0 23

0 1 2 3 4
THE IDEAL LINE

(17,8)
What do we want?

3/5/17
Continuous
appearance
Uniform thickness
and brightness
Pixels near the ideal
line are on
Speed (2,2)

Discretization - converting a continuous signal


into discrete elements.
Scan Conversion - converting vertex/edges 24
information into pixel data for display
SLOPE-INTERCEPT METHOD

The cartesian slope-intercept equation for straight line is


y m.x b

3/5/17
where m represent the slope of the line, b as y intercept. Given in
the two line segment (x1, y1) and (x2, y2) and m, b is calculated

y 2 y1
m
x2 x1

b y1 mx1

y m.x
25
SLOPE-INTERCEPT METHOD
y
m
x

3/5/17
m 1 thenx can be set proportional to small horizontal
deflection voltage and the corresponding vertical deflection is
then set proportional to y

m 1 y
then can be set proportional to small
vertical deflection voltage and the corresponding horizontal
deflection is then set proportional to x

m 1 then y x , the horizontal and vertical


deflections voltages are equal. 26
Example 1:
Point1 V:(2,2) C:(255,102,0) Point2 V:(17,8) C:(255,102,0) What if colors
were different?
On raster systems, lines are plotted with pixels, and step sizes in the
horizontal and vertical directions are constrained by pixel separations.
That is, we must "sample" a line at discrete positions and determine the

3/5/17
nearest pixel to the line at each sampled.

(0,9)
(17,8)

(2,2)
27
(0,0) (18,0)
DDA ALGORITHM

Digital Differential Analyzer

3/5/17
0 < Slope <= 1
Unit x interval = 1

y2
y1

x1 x2

yk 1 yk m
28
DDA ALGORITHM

Digital Differential Analyzer

3/5/17
0 < Slope <= 1
Unit x interval = 1

Slope > 1 y2
Unit y interval = 1

y1
x1 x2
1
xk 1 xk
m 29
DDA ALGORITHM

Digital Differential Analyzer

3/5/17
0 < Slope <= 1
Unit x interval = 1

Slope > 1 y1
Unit y interval = 1
y2
-1 <= Slope < 0
Unit x interval = -1
x1 x2

yk 1 yk m
30
DDA ALGORITHM

Digital Differential Analyzer

3/5/17
Slope >= 1
Unit x interval = 1

0 < Slope < 1 y2


Unit y interval = 1

-1 <= Slope < 0 y1


Unit x interval = -1
x1 x2
Slope < -1 1
Unit y interval = -1 xk 1 xk
m 31
DDA ALGORITHM
Void lineDDA (int x0, int y0, int x1, int y1)
{

3/5/17
int dx = x1 x0, dy = y1 y0, steps, k;
float xrncrement, yIncrement, x = x0, y = y0;

i f (abs (dx) > abs (dy))


steps = abs (dx) ;
else
steps = abs dy);

xIncrement = dx / (float) steps;


yIncrement = dy / (float) steps;

setpixel (ROUND(x), ROUND(y) );


for (k=O; k<steps; k++) {
x += xIncrment;
y += yIncrement;
32
setpixel (ROUND(x), ROVND(y));
}
}
PROS AND CONS:
Pros:

1. It is the simplest algorithm and it does not require special

3/5/17
skills for implementation.
2. It is a faster method for calculating pixel positions than the
direct use of equation y = mx + b. It eliminates the
multiplication in the equation by making use of raster
characteristics, so that appropriate increments are applied in
the x or v direction to find the pixel positions along the line
path.

Cons:

1. Floating point arithmetic in DDA algorithm is still time-


consuming.
2. The algorithm is orientation dependent. Hence end point 33
accuracy is poor.
BRESENHAMS LINE ALGORITHM
The Bresenham algorithm is another incremental scan
conversion algorithm. The big advantage of this algorithm is
that, it uses only integer calculations. Moving across the x axis

3/5/17
in unit intervals and at each step choose between two different
y coordinates.

Accurate and Efficient


Use only incremental integer calculations
Test the sign of an integer parameter

Case) Positive Slope Less Than 1


After the pixel (xk, yk) is displayed,
yk+1
next which pixel is decided to plot
in column xk+1?
yk
34
xk xk+1
(xk+1, yk) or (xk+1, yk+1)
BRESENHAMS ALGORITHM(CONT.)

Case) Positive Slope Less Than 1

3/5/17
y at sampling position xk
y m xk 1 b
Difference
d1 y yk m xk 1 b yk yk+1 d2
d 2 yk 1 y yk 1 m xk 1 b d1
d1 d2 < 0 (xk+1, yk)
yk
d1 d2 > 0 (xk+1, yk+1) xk xk+1
Decision
d1 d 2
pk xparameter
2y xk 2x yk 2y x 2b 1 35
2y xk 2x yk c
BRESENHAMS ALGORITHM(CONT.)

Case) Positive Slope Less Than 1

3/5/17
Decision parameter
pk 1 pk 2y xk 1 2x yk 1 c 2y xk 2x yk c
2y xk 1 xk 2x yk 1 yk
xk 1 xk 1 pk 1 pk 2y 2x yk 1 yk
Where, yk+1 yk is either 0 or 1 depending on the sign of pk.
Decision parameter of a starting pixel (x0, y0)
p0 2y x0 2x y0 2y x 2b 1
2y x0 2x mx0 b 2y x 2b 1
2y x0 2y x0 2bx 2y 2bx x 36

p0 2y x
BRESENHAMS ALGORITHM(CONT.)

Algorithm for 0<m<1

3/5/17
Step 1: Input the two line endpoints and store the left end point in (x0,
y0 )
Step 2: Load (x0, y0) into the frame buffer; that is, plot the first point
Step 3: Calculate constants x, y, 2y, and 2y 2x, and obtain the
starting value for the decision parameter as

p0 2y x
Step 4: At each xk along the line, start at k =0, perform the following
test:
If pk < 0, the next point to plot is (xk+1, yk) and
pk 1 pk 2y
Otherwise, the next point to plot is (xk+1, yk+1) and
pk 1 pk 2y 2x
37
Repeat the step 4 in x times
FRAME BUFFER ADDRESS
CALCULATION

3/5/17
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 (xmax, ymax) at the top right corner (Fig. ). For a
bilevel system (1 bit per pixel), the frame-buffer bit address
for pixel position (x, y) is calculated as
38
addr ( x, y ) addr (0,0) y ( xmax 1) x
FRAME BUFFER ADDRESS
CALCULATION
Moving across a scan line, we can calculate the frame-buffer
address for the pixel at (x + 1, y) as the following offset from

3/5/17
the address for position (x, y):

addr ( x 1, y ) addr ( x, y ) 1

Stepping diagonally up to the next scan line from (x, y), we


get to the frame buffer address of (x + 1, y + 1) with the
calculation

addr ( x 1, y 1) addr ( x, y ) xmax 2

39
CIRCLE GENERATING ALGORITHM
Drawing a circle on the screen is a little complex than drawing
a line. There are two popular algorithms for generating a circle:

3/5/17
Bresenhams Algorithm and Midpoint Circle Algorithm.
These algorithms are based on the idea of determining the
subsequent points required to draw the circle.

A circle is defined as the set of


points that are all at a given
distance r from a centre position
(Xc,Yc). This distance relationship
Yc
is expressed by the Pythagorean
theorem in Cartesian coordinates
as
Xc 40
( x xc ) 2 ( y yc ) 2 r 2
CIRCLE GENERATING ALGORITHM(CONTD..)
We can calculate the position of points on a circle circumference
by stepping along the x axis in unit steps from x c - r to xc + r and
calculating the corresponding y values at each position as

3/5/17
y yc r 2 ( xc x) 2

But this is not the best method for


generating a circle. One problem
with this approach is that it involves
considerable computation at each
step. Moreover, the spacing between xc - r xc + r
plotted pixel positions is not uniform,
as demonstrated in Fig.
We could adjust the spacing by interchanging x and y (stepping
through y values and calculating x values) whenever the
absolute value of the slope of the circle is greater than 1. But 41
this simply increases the computation and processing required
by the algorithm.
CIRCLE GENERATING ALGORITHM(CONTD..)

Another way to unequal spacing by expressing the circle


equation in parametric polar form yields the pair of equations

3/5/17
x xc r cos y yc r sin

A display is generated with these equations using a fixed


angular step size, a circle is plotted with equally spaced points
along the circumference. The step size chosen for depends on
the application and the display device.

On the basis of symmetry, we can


generate all the pixel position
around a circle by calculating
only the points within the sector
From x=0 to x=y.
42
CIRCLE GENERATING ALGORITHM(CONTD..)

In case of polar form, larger angular separation along the


circumference can be connected with straight line segments to

3/5/17
approximate the circular path.

Determining pixel positions along a circle circumference using


either any previous equation, still requires a good deal of
computation time.

The Cartesian equation involves multiplications and square


root calculations, while the parametric equations contain
multiplications and trigonometric calculations.

More efficient circle algorithms are based on incremental


calculation of decision-parameters, as in the Bresenham line
algorithm, which involves only simple integer operations,
43
MIDPOINT CIRCLE ALGORITHM

A method for direct distance comparison is to test the halfway


position between two pixels to determine if this midpoint is

3/5/17
inside or outside the circle boundary.

The midpoint approach generates the same pixel positions as


the Bresenham circle algorithm.

To apply the midpoint method, we define a circle function:


f circle ( x, y ) x 2 y 2 r 2

0, if (x,y) is inside the circle boundary


if (x,y) is on the circle boundary
f circle ( x, y ) 0,
0, if (x,y) is outside the circle boundary
44
The relative position of any point (x. y) can be determined by
checking the sign of the circle function
MIDPOINT CIRCLE
ALGORITHM(CONTD..)
The circle-function tests in 3-28 are
performed for the mid-positions

3/5/17
between pixels near the circle path x2+y2-r2=0
at each sampling step. yk
Here, 0<Slope<-1 yk -1 midpoint
After the pixel (xk, yk) is displayed,
next which pixel is decided to plot in
column xk+1? xk xk+1 xk+2
(xk+1, yk) or (xk+1, yk-1)

Decision parameter is the circle function evaluated at the


midpoint between these two pixels
1
Pk f circle ( xk 1, yk )
2
1 2 45
( xk 1) ( yk ) r 2
2

2
MIDPOINT CIRCLE
ALGORITHM(CONTD..)
Successive decision parameters are obtained using
incremental calculations. We obtain a recursive expression
for the next decision parameter by evaluating the circle

3/5/17
function at sampling xk 1 1 xk 2

1
Pk 1 f circle ( xk 1 1, yk 1 )
2
1
[( xk 1) 1]2 ( yk 1 ) 2 r 2
2
Or
pk 1 pk 2( xk 1) ( yk21 yk2 ) ( yk 1 yk ) 1

Where yk 1 is either y k or yk 1 , depending on the sign of pk

46
MIDPOINT CIRCLE
ALGORITHM(CONTD..)

As per previous equation, increments for obtaining pk 1 are either


2 xk 1 1 or 2 xk 1 1 2 yk 1 . Evaluation of terms 2 xk 1 and 2 yk 1 can

3/5/17
also be done incrementally
2x 2x 2 2 yk 1 2 yk 2
k 1 k

The initial decision parameter is obtained by evaluating the circle


function at the start position ( x0 , y0 ) (0, r )
1
p0 f circle (1, r )
2
1 2
1 (r ) r 2
2
Or 5
p0 r
4
If the radius r is specified as an integer, we can simply round p o to
47
p0 1 r
MIDPOINT CIRCLE
ALGORITHM(CONTD..)
1. Input radius r and circle center (xc, yc), and obtain the first point on
the circumference of a circle centered on the origin as

3/5/17
( x0 , y0 ) (0, r )
2. Calculate the initial value of the decision parameter as
5
p0 r
4
3. At each xk position, starting at k=0, perform the following test: If
pk<0, the next point along the circle centered on (0,0) is (xk+1, yk)
and pk 1 pk 2 xk 1 1

otherwise, the next point along the circle is (xk+1, yk-1) and
pk 1 pk 2 xk 1 1 2 yk 1

where 2xk+1 = 2xk+2 and 2yk+1 = 2yk-2


4. Determine symmetry points in the other seven octants.
5. Move each calculated pixel position (x,y) onto the circular path
48
centered on (xc, yc) xand
x plot
x the coordinates
y y yc values:
c

6. Repeat the steps 3 through 5 until x>=y


POLYGONS
For filling polygons with particular colors, you need to determine the
pixels falling on the border of the polygon and those which fall inside the
polygon.
Filling Polygons

3/5/17
Scan-line fill
algorithm
Inside-Outside tests

Boundary fill
algorithm
11
1 2 3 4 5 6 7 8 9 10 5 6 7 8 9
4 3 1 2

49
SCAN-LINE POLYGON FILL

Topological Difference between 2 Scan lines

3/5/17
y : intersection edges are opposite sides
y : intersection edges are same side

y 1 2
2
y 1 1

50
INSIDE-OUTSIDE TESTS
Area-filling algorithms and other graphics processes often need
to identify interior regions of objects

3/5/17
Self-Intersections
Odd-Even rule

exterior
Nonzerowinding
number rule
interior

51
BOUNDARY-FILL ALGORITHM
Proceed to Neighboring Pixels

3/5/17
4-Connected
8-Connected

52
ANTIALIASING

Aliasing

3/5/17
Undersampling: Low-frequency sampling

original

sample

reconstruct

f s 2 f max
Nyquist sampling frequency: xcycle
Nyquist sampling interval:
x s
2 53
ANTIALIASING (CONT.)

Supersampling (Postfiltering)

3/5/17
Pixel-weighting masks
Area Sampling (Prefiltering)
Pixel Phasing
Shift the display location of pixel areas
Micropositioning the electron beam in relation to
object geometry

54
SUPERSAMPLING

Subpixels

3/5/17
Increase resolution

22
(10, 20): Maximum Intensity
21
(11, 21): Next Highest Intensity
(11, 20): Lowest Intensity
20

10 11 12
55
SUPERSAMPLING

Subpixels

3/5/17
Increase resolution

22
(10, 20): Maximum Intensity
21
(11, 21): Next Highest Intensity
(11, 20): Lowest Intensity
20

10 11 12
56
PIXEL-WEIGHTING MASKS

Give More Weight to Subpixels Near the

3/5/17
Center of a Pixel Area

1 2 1
2 4 2
1 2 1

57
AREA SAMPLING

Set Each Pixel Intensity Proportional to the

3/5/17
Area of Overlap of Pixel
2 adjacent vertical (or horizontal) screen grid lines
trapezoid

22

(10, 20): 90%


21
(10, 21): 15%

20
58
10 11 12
3/5/17
59

You might also like