Computer Graphics - Jaish Khan
Computer Graphics - Jaish Khan
It is the branch of science and technology concerned with methods and techniques
for
converting data to or from visual presentation using computers.
It is used in many different areas like CAD, Education and Entertainment and creating
things like GUIs, Art, Simulations/VR and Visualization.
A Graphics API is used for creating/interacting with graphics without having to deal
with low level system system stuff like window handling.
Graphics/Display Controller -> Translator between the computer and the the display.
Graphics Pipeline
The processes it takes to render graphics on the screen. It can generally be divided
into 3 parts.
1. Application Step
This stage happens entirely on the CPU and is controlled by your application.
2. Geometry Step
This is where all the objects are prepared for rendering.
3. Rasterization Step
This is where primitives (usually triangles) are converted into fragments.
At the end Fragment Shaders are used to determine the final pixel (color) that is to be
shown based on the calculations done.
Displaying Images
Display Attributes
Refresh Rate -> The redrawing of image on a screen.
It is measured in Hertz.
Higher refresh rate results in smoother motion and better for eye comfort.
Contrast Ratio -> The difference between the brightest and the darkest colors that a
display is able to produce.
It is shown using a ratio.
Higher contrast ratio results in darker blacks and brighter whites.
Response Time -> The time it takes for a monitor to change from one color to another.
It is measured in milliseconds.
Higher response time results in reduced ghosting (images leaving a trail behind).
Display Resolution -> The total amount of pixels used in the screen.
It is shown using width x height.
Higher resolution results in sharper/clearer images.
Pixel Density -> The average amount of pixels per an inch of screen.
It is measured in PPI (pixels per inch)
Higher pixel density results in sharper/clearer images.
To calculate -> √ (W idth
2 2
+ H eight )/DiagonalI nches
Types of Displays
CRT (Cathode Ray Tube)
Uses an electron gun on a phosphorus film to create images.
A focusing system and a deflection system are used to aim the light exactly where
we want.
Monochrome CRT (Black and White) -> Used a single white colored electron gun.
Color CRT (Full Color)
Beam Penetration Method -> Uses 2 color films of phosphor. Color depends
on how far the beam penerates in the layers.
Shadow Masking Method -> Uses 3 color dots of phosphor and 3 electron
guns of each color. Color depends on which gun is used.
Raster Scan
The electron beam is swept across the screen, one row at a time from top to bottom.
Each row that is scanned is called a Scan Line. These scan lines can be scanned one-
by-one in order (Progressive) or in odd-even pairs (Interlacing).
Horizontal Retrace -> When it scans an entire row it goes to the start of the next row.
Vertical Retrace -> When it scans an entire screen (all rows) it goes to the start of the
screen.
The electron beam is directed to the parts of the screen where a picture is to be
drawn.
LCD (Liquid Crystal Display) -> Uses an RGB filter with a CCFL backlight to create
images.
TN (Twisted Nematic) -> Uses liquid crystals that twist to pass light through.
Best refresh rate and response time.
IPS (In-Plane Switching) -> Uses liquid crystals that are fixed and aligned with the
glass.
Best color and viewing angle.
VA (Vertical Alignment) -> Mix of TN and IPS.
Average for everything.
Emissive Displays
They create their own light and each pixel is capable of individually switching on/off
which results in pure blacks (high contrast ratios).
LED (Light Emitting Diode) -> Uses a layer of pixels infront of an LED backlight.
OLED (Organic LED) -> Uses a layer of pixels which have their own light.
AMOLED (Active Matrix OLED)
PDP (Plasma Display) -> Uses small pockets of gas/plasma. Very expensive and not
much used.
FED (Field Emission Display) -> Uses a field of electron to target a phosphorus film to
create color. Not used these days.
They have a digitizer layer which creates an electric field, which when disturbed
catches touch inputs.
Image Formats
Raster Image Formats
Raster Image Storage -> Stored in individual points to display.
1. JPEG (Joint Photographic Experts Group) -> Lossy Format, uses an algorithm to
remove excess information that human eyes cannot see.
8 bits per channel for R, G, B each -> 24 bits total.
2. PNG (Portable Network Group) -> Lossless Format, allows for transparency.
PNG-32 -> 8 bits, 4 channels (R, G, B, A).
PNG-24 -> 8 bits, 3 channels (R, G, B).
PNG-8 -> 8 bits, single chanel.
3. GIF (Graphics Interchange Format) ->
4. TIFF (Tagged Image File Format) ->
16 bits per channel for R, G, B
2D Image Transformations
Changing the image in one way or another.
Rigid Transformation -> If a transformation preserves the points. Translation, Rotation,
Reflection but not Scale or Shear.
Translation
Moving the object from one point to another.
1 0
⎡ ⎤
0 1
⎣ ⎦
Tx Ty
Rotation
Turning the object on its axis.
cosx −sinx
[ ]
sinx cosx
Scale
Changing the size of the object.
Sx 0
[ ]
0 Sy
Shear/Skew
Translating the individual pixel of the image based on an angle.
1 Shy
[ ]
Shx 1
Reflection
Mirroring the object in one or both axes.
1. Flip horizontally.
1 0
[ ]
0 −1
2. Flip vertically.
−1 0
[ ]
0 1
3. Flip both.
−1 0
[ ]
0 −1
Color Representation
Human Vision is more suited to Brightness/Darkness compared to it being suited to
Hue(Color).
Additive Color Model -> Based on emitted light. Combining the primary colors results
in White. Used for displays.
Subtractive Color Model -> Based on absorbed light. Combining the primary colors
results in Black. Used for pigments.
Color Models
A theoretical system used to describe colors by using numbers.
Color Spaces
A practical implementation based on a color models which decides how many colors
are available for use.
Drawing Graphics
Line Drawing
Drawing even a single line on the screen is a complicated process.
points = []
if dx > dy:
start, end = sorted([x0, x1])
for x in range(start, end + 1):
y = m * x + c
points.append((x, round(y)))
else:
start, end = sorted([y0, y1])
for y in range(start, end + 1):
x = (y - c) / m
points.append((round(x), y))
But this approach is extremely slow and requires the floats and rounding numbers.
It is incremental and avoids having to round down numbers and avoids using floats.
if P0 < 0:
P0 = P0 + dy2
else:
P0 = P0 + dy2 - dx2
y = y + 1
Circle Drawing
Equation of Circle -> x
2 2
+ y
2
= r
Approach 1 -> Get every point by putting values for x in the range of [−R, R].
Approach 2 -> Use polar coordinates and then use trigonometric functions.
Both of these approaches are inefficient and we can do better using the Bresenham
Algorithm.
(The algorithm is very complicated and I have no clue how the fuck it works)
Aliasing
A problem in graphics caused when a diagonal/curved shape is drawn.
This is due to the fact that a screen is made up of square pixels. It results in the image
having jagged edges, distortion or pixelation.
Anti Aliasing
The process of smoothing out lines by using different techniques. This can usually
done by
All of these methods do impact performance a little because they all require extra
processing.