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
e974fb94
Commit
e974fb94
authored
May 23, 2010
by
Nigel Tao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
When making images, allocate one big buffer instead of many small ones.
R=rsc, r CC=golang-dev
https://golang.org/cl/1267041
parent
72fd5c80
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
24 deletions
+30
-24
image.go
src/pkg/image/image.go
+30
-24
No files found.
src/pkg/image/image.go
View file @
e974fb94
...
...
@@ -38,11 +38,12 @@ func (p *RGBA) Set(x, y int, c Color) { p.Pixel[y][x] = toRGBAColor(c).(RGBAColo
// NewRGBA returns a new RGBA with the given width and height.
func
NewRGBA
(
w
,
h
int
)
*
RGBA
{
pixel
:=
make
([][]
RGBAColor
,
h
)
for
y
:=
0
;
y
<
h
;
y
++
{
pixel
[
y
]
=
make
([]
RGBAColor
,
w
)
buf
:=
make
([]
RGBAColor
,
w
*
h
)
pix
:=
make
([][]
RGBAColor
,
h
)
for
y
:=
range
pix
{
pix
[
y
]
=
buf
[
w
*
y
:
w
*
(
y
+
1
)]
}
return
&
RGBA
{
pix
el
}
return
&
RGBA
{
pix
}
}
// An RGBA64 is an in-memory image backed by a 2-D slice of RGBA64Color values.
...
...
@@ -68,11 +69,12 @@ func (p *RGBA64) Set(x, y int, c Color) { p.Pixel[y][x] = toRGBA64Color(c).(RGBA
// NewRGBA64 returns a new RGBA64 with the given width and height.
func
NewRGBA64
(
w
,
h
int
)
*
RGBA64
{
pixel
:=
make
([][]
RGBA64Color
,
h
)
for
y
:=
0
;
y
<
h
;
y
++
{
pixel
[
y
]
=
make
([]
RGBA64Color
,
w
)
buf
:=
make
([]
RGBA64Color
,
w
*
h
)
pix
:=
make
([][]
RGBA64Color
,
h
)
for
y
:=
range
pix
{
pix
[
y
]
=
buf
[
w
*
y
:
w
*
(
y
+
1
)]
}
return
&
RGBA64
{
pix
el
}
return
&
RGBA64
{
pix
}
}
// A NRGBA is an in-memory image backed by a 2-D slice of NRGBAColor values.
...
...
@@ -98,11 +100,12 @@ func (p *NRGBA) Set(x, y int, c Color) { p.Pixel[y][x] = toNRGBAColor(c).(NRGBAC
// NewNRGBA returns a new NRGBA with the given width and height.
func
NewNRGBA
(
w
,
h
int
)
*
NRGBA
{
pixel
:=
make
([][]
NRGBAColor
,
h
)
for
y
:=
0
;
y
<
h
;
y
++
{
pixel
[
y
]
=
make
([]
NRGBAColor
,
w
)
buf
:=
make
([]
NRGBAColor
,
w
*
h
)
pix
:=
make
([][]
NRGBAColor
,
h
)
for
y
:=
range
pix
{
pix
[
y
]
=
buf
[
w
*
y
:
w
*
(
y
+
1
)]
}
return
&
NRGBA
{
pix
el
}
return
&
NRGBA
{
pix
}
}
// A NRGBA64 is an in-memory image backed by a 2-D slice of NRGBA64Color values.
...
...
@@ -128,11 +131,12 @@ func (p *NRGBA64) Set(x, y int, c Color) { p.Pixel[y][x] = toNRGBA64Color(c).(NR
// NewNRGBA64 returns a new NRGBA64 with the given width and height.
func
NewNRGBA64
(
w
,
h
int
)
*
NRGBA64
{
pixel
:=
make
([][]
NRGBA64Color
,
h
)
for
y
:=
0
;
y
<
h
;
y
++
{
pixel
[
y
]
=
make
([]
NRGBA64Color
,
w
)
buf
:=
make
([]
NRGBA64Color
,
w
*
h
)
pix
:=
make
([][]
NRGBA64Color
,
h
)
for
y
:=
range
pix
{
pix
[
y
]
=
buf
[
w
*
y
:
w
*
(
y
+
1
)]
}
return
&
NRGBA64
{
pix
el
}
return
&
NRGBA64
{
pix
}
}
// An Alpha is an in-memory image backed by a 2-D slice of AlphaColor values.
...
...
@@ -158,11 +162,12 @@ func (p *Alpha) Set(x, y int, c Color) { p.Pixel[y][x] = toAlphaColor(c).(AlphaC
// 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
)
buf
:=
make
([]
AlphaColor
,
w
*
h
)
pix
:=
make
([][]
AlphaColor
,
h
)
for
y
:=
range
pix
{
pix
[
y
]
=
buf
[
w
*
y
:
w
*
(
y
+
1
)]
}
return
&
Alpha
{
pix
el
}
return
&
Alpha
{
pix
}
}
// A PalettedColorModel represents a fixed palette of colors.
...
...
@@ -235,9 +240,10 @@ func (p *Paletted) SetColorIndex(x, y int, index uint8) {
// NewPaletted returns a new Paletted with the given width, height and palette.
func
NewPaletted
(
w
,
h
int
,
m
PalettedColorModel
)
*
Paletted
{
pixel
:=
make
([][]
uint8
,
h
)
for
y
:=
0
;
y
<
h
;
y
++
{
pixel
[
y
]
=
make
([]
uint8
,
w
)
buf
:=
make
([]
uint8
,
w
*
h
)
pix
:=
make
([][]
uint8
,
h
)
for
y
:=
range
pix
{
pix
[
y
]
=
buf
[
w
*
y
:
w
*
(
y
+
1
)]
}
return
&
Paletted
{
pix
el
,
m
}
return
&
Paletted
{
pix
,
m
}
}
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