Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
a3372bd6
Commit
a3372bd6
authored
Feb 02, 2010
by
Nigel Tao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New image.A type, to represent anti-aliased font glyphs.
R=r, rsc CC=golang-dev
https://golang.org/cl/199052
parent
d00210f5
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
0 deletions
+53
-0
color.go
src/pkg/image/color.go
+23
-0
image.go
src/pkg/image/image.go
+30
-0
No files found.
src/pkg/image/color.go
View file @
a3372bd6
...
@@ -100,6 +100,18 @@ func (c NRGBA64Color) RGBA() (r, g, b, a uint32) {
...
@@ -100,6 +100,18 @@ func (c NRGBA64Color) RGBA() (r, g, b, a uint32) {
return
return
}
}
// An AlphaColor represents an 8-bit alpha.
type
AlphaColor
struct
{
A
uint8
}
func
(
c
AlphaColor
)
RGBA
()
(
r
,
g
,
b
,
a
uint32
)
{
a
=
uint32
(
c
.
A
)
a
|=
a
<<
8
a
|=
a
<<
16
return
a
,
a
,
a
,
a
}
// A ColorModel can convert foreign Colors, with a possible loss of precision, to a Color
// A ColorModel can convert foreign Colors, with a possible loss of precision, to a Color
// from its own color model.
// from its own color model.
type
ColorModel
interface
{
type
ColorModel
interface
{
...
@@ -176,6 +188,14 @@ func toNRGBA64Color(c Color) Color {
...
@@ -176,6 +188,14 @@ func toNRGBA64Color(c Color) Color {
return
NRGBA64Color
{
uint16
(
r
),
uint16
(
g
),
uint16
(
b
),
uint16
(
a
)}
return
NRGBA64Color
{
uint16
(
r
),
uint16
(
g
),
uint16
(
b
),
uint16
(
a
)}
}
}
func
toAlphaColor
(
c
Color
)
Color
{
if
_
,
ok
:=
c
.
(
AlphaColor
);
ok
{
// no-op conversion
return
c
}
_
,
_
,
_
,
a
:=
c
.
RGBA
()
return
AlphaColor
{
uint8
(
a
>>
24
)}
}
// The ColorModel associated with RGBAColor.
// The ColorModel associated with RGBAColor.
var
RGBAColorModel
ColorModel
=
ColorModelFunc
(
toRGBAColor
)
var
RGBAColorModel
ColorModel
=
ColorModelFunc
(
toRGBAColor
)
...
@@ -187,3 +207,6 @@ var NRGBAColorModel ColorModel = ColorModelFunc(toNRGBAColor)
...
@@ -187,3 +207,6 @@ var NRGBAColorModel ColorModel = ColorModelFunc(toNRGBAColor)
// The ColorModel associated with NRGBA64Color.
// The ColorModel associated with NRGBA64Color.
var
NRGBA64ColorModel
ColorModel
=
ColorModelFunc
(
toNRGBA64Color
)
var
NRGBA64ColorModel
ColorModel
=
ColorModelFunc
(
toNRGBA64Color
)
// The ColorModel associated with AlphaColor.
var
AlphaColorModel
ColorModel
=
ColorModelFunc
(
toAlphaColor
)
src/pkg/image/image.go
View file @
a3372bd6
...
@@ -135,6 +135,36 @@ func NewNRGBA64(w, h int) *NRGBA64 {
...
@@ -135,6 +135,36 @@ func NewNRGBA64(w, h int) *NRGBA64 {
return
&
NRGBA64
{
pixel
}
return
&
NRGBA64
{
pixel
}
}
}
// An Alpha is an in-memory image backed by a 2-D slice of AlphaColor values.
type
Alpha
struct
{
// The Pixel field's indices are y first, then x, so that At(x, y) == Pixel[y][x].
Pixel
[][]
AlphaColor
}
func
(
p
*
Alpha
)
ColorModel
()
ColorModel
{
return
AlphaColorModel
}
func
(
p
*
Alpha
)
Width
()
int
{
if
len
(
p
.
Pixel
)
==
0
{
return
0
}
return
len
(
p
.
Pixel
[
0
])
}
func
(
p
*
Alpha
)
Height
()
int
{
return
len
(
p
.
Pixel
)
}
func
(
p
*
Alpha
)
At
(
x
,
y
int
)
Color
{
return
p
.
Pixel
[
y
][
x
]
}
func
(
p
*
Alpha
)
Set
(
x
,
y
int
,
c
Color
)
{
p
.
Pixel
[
y
][
x
]
=
toAlphaColor
(
c
)
.
(
AlphaColor
)
}
// NewAlpha returns a new Alpha with the given width and height.
func
NewAlpha
(
w
,
h
int
)
*
Alpha
{
pixel
:=
make
([][]
AlphaColor
,
h
)
for
y
:=
0
;
y
<
h
;
y
++
{
pixel
[
y
]
=
make
([]
AlphaColor
,
w
)
}
return
&
Alpha
{
pixel
}
}
// A PalettedColorModel represents a fixed palette of colors.
// A PalettedColorModel represents a fixed palette of colors.
type
PalettedColorModel
[]
Color
type
PalettedColorModel
[]
Color
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment