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
6de79ee0
Commit
6de79ee0
authored
Jun 16, 2010
by
Nigel Tao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
image: add an Alpha16 type, for completeness.
R=rsc CC=golang-dev, rog
https://golang.org/cl/1707042
parent
d60312c4
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
0 deletions
+69
-0
color.go
src/pkg/image/color.go
+21
-0
image.go
src/pkg/image/image.go
+48
-0
No files found.
src/pkg/image/color.go
View file @
6de79ee0
...
...
@@ -93,6 +93,16 @@ func (c AlphaColor) RGBA() (r, g, b, a uint32) {
return
a
,
a
,
a
,
a
}
// An Alpha16Color represents a 16-bit alpha.
type
Alpha16Color
struct
{
A
uint16
}
func
(
c
Alpha16Color
)
RGBA
()
(
r
,
g
,
b
,
a
uint32
)
{
a
=
uint32
(
c
.
A
)
return
a
,
a
,
a
,
a
}
// A ColorModel can convert foreign Colors, with a possible loss of precision,
// to a Color from its own color model.
type
ColorModel
interface
{
...
...
@@ -169,6 +179,14 @@ func toAlphaColor(c Color) Color {
return
AlphaColor
{
uint8
(
a
>>
8
)}
}
func
toAlpha16Color
(
c
Color
)
Color
{
if
_
,
ok
:=
c
.
(
Alpha16Color
);
ok
{
return
c
}
_
,
_
,
_
,
a
:=
c
.
RGBA
()
return
Alpha16Color
{
uint16
(
a
)}
}
// The ColorModel associated with RGBAColor.
var
RGBAColorModel
ColorModel
=
ColorModelFunc
(
toRGBAColor
)
...
...
@@ -183,3 +201,6 @@ var NRGBA64ColorModel ColorModel = ColorModelFunc(toNRGBA64Color)
// The ColorModel associated with AlphaColor.
var
AlphaColorModel
ColorModel
=
ColorModelFunc
(
toAlphaColor
)
// The ColorModel associated with Alpha16Color.
var
Alpha16ColorModel
ColorModel
=
ColorModelFunc
(
toAlpha16Color
)
src/pkg/image/image.go
View file @
6de79ee0
...
...
@@ -255,6 +255,54 @@ func NewAlpha(w, h int) *Alpha {
return
&
Alpha
{
pix
}
}
// An Alpha16 is an in-memory image backed by a 2-D slice of Alpha16Color values.
type
Alpha16
struct
{
// The Pixel field's indices are y first, then x, so that At(x, y) == Pixel[y][x].
Pixel
[][]
Alpha16Color
}
func
(
p
*
Alpha16
)
ColorModel
()
ColorModel
{
return
Alpha16ColorModel
}
func
(
p
*
Alpha16
)
Width
()
int
{
if
len
(
p
.
Pixel
)
==
0
{
return
0
}
return
len
(
p
.
Pixel
[
0
])
}
func
(
p
*
Alpha16
)
Height
()
int
{
return
len
(
p
.
Pixel
)
}
func
(
p
*
Alpha16
)
At
(
x
,
y
int
)
Color
{
return
p
.
Pixel
[
y
][
x
]
}
func
(
p
*
Alpha16
)
Set
(
x
,
y
int
,
c
Color
)
{
p
.
Pixel
[
y
][
x
]
=
toAlpha16Color
(
c
)
.
(
Alpha16Color
)
}
// Opaque scans the entire image and returns whether or not it is fully opaque.
func
(
p
*
Alpha16
)
Opaque
()
bool
{
h
:=
len
(
p
.
Pixel
)
if
h
>
0
{
w
:=
len
(
p
.
Pixel
[
0
])
for
y
:=
0
;
y
<
h
;
y
++
{
pix
:=
p
.
Pixel
[
y
]
for
x
:=
0
;
x
<
w
;
x
++
{
if
pix
[
x
]
.
A
!=
0xffff
{
return
false
}
}
}
}
return
true
}
// NewAlpha16 returns a new Alpha16 with the given width and height.
func
NewAlpha16
(
w
,
h
int
)
*
Alpha16
{
buf
:=
make
([]
Alpha16Color
,
w
*
h
)
pix
:=
make
([][]
Alpha16Color
,
h
)
for
y
:=
range
pix
{
pix
[
y
]
=
buf
[
w
*
y
:
w
*
(
y
+
1
)]
}
return
&
Alpha16
{
pix
}
}
// A PalettedColorModel represents a fixed palette of colors.
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