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.
| /---/ |---|
| /---/_______|---| When rendering this shape to the
V /----------------| current scanline y, we must
/-----------------| compute the x values of the
没有合适的资源?快使用搜索试试~ 我知道了~
游戏引擎Genesis.zip
共1139个文件
h:308个
c:215个
hpp:138个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 185 浏览量
2024-04-14
19:45:00
上传
评论
收藏 6.4MB ZIP 举报
温馨提示
这个C#实现的小游戏是一个简单的猜数字游戏,让玩家猜一个1到100之间的随机生成的数字。以下是对这个小游戏的分析: Random 类的使用:游戏开始时,使用 Random 类生成一个1到100之间的随机数作为要猜的数字。 循环结构:游戏使用 while 循环,直到玩家猜对为止。玩家每次猜测后,根据猜测的数字与目标数字的大小关系,给出相应的提示,并根据猜测结果决定下一步的操作。 用户输入处理:通过 Console.ReadLine() 获取用户输入,并使用 int.TryParse() 方法将输入转换为整数。如果用户输入无效,会提示用户输入有效的数字。 游戏逻辑:根据玩家猜测的数字与目标数字的大小关系,给出相应的提示,提示玩家猜的数字是太高了还是太低了。 【引流】 Java、Python、Node.js、Spring Boot、Django、Express、MySQL、PostgreSQL、MongoDB、React、Angular、Vue、Bootstrap、Material-UI、Redis、Docker、Kubernetes
资源推荐
资源详情
资源评论
收起资源包目录
游戏引擎Genesis.zip (1139个子文件)
freetype-config.1 2KB
ChangeLog.20 89KB
ChangeLog.21 321KB
ChangeLog.22 97KB
ChangeLog.23 266KB
ChangeLog.24 202KB
ChangeLog.25 158KB
ChangeLog.26 172KB
configure.ac 28KB
INSTALL.ANY 6KB
deflinejoiner.awk 4KB
ttinterp.c 280KB
ftobjs.c 139KB
ttcmap.c 114KB
aflatin.c 108KB
ftraster.c 104KB
ttgxvar.c 99KB
cffgload.c 98KB
ttgload.c 88KB
glad.c 83KB
t1load.c 74KB
bdflib.c 71KB
aflatin2.c 71KB
cffload.c 70KB
afcjk.c 67KB
ftstroke.c 66KB
cf2hints.c 62KB
ftgrays.c 61KB
pshalgo.c 58KB
cf2intrp.c 58KB
sfobjs.c 54KB
gxvcommn.c 54KB
t1decode.c 50KB
ttload.c 49KB
psobjs.c 49KB
ttsbit.c 47KB
ttobjs.c 45KB
afblue.c 45KB
afhints.c 43KB
cffparse.c 43KB
ftmac.c 43KB
pcfread.c 40KB
t42parse.c 38KB
cffdrivr.c 37KB
cffobjs.c 36KB
winfnt.c 35KB
ftmac.c 33KB
ttsubpix.c 33KB
pshrec.c 31KB
ftrfork.c 30KB
otvgpos.c 29KB
pfrload.c 29KB
ftoutln.c 28KB
gxvkern.c 28KB
otvcommn.c 28KB
afranges.c 26KB
ftcalc.c 25KB
bdfdrivr.c 25KB
ftdbgmem.c 24KB
t1driver.c 24KB
ttdriver.c 23KB
cidload.c 23KB
pshglob.c 23KB
afloader.c 22KB
pfrgload.c 22KB
afmparse.c 22KB
cf2ft.c 22KB
pfrsbit.c 21KB
ttpload.c 21KB
gxvjust.c 21KB
ftbbox.c 21KB
ftgzip.c 21KB
t1objs.c 20KB
t42objs.c 20KB
afshaper.c 20KB
cf2blues.c 20KB
cf2font.c 20KB
ftsystem.c 20KB
ftstream.c 20KB
ftbitmap.c 19KB
pcfdrivr.c 18KB
t1gload.c 18KB
otvgsub.c 18KB
pfrobjs.c 18KB
ftglyph.c 18KB
ftcmanag.c 18KB
t1parse.c 17KB
ftcbasic.c 17KB
ftrandom.c 17KB
ttpost.c 17KB
cidobjs.c 17KB
afmodule.c 16KB
psmodule.c 16KB
cidgload.c 16KB
inftrees.c 16KB
sfdriver.c 15KB
gxvfgen.c 15KB
ftsystem.c 15KB
ftccache.c 15KB
otvmath.c 14KB
共 1139 条
- 1
- 2
- 3
- 4
- 5
- 6
- 12
资源评论
枫蜜柚子茶
- 粉丝: 8975
- 资源: 5351
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- (源码)基于ROS的PickPlace机械臂控制系统.zip
- (源码)基于树莓派(Raspberry Pi)的环境监控与警报系统.zip
- (源码)基于Spring Boot和LayUI的仓库管理系统.zip
- (源码)基于C++的通用数据处理系统.zip
- (源码)基于C语言的操作系统进程调度模拟实验.zip
- (源码)基于DSO算法的视觉里程计系统.zip
- (源码)基于C语言Unixlike操作系统框架的shell程序.zip
- (源码)基于Java Web的学生资料管理系统.zip
- (源码)基于嵌入式系统的Marble Run项目.zip
- (源码)基于Spring Boot和Vue的博客支付管理系统.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功