Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小雨青年
freetype
提交
9c4da769
F
freetype
项目概览
小雨青年
/
freetype
通知
14
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
freetype
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
9c4da769
编写于
5月 19, 2010
作者:
N
Nigel Tao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Freetype-Go: gamma is now a float instead of a float64.
R=r CC=golang-dev
http://codereview.appspot.com/1236042
上级
25c38cfe
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
50 addition
and
30 deletion
+50
-30
example/freetype/main.go
example/freetype/main.go
+2
-0
example/gamma/main.go
example/gamma/main.go
+1
-1
freetype/freetype.go
freetype/freetype.go
+16
-8
freetype/raster/paint.go
freetype/raster/paint.go
+31
-21
未找到文件。
example/freetype/main.go
浏览文件 @
9c4da769
...
...
@@ -16,6 +16,7 @@ import (
var
(
dpi
=
flag
.
Int
(
"dpi"
,
72
,
"screen resolution in Dots Per Inch"
)
fontfile
=
flag
.
String
(
"fontfile"
,
"../../luxi-fonts/luxisr.ttf"
,
"filename of the ttf font"
)
gamma
=
flag
.
Float
(
"gamma"
,
1.0
,
"gamma correction"
)
size
=
flag
.
Float
(
"size"
,
12
,
"font size in points"
)
spacing
=
flag
.
Float
(
"spacing"
,
1.5
,
"line spacing (e.g. 2 means double spaced)"
)
wonb
=
flag
.
Bool
(
"whiteonblack"
,
false
,
"white text on a black background"
)
...
...
@@ -87,6 +88,7 @@ func main() {
c
.
SetDPI
(
*
dpi
)
c
.
SetFont
(
font
)
c
.
SetFontSize
(
*
size
)
c
.
SetGamma
(
*
gamma
)
// Draw the guidelines.
for
i
:=
0
;
i
<
200
;
i
++
{
...
...
example/gamma/main.go
浏览文件 @
9c4da769
...
...
@@ -53,7 +53,7 @@ func main() {
mask
:=
image
.
NewAlpha
(
50
,
50
)
painter
:=
raster
.
NewAlphaPainter
(
mask
)
painter
.
Op
=
draw
.
Src
gammas
:=
[]
float
64
{
1.0
/
10.0
,
1.0
/
3.0
,
1.0
/
2.0
,
2.0
/
3.0
,
4.0
/
5.0
,
1.0
,
5.0
/
4.0
,
3.0
/
2.0
,
2.0
,
3.0
,
10.0
}
gammas
:=
[]
float
{
1.0
/
10.0
,
1.0
/
3.0
,
1.0
/
2.0
,
2.0
/
3.0
,
4.0
/
5.0
,
1.0
,
5.0
/
4.0
,
3.0
/
2.0
,
2.0
,
3.0
,
10.0
}
for
i
,
g
:=
range
gammas
{
clear
(
mask
)
r
.
Rasterize
(
raster
.
NewGammaCorrectionPainter
(
painter
,
g
))
...
...
freetype/freetype.go
浏览文件 @
9c4da769
...
...
@@ -32,7 +32,8 @@ func Pt(x, y int) raster.Point {
// given size.
type
RGBAContext
struct
{
r
*
raster
.
Rasterizer
p
*
raster
.
RGBAPainter
rp
*
raster
.
RGBAPainter
gp
*
raster
.
GammaCorrectionPainter
font
*
truetype
.
Font
glyphBuf
*
truetype
.
GlyphBuf
fontSize
float
...
...
@@ -144,7 +145,7 @@ func (c *RGBAContext) DrawText(pt raster.Point, s string) (err os.Error) {
advance
,
x0
:=
0
,
pt
.
X
dx
:=
raster
.
Fixed
(
-
c
.
xmin
<<
8
)
dy
:=
raster
.
Fixed
(
-
c
.
ymin
<<
8
)
c
.
p
.
Dy
,
y
=
c
.
ymin
+
int
(
pt
.
Y
>>
8
),
pt
.
Y
&
0xff
c
.
r
p
.
Dy
,
y
=
c
.
ymin
+
int
(
pt
.
Y
>>
8
),
pt
.
Y
&
0xff
y
+=
dy
prev
,
hasPrev
:=
truetype
.
Index
(
0
),
false
for
_
,
ch
:=
range
s
{
...
...
@@ -169,7 +170,7 @@ func (c *RGBAContext) DrawText(pt raster.Point, s string) (err os.Error) {
x
=
x0
+
c
.
FUnitToFixed
(
advance
)
// Break the co-ordinate down into an integer pixel part and a
// sub-pixel part, making sure that the latter is non-negative.
c
.
p
.
Dx
,
x
=
c
.
xmin
+
int
(
x
>>
8
),
x
&
0xff
c
.
r
p
.
Dx
,
x
=
c
.
xmin
+
int
(
x
>>
8
),
x
&
0xff
x
+=
dx
// Draw the contours.
c
.
r
.
Clear
()
...
...
@@ -178,7 +179,7 @@ func (c *RGBAContext) DrawText(pt raster.Point, s string) (err os.Error) {
c
.
drawContour
(
c
.
glyphBuf
.
Point
[
e0
:
e
],
x
,
y
)
e0
=
e
}
c
.
r
.
Rasterize
(
c
.
p
)
c
.
r
.
Rasterize
(
c
.
g
p
)
// Advance the cursor.
advance
+=
int
(
c
.
font
.
HMetric
(
index
)
.
AdvanceWidth
)
prev
,
hasPrev
=
index
,
true
...
...
@@ -204,7 +205,7 @@ func (c *RGBAContext) recalc() {
// SetColor sets the color to draw text.
func
(
c
*
RGBAContext
)
SetColor
(
color
image
.
Color
)
{
c
.
p
.
SetColor
(
color
)
c
.
r
p
.
SetColor
(
color
)
}
// SetDPI sets the screen resolution in dots per inch.
...
...
@@ -229,20 +230,27 @@ func (c *RGBAContext) SetFontSize(fontSize float) {
c
.
recalc
()
}
// SetGamma sets the gamma correction parameter.
func
(
c
*
RGBAContext
)
SetGamma
(
g
float
)
{
c
.
gp
.
SetGamma
(
g
)
}
// SetRGBA sets the image that the RGBAContext draws onto.
func
(
c
*
RGBAContext
)
SetRGBA
(
m
*
image
.
RGBA
)
{
c
.
p
.
Image
=
m
c
.
r
p
.
Image
=
m
}
// NewRGBAContext creates a new RGBAContext.
func
NewRGBAContext
(
m
*
image
.
RGBA
)
*
RGBAContext
{
return
&
RGBAContext
{
c
:=
&
RGBAContext
{
r
:
raster
.
NewRasterizer
(
0
,
0
),
p
:
raster
.
NewRGBAPainter
(
m
),
rp
:
raster
.
NewRGBAPainter
(
m
),
glyphBuf
:
truetype
.
NewGlyphBuf
(),
fontSize
:
12
,
dpi
:
72
,
upe
:
2048
,
scale
:
(
12
*
72
*
256
*
256
)
/
(
2048
*
72
),
}
c
.
gp
=
raster
.
NewGammaCorrectionPainter
(
c
.
rp
,
1.0
)
return
c
}
freetype/raster/paint.go
浏览文件 @
9c4da769
...
...
@@ -215,46 +215,56 @@ type GammaCorrectionPainter struct {
Painter
Painter
// Precomputed alpha values for linear interpolation, with fully opaque == 1<<16-1.
a
[
256
]
uint16
// Whether gamma correction is a no-op.
gammaIsOne
bool
}
// Paint delegates to the wrapped Painter after performing gamma-correction
// on each Span.
func
(
g
*
GammaCorrectionPainter
)
Paint
(
ss
[]
Span
)
{
const
(
M
=
0x1010101
// 255*M == 1<<32-1
N
=
0x8080
// N = M>>9, and N < 1<<16-1
)
for
i
,
_
:=
range
ss
{
if
ss
[
i
]
.
A
==
0
||
ss
[
i
]
.
A
==
1
<<
32
-
1
{
continue
}
p
,
q
:=
ss
[
i
]
.
A
/
M
,
(
ss
[
i
]
.
A
%
M
)
>>
9
// The resultant alpha is a linear interpolation of g.a[p] and g.a[p+1].
a
:=
uint32
(
g
.
a
[
p
])
*
(
N
-
q
)
+
uint32
(
g
.
a
[
p
+
1
])
*
q
a
=
(
a
+
N
/
2
)
/
N
// Convert the alpha from 16-bit (which is g.a's range) to 32-bit.
a
|=
a
<<
16
// A non-final Span can't have zero alpha.
if
a
==
0
{
a
=
1
if
!
g
.
gammaIsOne
{
const
(
M
=
0x1010101
// 255*M == 1<<32-1
N
=
0x8080
// N = M>>9, and N < 1<<16-1
)
for
i
,
_
:=
range
ss
{
if
ss
[
i
]
.
A
==
0
||
ss
[
i
]
.
A
==
1
<<
32
-
1
{
continue
}
p
,
q
:=
ss
[
i
]
.
A
/
M
,
(
ss
[
i
]
.
A
%
M
)
>>
9
// The resultant alpha is a linear interpolation of g.a[p] and g.a[p+1].
a
:=
uint32
(
g
.
a
[
p
])
*
(
N
-
q
)
+
uint32
(
g
.
a
[
p
+
1
])
*
q
a
=
(
a
+
N
/
2
)
/
N
// Convert the alpha from 16-bit (which is g.a's range) to 32-bit.
a
|=
a
<<
16
// A non-final Span can't have zero alpha.
if
a
==
0
{
a
=
1
}
ss
[
i
]
.
A
=
a
}
ss
[
i
]
.
A
=
a
}
g
.
Painter
.
Paint
(
ss
)
}
// SetGamma sets the gamma value.
func
(
g
*
GammaCorrectionPainter
)
SetGamma
(
gamma
float64
)
{
func
(
g
*
GammaCorrectionPainter
)
SetGamma
(
gamma
float
)
{
if
gamma
==
1.0
{
g
.
gammaIsOne
=
true
return
}
g
.
gammaIsOne
=
false
gamma64
:=
float64
(
gamma
)
for
i
:=
0
;
i
<
256
;
i
++
{
a
:=
float64
(
i
)
/
0xff
a
=
math
.
Pow
(
a
,
gamma
)
a
=
math
.
Pow
(
a
,
gamma
64
)
g
.
a
[
i
]
=
uint16
(
0xffff
*
a
)
}
}
// NewGammaCorrectionPainter creates a new GammaCorrectionPainter that wraps
// the given Painter.
func
NewGammaCorrectionPainter
(
p
Painter
,
gamma
float
64
)
*
GammaCorrectionPainter
{
func
NewGammaCorrectionPainter
(
p
Painter
,
gamma
float
)
*
GammaCorrectionPainter
{
g
:=
&
GammaCorrectionPainter
{
Painter
:
p
}
g
.
SetGamma
(
gamma
)
return
g
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录