Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
c2e9f0c5
Commit
c2e9f0c5
authored
Jun 03, 2010
by
Nigel Tao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Opaque method to the image types.
R=rsc CC=golang-dev
https://golang.org/cl/1533041
parent
9a70762a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
102 additions
and
0 deletions
+102
-0
src/pkg/image/image.go
src/pkg/image/image.go
+96
-0
src/pkg/image/names.go
src/pkg/image/names.go
+6
-0
No files found.
src/pkg/image/image.go
View file @
c2e9f0c5
...
...
@@ -36,6 +36,23 @@ func (p *RGBA) At(x, y int) Color { return p.Pixel[y][x] }
func
(
p
*
RGBA
)
Set
(
x
,
y
int
,
c
Color
)
{
p
.
Pixel
[
y
][
x
]
=
toRGBAColor
(
c
)
.
(
RGBAColor
)
}
// Opaque scans the entire image and returns whether or not it is fully opaque.
func
(
p
*
RGBA
)
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
!=
0xff
{
return
false
}
}
}
}
return
true
}
// NewRGBA returns a new RGBA with the given width and height.
func
NewRGBA
(
w
,
h
int
)
*
RGBA
{
buf
:=
make
([]
RGBAColor
,
w
*
h
)
...
...
@@ -67,6 +84,23 @@ func (p *RGBA64) At(x, y int) Color { return p.Pixel[y][x] }
func
(
p
*
RGBA64
)
Set
(
x
,
y
int
,
c
Color
)
{
p
.
Pixel
[
y
][
x
]
=
toRGBA64Color
(
c
)
.
(
RGBA64Color
)
}
// Opaque scans the entire image and returns whether or not it is fully opaque.
func
(
p
*
RGBA64
)
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
}
// NewRGBA64 returns a new RGBA64 with the given width and height.
func
NewRGBA64
(
w
,
h
int
)
*
RGBA64
{
buf
:=
make
([]
RGBA64Color
,
w
*
h
)
...
...
@@ -98,6 +132,23 @@ func (p *NRGBA) At(x, y int) Color { return p.Pixel[y][x] }
func
(
p
*
NRGBA
)
Set
(
x
,
y
int
,
c
Color
)
{
p
.
Pixel
[
y
][
x
]
=
toNRGBAColor
(
c
)
.
(
NRGBAColor
)
}
// Opaque scans the entire image and returns whether or not it is fully opaque.
func
(
p
*
NRGBA
)
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
!=
0xff
{
return
false
}
}
}
}
return
true
}
// NewNRGBA returns a new NRGBA with the given width and height.
func
NewNRGBA
(
w
,
h
int
)
*
NRGBA
{
buf
:=
make
([]
NRGBAColor
,
w
*
h
)
...
...
@@ -129,6 +180,23 @@ func (p *NRGBA64) At(x, y int) Color { return p.Pixel[y][x] }
func
(
p
*
NRGBA64
)
Set
(
x
,
y
int
,
c
Color
)
{
p
.
Pixel
[
y
][
x
]
=
toNRGBA64Color
(
c
)
.
(
NRGBA64Color
)
}
// Opaque scans the entire image and returns whether or not it is fully opaque.
func
(
p
*
NRGBA64
)
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
}
// NewNRGBA64 returns a new NRGBA64 with the given width and height.
func
NewNRGBA64
(
w
,
h
int
)
*
NRGBA64
{
buf
:=
make
([]
NRGBA64Color
,
w
*
h
)
...
...
@@ -160,6 +228,23 @@ 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
)
}
// Opaque scans the entire image and returns whether or not it is fully opaque.
func
(
p
*
Alpha
)
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
!=
0xff
{
return
false
}
}
}
}
return
true
}
// NewAlpha returns a new Alpha with the given width and height.
func
NewAlpha
(
w
,
h
int
)
*
Alpha
{
buf
:=
make
([]
AlphaColor
,
w
*
h
)
...
...
@@ -235,6 +320,17 @@ func (p *Paletted) SetColorIndex(x, y int, index uint8) {
p
.
Pixel
[
y
][
x
]
=
index
}
// Opaque scans the entire image and returns whether or not it is fully opaque.
func
(
p
*
Paletted
)
Opaque
()
bool
{
for
_
,
c
:=
range
p
.
Palette
{
_
,
_
,
_
,
a
:=
c
.
RGBA
()
if
a
!=
0xffff
{
return
false
}
}
return
true
}
// NewPaletted returns a new Paletted with the given width, height and palette.
func
NewPaletted
(
w
,
h
int
,
m
PalettedColorModel
)
*
Paletted
{
buf
:=
make
([]
uint8
,
w
*
h
)
...
...
src/pkg/image/names.go
View file @
c2e9f0c5
...
...
@@ -48,3 +48,9 @@ func (c ColorImage) Width() int { return 1e9 }
func
(
c
ColorImage
)
Height
()
int
{
return
1e9
}
func
(
c
ColorImage
)
At
(
x
,
y
int
)
Color
{
return
c
.
C
}
// Opaque scans the entire image and returns whether or not it is fully opaque.
func
(
c
ColorImage
)
Opaque
()
bool
{
_
,
_
,
_
,
a
:=
c
.
C
.
RGBA
()
return
a
==
0xffff
}
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