Вы находитесь на странице: 1из 30

Introduction to computer graphics

Computer graphics

End product is picture/image.


Creation, presentation & manipulation of pictures is CG.
Main building blocks of image is PIXEL.
Frame buffers continuous memory.
One memory bit one pixel (0 or 1)
Frame buffer bit plane
Image clarity

Mega pixel concept

Frame buffer Memory Clarity of


size required image in MP
2560 X 1920 4.91 X 10 ^ 6 5 MP
2048 X 1536 3.145 X 10 ^ 6 3.2 MP
1600 X 1200 1.92 X 10 ^ 6 2 MP
1280 X 960 1.228 X 10 ^ 6 1.3 MP
640 X 480 0.307 X 10 ^ 6 0.3 MP
Image formats

BMP (Bitmap) std window image format


GIF (graphics interchange format) designed to minimize
file size and download (electronic transfer) time
JPEG (joint photographic expert group) compress file
size by selectively discarding data, JPEG retains color
information.
TIFF (Tagged Image File Format) used to exchange files
between applications and computer platforms.
Print resolution

Measured in dots per inch (dpi)


Print resolution should be at least 150 dpi
For high quality printing the image should be 300 dpi or
greater.
Output devices

Digital output devices


CRT
Flat CRT
Plasma display
Liquid color display
Hardcopy output devices
Electrostatic plotters
Ink jet plotters
Thermal plotters
Dye sublimation printers
Pen & ink plotters
Laser printers
Physical interactive devices

Tablets
Touch panels
Joysticks
Trackball
Mouse
Light pen
Keyboard
Space ball
Vector and raster graphics

Vector graphics objects are drawn at once

Raster graphics objects are drawn each pixel at a time

Most display devices use raster graphics for displaying a


image.
Vector graphics Vs raster graphics

Whole object is drawn at once


Resized without loosing its quality
Image size is smaller than raster graphics
Used for creating logos where clarity is not lost when
scaled.

Pixel by pixel drawing


Lose quality if enlarged more than 20% of actual size.
Larger file size than vector graphics
Most image format and output devices use raster graphics
Raster CRT graphics (simple black and white)

DAC
1 Electron gun

DAC digital to analog converter


Convert digital value of pixel intensity to voltage
value (analog) of electron gun
Raster CRT for 8 intensity values (gray scale)

1
0

0 0 1

2^3 DAC

Electron gun
Raster CRT for RGB (8 colors)

1 1 DAC blue
0
0 DAC green
0 0 DAC red
Buffer color combinations

RED GREEN BLUE


Black 0 0 0
Red 1 0 0
Green 0 1 0
Blue 0 0 1
Yellow 1 1 0
Cyan 0 1 1
Magenta 1 0 1
White 1 1 1
24 bit plane color frame buffer

0 0 0 0 1 0 1 0

RED 10
2D Graphics Pipeline

Clipping
Object window to
Object Applying
subset viewport
World Coordinates world window
mapping

Simple 2D Drawing Pipeline

Object
Display Rasterization
Screen coordinates
Rasterization Operations

Drawing lines on the screen


Manipulating pixel maps (pixmaps): copying, scaling,
rotating, etc
Compositing images, defining and modifying regions
Drawing and filling polygons
Previously glBegin(GL_POLYGON), etc
Aliasing and antialiasing methods
Line drawing algorithm
Programmer specifies (x,y) values of end pixels
Need algorithm to figure out which intermediate pixels
are on line path
Pixel (x,y) values constrained to integer values
Actual computed intermediate line values may be floats
Rounding may be required. E.g. computed point
(10.48, 20.51) rounded to (10, 21)
Rounded pixel value is off actual line path (jaggy!!)
Sloped lines end up having jaggies
Vertical, horizontal lines, no jaggies
Image with jaggy effect
Line Drawing Algorithm

8
7 Line: (3,2) -> (9,6)
6
5
4
? Which intermediate
pixels to turn on?
3
2
1

0 1 2 3 4 5 6 7 8 9 10 11 12
Line drawing algorithms

DDA digital differential analyzer

Bresenhams line drawing algorithm


DDA Line Drawing Algorithm

Slope-intercept line equation


y = mx + b
Given two end points (x0,y0), (x1, y1), how to compute m
and b?
dy y1 y 0 b y 0 m * x0
m
dx x1 x0

(x1,y1)
dy

(x0,y0)
dx
DDA Line Drawing Algorithm

Numerical example of finding slope m:


(Ax, Ay) = (23, 41), (Bx, By) = (125, 96)

By Ay 96 41 55
m 0.5392
Bx Ax 125 23 102
Digital Differential Analyzer (DDA): Line Drawing
Algorithm

Walk through the line, starting at (x0,y0)


Constrain x, y increments to values in [0,1] range
Case a: x is incrementing faster (m < =1)
Step in x=1 increments, compute and round y
Case b: y is incrementing faster (m > 1)
Step in y=1 increments, compute and round x

(x1,y1)
dy

(x0,y0)
dx
DDA Line Drawing Algorithm (Case a: m < = 1)

y k 1 y k m x = x0 y = y0

Illuminate pixel (x, round(y))


(x1,y1)
x = x0 + 1 y = y0 + 1 * m

Illuminate pixel (x, round(y))

x=x+1 y=y+1*m

Illuminate pixel (x, round(y))

Until x == x1
(x0, y0)
DDA Line Drawing Algorithm (Case b: m > 1)

1 x = x0 y = y0
x k 1 xk (x1,y1)
m Illuminate pixel (round(x), y)

y = y0 + 1 x = x0 + 1 * 1/m

Illuminate pixel (round(x), y)

y=y+1 x = x + 1 /m

Illuminate pixel (round(x), y)

(x0,y0) Until y == y1
DDA Line Drawing Algorithm Pseudocode

compute m;
if m <= 1:
{
float y = y0; // initial value
//x0 is smallest value between xo and x1
for(int x = x0;x <= x1; x++, y += m)
setPixel(x, round(y));
}
else // m > 1
{
float x = x0; // initial value
//y0 is smallest value between yo and y1
for(int y = y0;y <= y1; y++, x += 1/m)
setPixel(round(x), y);
}
Note: setPixel(x, y) writes current color into pixel in column x and
row y in frame buffer
Line Drawing Algorithm Drawbacks

DDA is the simplest line drawing algorithm


Not very efficient
Round operation is expensive
Find out intermediate pixels for line with end
points (-8,-4) & (0,0)

M=-4/-8=0.5 m<1
X0=-8 y0=-4
Find out intermediate pixels for line with end
points (4,2) & (6,7)

M=(7-2)/(6-4)=5/2 m>1
X0=4 y0=2
Find out intermediate pixels for line with end
points (2,-3) & (-3,3)

M=6/-5 m>1
X0=2 y0=-3

Вам также может понравиться