How FreeType's rasterizer work
by David Turner
Revised 2007-Feb-01
This file is an attempt to explain the internals of the FreeType
rasterizer. The rasterizer is of quite general purpose and could
easily be integrated into other programs.
I. Introduction
II. Rendering Technology
1. Requirements
2. Profiles and Spans
a. Sweeping the Shape
b. Decomposing Outlines into Profiles
c. The Render Pool
d. Computing Profiles Extents
e. Computing Profiles Coordinates
f. Sweeping and Sorting the Spans
I. Introduction
===============
A rasterizer is a library in charge of converting a vectorial
representation of a shape into a bitmap. The FreeType rasterizer
has been originally developed to render the glyphs found in
TrueType files, made up of segments and second-order Béziers.
Meanwhile it has been extended to render third-order Bézier curves
also. This document is an explanation of its design and
implementation.
While these explanations start from the basics, a knowledge of
common rasterization techniques is assumed.
II. Rendering Technology
========================
1. Requirements
---------------
We assume that all scaling, rotating, hinting, etc., has been
already done. The glyph is thus described by a list of points in
the device space.
- All point coordinates are in the 26.6 fixed float format. The
used orientation is:
^ y
| reference orientation
|
*----> x
0
`26.6' means that 26 bits are used for the integer part of a
value and 6 bits are used for the fractional part.
Consequently, the `distance' between two neighbouring pixels is
64 `units' (1 unit = 1/64th of a pixel).
Note that, for the rasterizer, pixel centers are located at
integer coordinates. The TrueType bytecode interpreter,
however, assumes that the lower left edge of a pixel (which is
taken to be a square with a length of 1 unit) has integer
coordinates.
^ y ^ y
| |
| (1,1) | (0.5,0.5)
+-----------+ +-----+-----+
| | | | |
| | | | |
| | | o-----+-----> x
| | | (0,0) |
| | | |
o-----------+-----> x +-----------+
(0,0) (-0.5,-0.5)
TrueType bytecode interpreter FreeType rasterizer
A pixel line in the target bitmap is called a `scanline'.
- A glyph is usually made of several contours, also called
`outlines'. A contour is simply a closed curve that delimits an
outer or inner region of the glyph. It is described by a series
of successive points of the points table.
Each point of the glyph has an associated flag that indicates
whether it is `on' or `off' the curve. Two successive `on'
points indicate a line segment joining the two points.
One `off' point amidst two `on' points indicates a second-degree
(conic) Bézier parametric arc, defined by these three points
(the `off' point being the control point, and the `on' ones the
start and end points). Similarly, a third-degree (cubic) Bézier
curve is described by four points (two `off' control points
between two `on' points).
Finally, for second-order curves only, two successive `off'
points forces the rasterizer to create, during rendering, an
`on' point amidst them, at their exact middle. This greatly
facilitates the definition of successive Bézier arcs.
The parametric form of a second-order Bézier curve is:
P(t) = (1-t)^2*P1 + 2*t*(1-t)*P2 + t^2*P3
(P1 and P3 are the end points, P2 the control point.)
The parametric form of a third-order Bézier curve is:
P(t) = (1-t)^3*P1 + 3*t*(1-t)^2*P2 + 3*t^2*(1-t)*P3 + t^3*P4
(P1 and P4 are the end points, P2 and P3 the control points.)
For both formulae, t is a real number in the range [0..1].
Note that the rasterizer does not use these formulae directly.
They exhibit, however, one very useful property of Bézier arcs:
Each point of the curve is a weighted average of the control
points.
As all weights are positive and always sum up to 1, whatever the
value of t, each arc point lies within the triangle (polygon)
defined by the arc's three (four) control points.
In the following, only second-order curves are discussed since
rasterization of third-order curves is completely identical.
Here some samples for second-order curves.
* # on curve
* off curve
__---__
#-__ _-- -_
--__ _- -
--__ # \
--__ #
-#
Two `on' points
Two `on' points and one `off' point
between them
*
# __ Two `on' points with two `off'
\ - - points between them. The point
\ / \ marked `0' is the middle of the
- 0 \ `off' points, and is a `virtual
-_ _- # on' point where the curve passes.
-- It does not appear in the point
* list.
2. Profiles and Spans
---------------------
The following is a basic explanation of the _kind_ of computations
made by the rasterizer to build a bitmap from a vector
representation. Note that the actual implementation is slightly
different, due to performance tuning and other factors.
However, the following ideas remain in the same category, and are
more convenient to understand.
a. Sweeping the Shape
The best way to fill a shape is to decompose it into a number of
simple horizontal segments, then turn them on in the target
bitmap. These segments are called `spans'.
__---__
_-- -_
_- -
- \
/ \
/ \
| \
__---__ Example: filling a shape
_----------_ with spans.
_--------------
----------------\
/-----------------\ This is typically done from the top
/ \ to the bottom of the shape, in a
| | \ movement called a `sweep'.
V
__---__
_----------_
_--------------
----------------\
/-----------------\
/-------------------\
|---------------------\
In order to draw a span, the rasterizer must compute its
coordinates, which are simply the x coordinates of the shape's
contours, taken on the y scanlines.
/---/ |---| Note that there are usually
/---/ |---| several spans per scanline.
| /
没有合适的资源?快使用搜索试试~ 我知道了~
摇钱树捕鱼源码
共1424个文件
dat:430个
h:411个
c:198个
4星 · 超过85%的资源 需积分: 50 226 下载量 88 浏览量
2013-09-05
10:06:06
上传
评论 19
收藏 4.68MB RAR 举报
温馨提示
捕鱼源码c++开发,可运行,客户端服务器都有,自己架设网狐框架就能运行
资源推荐
资源详情
资源评论
收起资源包目录
摇钱树捕鱼源码 (1424个子文件)
ChangeLog.20 92KB
ChangeLog.21 331KB
ChangeLog.22 100KB
ChangeLog.23 274KB
configure.ac 18KB
all-wcprops 6KB
all-wcprops 3KB
all-wcprops 3KB
all-wcprops 2KB
all-wcprops 2KB
all-wcprops 1KB
all-wcprops 1KB
all-wcprops 1KB
all-wcprops 1KB
all-wcprops 968B
all-wcprops 968B
all-wcprops 956B
all-wcprops 956B
all-wcprops 904B
all-wcprops 684B
all-wcprops 674B
all-wcprops 673B
all-wcprops 444B
INSTALL.ANY 6KB
deflinejoiner.awk 4KB
clean.bat 393B
GAME_LOGO.BMP 1KB
ttinterp.c 264KB
ftobjs.c 130KB
ftraster.c 119KB
ttcmap.c 108KB
cffgload.c 91KB
bdflib.c 74KB
ttgload.c 71KB
t1load.c 71KB
aflatin2.c 70KB
aflatin.c 67KB
pshalgo.c 63KB
ftgrays.c 61KB
ttgxvar.c 57KB
gxvcommn.c 56KB
ttsbit.c 54KB
ftstroke.c 54KB
t1decode.c 51KB
psobjs.c 49KB
ttload.c 48KB
cffload.c 48KB
afcjk.c 44KB
ftmac.c 44KB
sfobjs.c 39KB
ttobjs.c 39KB
t42parse.c 36KB
pcfread.c 34KB
winfnt.c 34KB
ftmac.c 33KB
pshrec.c 33KB
cffobjs.c 32KB
otvgpos.c 30KB
ftoutln.c 30KB
afhints.c 29KB
otvcommn.c 28KB
gxvkern.c 28KB
ftrfork.c 28KB
ttsbit0.c 27KB
pfrload.c 26KB
ftbbox.c 26KB
ftdbgmem.c 25KB
cffparse.c 25KB
bdfdrivr.c 24KB
ftcbasic.c 24KB
afmparse.c 23KB
pfrgload.c 23KB
cffdrivr.c 22KB
ftcalc.c 22KB
pshglob.c 22KB
t1objs.c 20KB
ttpload.c 20KB
ftstream.c 20KB
ftsystem.c 20KB
t42objs.c 19KB
ftcmanag.c 19KB
gxvjust.c 19KB
pfrsbit.c 19KB
otvgsub.c 18KB
t1gload.c 18KB
cidload.c 18KB
pfrobjs.c 18KB
ftgzip.c 18KB
ttdriver.c 18KB
afloader.c 18KB
ftglyph.c 18KB
sfdriver.c 17KB
pcfdrivr.c 17KB
ttpost.c 17KB
cidobjs.c 17KB
t1parse.c 16KB
inftrees.c 16KB
ftrandom.c 16KB
ttmtx.c 16KB
ftbitmap.c 16KB
共 1424 条
- 1
- 2
- 3
- 4
- 5
- 6
- 15
我是英雄
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页