Sie sind auf Seite 1von 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
size

Memory
required

Clarity of
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

CRT
Flat CRT
Plasma display
Liquid color display

Digital output devices

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

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 0 1
2^3 DAC
Electron gun

Raster CRT for RGB (8 colors)

1
0
0

DAC

blue

0
0

DAC

green

DAC

red

Buffer color combinations


RED

GREEN

BLUE

Black

Red

Green

Blue

Yellow

Cyan

Magenta

White

24 bit plane color frame buffer

0 0 0 0 1 0 1 0

RED 10

2D Graphics Pipeline

Clipping
Object
World Coordinates

Applying
world window

Object
subset

window to
viewport
mapping

Simple 2D Drawing Pipeline

Display

Rasterization

Object
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
6
5
4
3
2
1

Line: (3,2) -> (9,6)

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

Which intermediate
pixels to turn on?

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 y0
m

dx x1 x0
(x1,y1)
dy

(x0,y0)

dx

b y 0 m * x0

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)


x = x0

y k 1 y k m
(x1,y1)

y = y0

Illuminate pixel (x, round(y))


x = x0 + 1

y = y0 + 1 * m

Illuminate pixel (x, round(y))


x=x+1

y=y+1*m

Illuminate pixel (x, round(y))

(x0, y0)

Until x == x1

DDA Line Drawing Algorithm (Case b: m > 1)

x k 1

1
xk
m

x = x0
(x1,y1)

y = y0

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
X0=-8 y0=-4

m<1

Find out intermediate pixels for line with end


points (4,2) & (6,7)
M=(7-2)/(6-4)=5/2
X0=4 y0=2

m>1

Find out intermediate pixels for line with end


points (2,-3) & (-3,3)
M=6/-5
m>1
X0=2 y0=-3

Das könnte Ihnen auch gefallen