Commit cb1ad7e7 authored by Nigel Tao's avatar Nigel Tao

Documentation for png.Decode and png.Encode.

R=r,rsc
APPROVED=r
DELTA=7  (5 added, 0 deleted, 2 changed)
OCL=35651
CL=35692
parent 76d585e5
...@@ -412,6 +412,8 @@ func (d *decoder) checkHeader(r io.Reader) os.Error { ...@@ -412,6 +412,8 @@ func (d *decoder) checkHeader(r io.Reader) os.Error {
return nil; return nil;
} }
// Decode reads a PNG formatted image from r and returns it as an image.Image.
// The type of Image returned depends on the PNG contents.
func Decode(r io.Reader) (image.Image, os.Error) { func Decode(r io.Reader) (image.Image, os.Error) {
var d decoder; var d decoder;
err := d.checkHeader(r); err := d.checkHeader(r);
......
...@@ -316,9 +316,12 @@ func (e *encoder) writeIEND() { ...@@ -316,9 +316,12 @@ func (e *encoder) writeIEND() {
e.writeChunk(e.tmp[0:0], "IEND"); e.writeChunk(e.tmp[0:0], "IEND");
} }
// Encode writes the Image m to w in PNG format. Any Image may be encoded, but
// images that are not image.NRGBA might be encoded lossily.
func Encode(w io.Writer, m image.Image) os.Error { func Encode(w io.Writer, m image.Image) os.Error {
// Obviously, negative widths and heights are invalid. Furthermore, // Obviously, negative widths and heights are invalid. Furthermore, the PNG
// the PNG spec section 11.2.2 says that zero is an invalid dimension. // spec section 11.2.2 says that zero is invalid. Excessively large images are
// also rejected.
mw, mh := int64(m.Width()), int64(m.Height()); mw, mh := int64(m.Width()), int64(m.Height());
if mw <= 0 || mh <= 0 || mw >= 1<<32 || mh >= 1<<32 { if mw <= 0 || mh <= 0 || mw >= 1<<32 || mh >= 1<<32 {
return FormatError("invalid image size: " + strconv.Itoa64(mw) + "x" + strconv.Itoa64(mw)); return FormatError("invalid image size: " + strconv.Itoa64(mw) + "x" + strconv.Itoa64(mw));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment