Transformation & RasterizationTransformationBasic 2D transformationsHomogeneous coordinates DefintionAffine transformationIn practiseFor 3DViewing transformationViewport transformationProject transformationPerspective transformationRasterizationResolutionBasic rasterizationAntialiasingTheoryAntialisaingFont rasterizationAntialiasing in font
Scaling
Each point (x0, y0) becomes (x1, y1) after scaling, then we define scaling matrix S(x,y):
Rotation
Suppose the rotate matrix R(θ) has:
Prove:
(1, 0) becomes (cosθ, sinθ)
(0, 1) becomes (-sinθ, cosθ)
Then, we have the definition of R
Linear transformation
Scaling and rotation are both shown as a linear form of matrix.
Translation
A translation is different from linear transformation. Now it must be two matrix for combining them:
But we want one matrix to express them together. Now we introduce a new tool: homogeneous coordinates.
To be simply, homogeneous coordinate works by adding an extra dimention to matrix, for describing higher dimention caused transformation, like projection. In other word, an n-dimention space will be described by n+1-dimention matrices.
We are discussing 2D transformation, so we express them in ternary form:
Accordingly, the transformation matrix will be 3D matrix as well:
The homogeneous transform grants us the characteristics below:
Applied homogeneous matrix, we have a transformation named "Affine transformation".
Of cource, the three transformations can be combined in one.
Affine transformation matrix for 2D transformation is useful. In UI interface for drawing element, we typically pass this matrix for apply trasformation.
In the 3D transformation matrix, the 3rd row will always be [0, 0, 1], it does not need to be told as parameter.
So the transformation matrix in 2D drawing functions will typically be like:
[A, B, C, D, Tx, Ty]
Affine transformation in 3D is just similar with 2D. Just make the transformation matrix to be 4D.
TBD
Images resolution
Display resolution
Native resolution The native resolution of display devices are determined by the fixed physical pixels. On a fixed native resolution, you could set a equivalent or lower display resolution, or display a lower resolution images. It is about scaling.
Your graphics card sends an 800×600 image to a 1366×768 LCD, the display must interpolate (scale) the image to be larger and fill the screen. In the example here, the aspect ratios (4:3 for 800×600 and 16:9 for 1366×768) are different – so not only will the image be enlarged, the image will be distorted.
Screen space
Subpixel layout
P30 Pro
Google Nexus One
What is rasterization? It is kind of a sampling.
An simple example: just imagine some colorful ink float on water, which show as a painting. Now we have a screen window, sink it under the water and slowly take it out. Then we'll have a painted screen window, which is similar to rasterization.
Bresenham's line algorithm is the most basic rasterization algorithm for drawing lines (primitive, vector) as bitmaps.
Step 1:
Step 2:
Step 3:
Step 4:
Step 5:
Now we get a rasterized figure. But it is really jaggy. It could be improved by a higher resolutions. (See MSPaint
)
Bad "Sampling":
How sampling frequency losses the original signal:
Blurr image before sampling:
Use low-pass filter to blur the filter the high frequency signals:
SSAA/MSAA (Super/Multi-Sampling Anti-Aliasing):
Use single sampling in pixel:
Use multi-sampling in pixel:
Refer to Font rasterization on Wiki.
Fonts are now vectors, then they could be scaled from extreme small to very large. Rasterization for fonts are map a vector path to a pixel matrix.
Raw rasterized font without antialiasing:
Different antialias level
Basic antialias without hint
Antialias with hint
Subpixel rendering for an RGB flat panel
For the purpose of on-screen text display, font hinting designates which primary pixels are interpolated to more clearly render a font.
-> Font editors are able to do automatic hinting.
-> High-quality commercial fonts are often manually hinted to provide the sharpest appearance.
Subpixel rendering making white
Sample
Nowadays, the most popular font rasterization library which supports both Windows and macOS is FreeType
Character 'e' in FreeType as small size with subpixel rendering.