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
5042a4e9
Commit
5042a4e9
authored
Dec 29, 2009
by
Nigel Tao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PNG decoder now handles transparent paletted images.
Fixes #439. R=r CC=golang-dev
https://golang.org/cl/181087
parent
50d3447a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
0 deletions
+32
-0
reader.go
src/pkg/image/png/reader.go
+32
-0
No files found.
src/pkg/image/png/reader.go
View file @
5042a4e9
...
...
@@ -164,6 +164,33 @@ func (d *decoder) parsePLTE(r io.Reader, crc hash.Hash32, length uint32) os.Erro
return
nil
}
func
(
d
*
decoder
)
parsetRNS
(
r
io
.
Reader
,
crc
hash
.
Hash32
,
length
uint32
)
os
.
Error
{
if
length
>
256
{
return
FormatError
(
"bad tRNS length"
)
}
n
,
err
:=
io
.
ReadFull
(
r
,
d
.
tmp
[
0
:
length
])
if
err
!=
nil
{
return
err
}
crc
.
Write
(
d
.
tmp
[
0
:
n
])
switch
d
.
colorType
{
case
ctTrueColor
:
return
UnsupportedError
(
"TrueColor transparency"
)
case
ctPaletted
:
p
:=
d
.
image
.
(
*
image
.
Paletted
)
.
Palette
if
n
>
len
(
p
)
{
return
FormatError
(
"bad tRNS length"
)
}
for
i
:=
0
;
i
<
n
;
i
++
{
rgba
:=
p
[
i
]
.
(
image
.
RGBAColor
)
p
[
i
]
=
image
.
RGBAColor
{
rgba
.
R
,
rgba
.
G
,
rgba
.
B
,
d
.
tmp
[
i
]}
}
case
ctTrueColorAlpha
:
return
FormatError
(
"tRNS, color type mismatch"
)
}
return
nil
}
// The Paeth filter function, as per the PNG specification.
func
paeth
(
a
,
b
,
c
uint8
)
uint8
{
p
:=
int
(
a
)
+
int
(
b
)
-
int
(
c
)
...
...
@@ -353,6 +380,11 @@ func (d *decoder) parseChunk(r io.Reader) os.Error {
}
d
.
stage
=
dsSeenPLTE
err
=
d
.
parsePLTE
(
r
,
crc
,
length
)
case
"tRNS"
:
if
d
.
stage
!=
dsSeenPLTE
{
return
chunkOrderError
}
err
=
d
.
parsetRNS
(
r
,
crc
,
length
)
case
"IDAT"
:
if
d
.
stage
<
dsSeenIHDR
||
d
.
stage
>
dsSeenIDAT
||
(
d
.
colorType
==
ctPaletted
&&
d
.
stage
==
dsSeenIHDR
)
{
return
chunkOrderError
...
...
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