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
fc8e3d40
Commit
fc8e3d40
authored
Feb 11, 2010
by
Nigel Tao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
exp/draw test.
R=rsc CC=golang-dev
https://golang.org/cl/203062
parent
c27c3aa6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
89 additions
and
1 deletion
+89
-1
Makefile
src/pkg/Makefile
+0
-1
draw_test.go
src/pkg/exp/draw/draw_test.go
+89
-0
No files found.
src/pkg/Makefile
View file @
fc8e3d40
...
...
@@ -121,7 +121,6 @@ DIRS=\
NOTEST
=
\
debug/proc
\
exp/draw
\
go/ast
\
go/doc
\
go/token
\
...
...
src/pkg/exp/draw/draw_test.go
0 → 100644
View file @
fc8e3d40
// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
draw
import
(
"image"
"testing"
)
func
eq
(
c0
,
c1
image
.
Color
)
bool
{
r0
,
g0
,
b0
,
a0
:=
c0
.
RGBA
()
r1
,
g1
,
b1
,
a1
:=
c1
.
RGBA
()
return
r0
==
r1
&&
g0
==
g1
&&
b0
==
b1
&&
a0
==
a1
}
func
fillBlue
(
alpha
int
)
image
.
Image
{
return
image
.
ColorImage
{
image
.
RGBAColor
{
0
,
0
,
uint8
(
alpha
),
uint8
(
alpha
)}}
}
func
fillAlpha
(
alpha
int
)
image
.
Image
{
return
image
.
ColorImage
{
image
.
AlphaColor
{
uint8
(
alpha
)}}
}
func
vgradGreen
(
alpha
int
)
image
.
Image
{
m
:=
image
.
NewRGBA
(
16
,
16
)
for
y
:=
0
;
y
<
16
;
y
++
{
for
x
:=
0
;
x
<
16
;
x
++
{
m
.
Set
(
x
,
y
,
image
.
RGBAColor
{
0
,
uint8
(
y
*
alpha
/
15
),
0
,
uint8
(
alpha
)})
}
}
return
m
}
func
vgradAlpha
(
alpha
int
)
image
.
Image
{
m
:=
image
.
NewAlpha
(
16
,
16
)
for
y
:=
0
;
y
<
16
;
y
++
{
for
x
:=
0
;
x
<
16
;
x
++
{
m
.
Set
(
x
,
y
,
image
.
AlphaColor
{
uint8
(
y
*
alpha
/
15
)})
}
}
return
m
}
func
hgradRed
(
alpha
int
)
Image
{
m
:=
image
.
NewRGBA
(
16
,
16
)
for
y
:=
0
;
y
<
16
;
y
++
{
for
x
:=
0
;
x
<
16
;
x
++
{
m
.
Set
(
x
,
y
,
image
.
RGBAColor
{
uint8
(
x
*
alpha
/
15
),
0
,
0
,
uint8
(
alpha
)})
}
}
return
m
}
type
drawTest
struct
{
desc
string
src
image
.
Image
mask
image
.
Image
expected
image
.
Color
}
var
drawTests
=
[]
drawTest
{
// Uniform mask (0% opaque) mask.
drawTest
{
"nop"
,
vgradGreen
(
255
),
fillAlpha
(
0
),
image
.
RGBAColor
{
136
,
0
,
0
,
255
}},
// Uniform mask (100%, 75%, nil) and vertical-gradient source.
drawTest
{
"copy"
,
vgradGreen
(
90
),
fillAlpha
(
255
),
image
.
RGBAColor
{
0
,
48
,
0
,
90
}},
drawTest
{
"copyAlpha"
,
vgradGreen
(
90
),
fillAlpha
(
192
),
image
.
RGBAColor
{
100
,
36
,
0
,
255
}},
drawTest
{
"copyNil"
,
vgradGreen
(
90
),
nil
,
image
.
RGBAColor
{
0
,
48
,
0
,
90
}},
// Uniform mask (100%, 75%, nil) and uniform source.
drawTest
{
"fill"
,
fillBlue
(
90
),
fillAlpha
(
255
),
image
.
RGBAColor
{
0
,
0
,
90
,
90
}},
drawTest
{
"fillAlpha"
,
fillBlue
(
90
),
fillAlpha
(
192
),
image
.
RGBAColor
{
100
,
0
,
68
,
255
}},
drawTest
{
"fillNil"
,
fillBlue
(
90
),
nil
,
image
.
RGBAColor
{
0
,
0
,
90
,
90
}},
// Variable mask. In detail, at (x, y) == (8, 8):
// The destination pixel is {136, 0, 0, 255}.
// The source pixel is {0, 0, 255, 255}.
// The mask pixel's alpha is 102, or 40%.
drawTest
{
"generic"
,
fillBlue
(
255
),
vgradAlpha
(
192
),
image
.
RGBAColor
{
81
,
0
,
102
,
255
}},
}
func
TestDraw
(
t
*
testing
.
T
)
{
for
_
,
test
:=
range
drawTests
{
dst
:=
hgradRed
(
255
)
DrawMask
(
dst
,
Rect
(
0
,
0
,
16
,
16
),
test
.
src
,
ZP
,
test
.
mask
,
ZP
,
SoverD
)
if
!
eq
(
dst
.
At
(
8
,
8
),
test
.
expected
)
{
t
.
Errorf
(
"draw %s: %v versus %v"
,
test
.
desc
,
dst
.
At
(
8
,
8
),
test
.
expected
)
}
}
}
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