diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2011-12-03 02:17:34 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2011-12-03 02:17:34 +0000 |
commit | 2fd401c8f190f1fe43e51a7f726f6ed6119a1f96 (patch) | |
tree | 7f76eff391f37fe6467ff4ffbc0c582c9959ea30 /libgo/go/image | |
parent | 02e9018f1616b23f1276151797216717b3564202 (diff) | |
download | gcc-2fd401c8f190f1fe43e51a7f726f6ed6119a1f96.zip gcc-2fd401c8f190f1fe43e51a7f726f6ed6119a1f96.tar.gz gcc-2fd401c8f190f1fe43e51a7f726f6ed6119a1f96.tar.bz2 |
libgo: Update to weekly.2011-11-02.
From-SVN: r181964
Diffstat (limited to 'libgo/go/image')
-rw-r--r-- | libgo/go/image/bmp/reader.go | 14 | ||||
-rw-r--r-- | libgo/go/image/decode_test.go | 6 | ||||
-rw-r--r-- | libgo/go/image/format.go | 16 | ||||
-rw-r--r-- | libgo/go/image/gif/reader.go | 30 | ||||
-rw-r--r-- | libgo/go/image/jpeg/huffman.go | 13 | ||||
-rw-r--r-- | libgo/go/image/jpeg/reader.go | 23 | ||||
-rw-r--r-- | libgo/go/image/jpeg/writer.go | 14 | ||||
-rw-r--r-- | libgo/go/image/jpeg/writer_test.go | 2 | ||||
-rw-r--r-- | libgo/go/image/png/reader.go | 41 | ||||
-rw-r--r-- | libgo/go/image/png/reader_test.go | 6 | ||||
-rw-r--r-- | libgo/go/image/png/writer.go | 9 | ||||
-rw-r--r-- | libgo/go/image/png/writer_test.go | 5 | ||||
-rw-r--r-- | libgo/go/image/tiff/buffer.go | 2 | ||||
-rw-r--r-- | libgo/go/image/tiff/buffer_test.go | 8 | ||||
-rw-r--r-- | libgo/go/image/tiff/compress.go | 5 | ||||
-rw-r--r-- | libgo/go/image/tiff/reader.go | 19 | ||||
-rw-r--r-- | libgo/go/image/tiff/reader_test.go | 2 |
17 files changed, 103 insertions, 112 deletions
diff --git a/libgo/go/image/bmp/reader.go b/libgo/go/image/bmp/reader.go index 134de5b..ad56865 100644 --- a/libgo/go/image/bmp/reader.go +++ b/libgo/go/image/bmp/reader.go @@ -8,15 +8,15 @@ package bmp import ( + "errors" "image/color" "image" "io" - "os" ) // ErrUnsupported means that the input BMP image uses a valid but unsupported // feature. -var ErrUnsupported = os.NewError("bmp: unsupported BMP image") +var ErrUnsupported = errors.New("bmp: unsupported BMP image") func readUint16(b []byte) uint16 { return uint16(b[0]) | uint16(b[1])<<8 @@ -27,7 +27,7 @@ func readUint32(b []byte) uint32 { } // decodePaletted reads an 8 bit-per-pixel BMP image from r. -func decodePaletted(r io.Reader, c image.Config) (image.Image, os.Error) { +func decodePaletted(r io.Reader, c image.Config) (image.Image, error) { var tmp [4]byte paletted := image.NewPaletted(image.Rect(0, 0, c.Width, c.Height), c.ColorModel.(color.Palette)) // BMP images are stored bottom-up rather than top-down. @@ -49,7 +49,7 @@ func decodePaletted(r io.Reader, c image.Config) (image.Image, os.Error) { } // decodeRGBA reads a 24 bit-per-pixel BMP image from r. -func decodeRGBA(r io.Reader, c image.Config) (image.Image, os.Error) { +func decodeRGBA(r io.Reader, c image.Config) (image.Image, error) { rgba := image.NewRGBA(image.Rect(0, 0, c.Width, c.Height)) // There are 3 bytes per pixel, and each row is 4-byte aligned. b := make([]byte, (3*c.Width+3)&^3) @@ -73,7 +73,7 @@ func decodeRGBA(r io.Reader, c image.Config) (image.Image, os.Error) { // Decode reads a BMP image from r and returns it as an image.Image. // Limitation: The file must be 8 or 24 bits per pixel. -func Decode(r io.Reader) (image.Image, os.Error) { +func Decode(r io.Reader) (image.Image, error) { c, err := DecodeConfig(r) if err != nil { return nil, err @@ -87,7 +87,7 @@ func Decode(r io.Reader) (image.Image, os.Error) { // DecodeConfig returns the color model and dimensions of a BMP image without // decoding the entire image. // Limitation: The file must be 8 or 24 bits per pixel. -func DecodeConfig(r io.Reader) (config image.Config, err os.Error) { +func DecodeConfig(r io.Reader) (config image.Config, err error) { // We only support those BMP images that are a BITMAPFILEHEADER // immediately followed by a BITMAPINFOHEADER. const ( @@ -99,7 +99,7 @@ func DecodeConfig(r io.Reader) (config image.Config, err os.Error) { return } if string(b[:2]) != "BM" { - err = os.NewError("bmp: invalid format") + err = errors.New("bmp: invalid format") return } offset := readUint32(b[10:14]) diff --git a/libgo/go/image/decode_test.go b/libgo/go/image/decode_test.go index b348c1d..1b7db8b 100644 --- a/libgo/go/image/decode_test.go +++ b/libgo/go/image/decode_test.go @@ -41,7 +41,7 @@ var imageTests = []imageTest{ {"testdata/video-005.gray.png", "testdata/video-005.gray.png", 0}, } -func decode(filename string) (image.Image, string, os.Error) { +func decode(filename string) (image.Image, string, error) { f, err := os.Open(filename) if err != nil { return nil, "", err @@ -50,7 +50,7 @@ func decode(filename string) (image.Image, string, os.Error) { return image.Decode(bufio.NewReader(f)) } -func decodeConfig(filename string) (image.Config, string, os.Error) { +func decodeConfig(filename string) (image.Config, string, error) { f, err := os.Open(filename) if err != nil { return image.Config{}, "", err @@ -83,7 +83,7 @@ loop: for _, it := range imageTests { g := golden[it.goldenFilename] if g == nil { - var err os.Error + var err error g, _, err = decode(it.goldenFilename) if err != nil { t.Errorf("%s: %v", it.goldenFilename, err) diff --git a/libgo/go/image/format.go b/libgo/go/image/format.go index b485932..78fc3ed 100644 --- a/libgo/go/image/format.go +++ b/libgo/go/image/format.go @@ -6,18 +6,18 @@ package image import ( "bufio" + "errors" "io" - "os" ) // An UnknownFormatErr indicates that decoding encountered an unknown format. -var UnknownFormatErr = os.NewError("image: unknown format") +var UnknownFormatErr = errors.New("image: unknown format") // A format holds an image format's name, magic header and how to decode it. type format struct { name, magic string - decode func(io.Reader) (Image, os.Error) - decodeConfig func(io.Reader) (Config, os.Error) + decode func(io.Reader) (Image, error) + decodeConfig func(io.Reader) (Config, error) } // Formats is the list of registered formats. @@ -29,14 +29,14 @@ var formats []format // string can contain "?" wildcards that each match any one byte. // Decode is the function that decodes the encoded image. // DecodeConfig is the function that decodes just its configuration. -func RegisterFormat(name, magic string, decode func(io.Reader) (Image, os.Error), decodeConfig func(io.Reader) (Config, os.Error)) { +func RegisterFormat(name, magic string, decode func(io.Reader) (Image, error), decodeConfig func(io.Reader) (Config, error)) { formats = append(formats, format{name, magic, decode, decodeConfig}) } // A reader is an io.Reader that can also peek ahead. type reader interface { io.Reader - Peek(int) ([]byte, os.Error) + Peek(int) ([]byte, error) } // AsReader converts an io.Reader to a reader. @@ -75,7 +75,7 @@ func sniff(r reader) format { // The string returned is the format name used during format registration. // Format registration is typically done by the init method of the codec- // specific package. -func Decode(r io.Reader) (Image, string, os.Error) { +func Decode(r io.Reader) (Image, string, error) { rr := asReader(r) f := sniff(rr) if f.decode == nil { @@ -89,7 +89,7 @@ func Decode(r io.Reader) (Image, string, os.Error) { // been encoded in a registered format. The string returned is the format name // used during format registration. Format registration is typically done by // the init method of the codec-specific package. -func DecodeConfig(r io.Reader) (Config, string, os.Error) { +func DecodeConfig(r io.Reader) (Config, string, error) { rr := asReader(r) f := sniff(rr) if f.decodeConfig == nil { diff --git a/libgo/go/image/gif/reader.go b/libgo/go/image/gif/reader.go index a5a4265..24b53c5 100644 --- a/libgo/go/image/gif/reader.go +++ b/libgo/go/image/gif/reader.go @@ -10,11 +10,11 @@ package gif import ( "bufio" "compress/lzw" + "errors" "fmt" "image" "image/color" "io" - "os" ) // If the io.Reader does not also have ReadByte, then decode will introduce its own buffering. @@ -97,7 +97,7 @@ type blockReader struct { tmp [256]byte } -func (b *blockReader) Read(p []byte) (int, os.Error) { +func (b *blockReader) Read(p []byte) (int, error) { if len(p) == 0 { return 0, nil } @@ -107,7 +107,7 @@ func (b *blockReader) Read(p []byte) (int, os.Error) { return 0, err } if blockLen == 0 { - return 0, os.EOF + return 0, io.EOF } b.slice = b.tmp[0:blockLen] if _, err = io.ReadFull(b.r, b.slice); err != nil { @@ -120,7 +120,7 @@ func (b *blockReader) Read(p []byte) (int, os.Error) { } // decode reads a GIF image from r and stores the result in d. -func (d *decoder) decode(r io.Reader, configOnly bool) os.Error { +func (d *decoder) decode(r io.Reader, configOnly bool) error { // Add buffering if r does not provide ReadByte. if rr, ok := r.(reader); ok { d.r = rr @@ -146,7 +146,7 @@ Loop: for err == nil { var c byte c, err = d.r.ReadByte() - if err == os.EOF { + if err == io.EOF { break } switch c { @@ -189,7 +189,7 @@ Loop: return err } if c != 0 { - return os.NewError("gif: extra data after image") + return errors.New("gif: extra data after image") } // Undo the interlacing if necessary. @@ -217,7 +217,7 @@ Loop: return nil } -func (d *decoder) readHeaderAndScreenDescriptor() os.Error { +func (d *decoder) readHeaderAndScreenDescriptor() error { _, err := io.ReadFull(d.r, d.tmp[0:13]) if err != nil { return err @@ -236,7 +236,7 @@ func (d *decoder) readHeaderAndScreenDescriptor() os.Error { return nil } -func (d *decoder) readColorMap() (color.Palette, os.Error) { +func (d *decoder) readColorMap() (color.Palette, error) { if d.pixelSize > 8 { return nil, fmt.Errorf("gif: can't handle %d bits per pixel", d.pixelSize) } @@ -258,7 +258,7 @@ func (d *decoder) readColorMap() (color.Palette, os.Error) { return colorMap, nil } -func (d *decoder) readExtension() os.Error { +func (d *decoder) readExtension() error { extension, err := d.r.ReadByte() if err != nil { return err @@ -307,7 +307,7 @@ func (d *decoder) readExtension() os.Error { panic("unreachable") } -func (d *decoder) readGraphicControl() os.Error { +func (d *decoder) readGraphicControl() error { if _, err := io.ReadFull(d.r, d.tmp[0:6]); err != nil { return fmt.Errorf("gif: can't read graphic control: %s", err) } @@ -326,7 +326,7 @@ func (d *decoder) setTransparency(colorMap color.Palette) { } } -func (d *decoder) newImageFromDescriptor() (*image.Paletted, os.Error) { +func (d *decoder) newImageFromDescriptor() (*image.Paletted, error) { if _, err := io.ReadFull(d.r, d.tmp[0:9]); err != nil { return nil, fmt.Errorf("gif: can't read image descriptor: %s", err) } @@ -338,7 +338,7 @@ func (d *decoder) newImageFromDescriptor() (*image.Paletted, os.Error) { return image.NewPaletted(image.Rect(left, top, left+width, top+height), nil), nil } -func (d *decoder) readBlock() (int, os.Error) { +func (d *decoder) readBlock() (int, error) { n, err := d.r.ReadByte() if n == 0 || err != nil { return 0, err @@ -379,7 +379,7 @@ func uninterlace(m *image.Paletted) { // Decode reads a GIF image from r and returns the first embedded // image as an image.Image. -func Decode(r io.Reader) (image.Image, os.Error) { +func Decode(r io.Reader) (image.Image, error) { var d decoder if err := d.decode(r, false); err != nil { return nil, err @@ -396,7 +396,7 @@ type GIF struct { // DecodeAll reads a GIF image from r and returns the sequential frames // and timing information. -func DecodeAll(r io.Reader) (*GIF, os.Error) { +func DecodeAll(r io.Reader) (*GIF, error) { var d decoder if err := d.decode(r, false); err != nil { return nil, err @@ -411,7 +411,7 @@ func DecodeAll(r io.Reader) (*GIF, os.Error) { // DecodeConfig returns the global color model and dimensions of a GIF image // without decoding the entire image. -func DecodeConfig(r io.Reader) (image.Config, os.Error) { +func DecodeConfig(r io.Reader) (image.Config, error) { var d decoder if err := d.decode(r, true); err != nil { return image.Config{}, err diff --git a/libgo/go/image/jpeg/huffman.go b/libgo/go/image/jpeg/huffman.go index 0d03a73..d238249 100644 --- a/libgo/go/image/jpeg/huffman.go +++ b/libgo/go/image/jpeg/huffman.go @@ -4,10 +4,7 @@ package jpeg -import ( - "io" - "os" -) +import "io" // Each code is at most 16 bits long. const maxCodeLength = 16 @@ -36,7 +33,7 @@ type huffman struct { } // Reads bytes from the io.Reader to ensure that bits.n is at least n. -func (d *decoder) ensureNBits(n int) os.Error { +func (d *decoder) ensureNBits(n int) error { for d.b.n < n { c, err := d.r.ReadByte() if err != nil { @@ -64,7 +61,7 @@ func (d *decoder) ensureNBits(n int) os.Error { } // The composition of RECEIVE and EXTEND, specified in section F.2.2.1. -func (d *decoder) receiveExtend(t uint8) (int, os.Error) { +func (d *decoder) receiveExtend(t uint8) (int, error) { err := d.ensureNBits(int(t)) if err != nil { return 0, err @@ -81,7 +78,7 @@ func (d *decoder) receiveExtend(t uint8) (int, os.Error) { // Processes a Define Huffman Table marker, and initializes a huffman struct from its contents. // Specified in section B.2.4.2. -func (d *decoder) processDHT(n int) os.Error { +func (d *decoder) processDHT(n int) error { for n > 0 { if n < 17 { return FormatError("DHT has wrong length") @@ -167,7 +164,7 @@ func (d *decoder) processDHT(n int) os.Error { // Returns the next Huffman-coded value from the bit stream, decoded according to h. // TODO(nigeltao): This decoding algorithm is simple, but slow. A lookahead table, instead of always // peeling off only 1 bit at at time, ought to be faster. -func (d *decoder) decodeHuffman(h *huffman) (uint8, os.Error) { +func (d *decoder) decodeHuffman(h *huffman) (uint8, error) { if h.length == 0 { return 0, FormatError("uninitialized Huffman table") } diff --git a/libgo/go/image/jpeg/reader.go b/libgo/go/image/jpeg/reader.go index 450355e..c1fc2d5 100644 --- a/libgo/go/image/jpeg/reader.go +++ b/libgo/go/image/jpeg/reader.go @@ -13,7 +13,6 @@ import ( "image/color" "image/ycbcr" "io" - "os" ) // TODO(nigeltao): fix up the doc comment style so that sentences start with @@ -22,12 +21,12 @@ import ( // A FormatError reports that the input is not a valid JPEG. type FormatError string -func (e FormatError) String() string { return "invalid JPEG format: " + string(e) } +func (e FormatError) Error() string { return "invalid JPEG format: " + string(e) } // An UnsupportedError reports that the input uses a valid but unimplemented JPEG feature. type UnsupportedError string -func (e UnsupportedError) String() string { return "unsupported JPEG feature: " + string(e) } +func (e UnsupportedError) Error() string { return "unsupported JPEG feature: " + string(e) } // Component specification, specified in section B.2.2. type component struct { @@ -91,7 +90,7 @@ var unzig = [blockSize]int{ // If the passed in io.Reader does not also have ReadByte, then Decode will introduce its own buffering. type Reader interface { io.Reader - ReadByte() (c byte, err os.Error) + ReadByte() (c byte, err error) } type decoder struct { @@ -109,7 +108,7 @@ type decoder struct { } // Reads and ignores the next n bytes. -func (d *decoder) ignore(n int) os.Error { +func (d *decoder) ignore(n int) error { for n > 0 { m := len(d.tmp) if m > n { @@ -125,7 +124,7 @@ func (d *decoder) ignore(n int) os.Error { } // Specified in section B.2.2. -func (d *decoder) processSOF(n int) os.Error { +func (d *decoder) processSOF(n int) error { switch n { case 6 + 3*nGrayComponent: d.nComp = nGrayComponent @@ -172,7 +171,7 @@ func (d *decoder) processSOF(n int) os.Error { } // Specified in section B.2.4.1. -func (d *decoder) processDQT(n int) os.Error { +func (d *decoder) processDQT(n int) error { const qtLength = 1 + blockSize for ; n >= qtLength; n -= qtLength { _, err := io.ReadFull(d.r, d.tmp[0:qtLength]) @@ -229,7 +228,7 @@ func (d *decoder) makeImg(h0, v0, mxx, myy int) { } // Specified in section B.2.3. -func (d *decoder) processSOS(n int) os.Error { +func (d *decoder) processSOS(n int) error { if d.nComp == 0 { return FormatError("missing SOF marker") } @@ -362,7 +361,7 @@ func (d *decoder) processSOS(n int) os.Error { } // Specified in section B.2.4.4. -func (d *decoder) processDRI(n int) os.Error { +func (d *decoder) processDRI(n int) error { if n != 2 { return FormatError("DRI has wrong length") } @@ -375,7 +374,7 @@ func (d *decoder) processDRI(n int) os.Error { } // decode reads a JPEG image from r and returns it as an image.Image. -func (d *decoder) decode(r io.Reader, configOnly bool) (image.Image, os.Error) { +func (d *decoder) decode(r io.Reader, configOnly bool) (image.Image, error) { if rr, ok := r.(Reader); ok { d.r = rr } else { @@ -451,14 +450,14 @@ func (d *decoder) decode(r io.Reader, configOnly bool) (image.Image, os.Error) { } // Decode reads a JPEG image from r and returns it as an image.Image. -func Decode(r io.Reader) (image.Image, os.Error) { +func Decode(r io.Reader) (image.Image, error) { var d decoder return d.decode(r, false) } // DecodeConfig returns the color model and dimensions of a JPEG image without // decoding the entire image. -func DecodeConfig(r io.Reader) (image.Config, os.Error) { +func DecodeConfig(r io.Reader) (image.Config, error) { var d decoder if _, err := d.decode(r, true); err != nil { return image.Config{}, err diff --git a/libgo/go/image/jpeg/writer.go b/libgo/go/image/jpeg/writer.go index 2bb6df5..fab0bd0 100644 --- a/libgo/go/image/jpeg/writer.go +++ b/libgo/go/image/jpeg/writer.go @@ -6,10 +6,10 @@ package jpeg import ( "bufio" + "errors" "image" "image/ycbcr" "io" - "os" ) // min returns the minimum of two integers. @@ -207,9 +207,9 @@ func init() { // writer is a buffered writer. type writer interface { - Flush() os.Error - Write([]byte) (int, os.Error) - WriteByte(byte) os.Error + Flush() error + Write([]byte) (int, error) + WriteByte(byte) error } // encoder encodes an image to the JPEG format. @@ -217,7 +217,7 @@ type encoder struct { // w is the writer to write to. err is the first error encountered during // writing. All attempted writes after the first error become no-ops. w writer - err os.Error + err error // buf is a scratch buffer. buf [16]byte // bits and nBits are accumulated bits to write to w. @@ -487,10 +487,10 @@ type Options struct { // Encode writes the Image m to w in JPEG 4:2:0 baseline format with the given // options. Default parameters are used if a nil *Options is passed. -func Encode(w io.Writer, m image.Image, o *Options) os.Error { +func Encode(w io.Writer, m image.Image, o *Options) error { b := m.Bounds() if b.Dx() >= 1<<16 || b.Dy() >= 1<<16 { - return os.NewError("jpeg: image is too large to encode") + return errors.New("jpeg: image is too large to encode") } var e encoder if ww, ok := w.(writer); ok { diff --git a/libgo/go/image/jpeg/writer_test.go b/libgo/go/image/jpeg/writer_test.go index 0378252..72cec93 100644 --- a/libgo/go/image/jpeg/writer_test.go +++ b/libgo/go/image/jpeg/writer_test.go @@ -36,7 +36,7 @@ func delta(u0, u1 uint32) int64 { return d } -func readPng(filename string) (image.Image, os.Error) { +func readPng(filename string) (image.Image, error) { f, err := os.Open(filename) if err != nil { return nil, err diff --git a/libgo/go/image/png/reader.go b/libgo/go/image/png/reader.go index 66f1916..7eb8cea 100644 --- a/libgo/go/image/png/reader.go +++ b/libgo/go/image/png/reader.go @@ -16,7 +16,6 @@ import ( "image" "image/color" "io" - "os" ) // Color type, as per the PNG spec. @@ -90,14 +89,14 @@ type decoder struct { // A FormatError reports that the input is not a valid PNG. type FormatError string -func (e FormatError) String() string { return "png: invalid format: " + string(e) } +func (e FormatError) Error() string { return "png: invalid format: " + string(e) } var chunkOrderError = FormatError("chunk out of order") // An UnsupportedError reports that the input uses a valid but unimplemented PNG feature. type UnsupportedError string -func (e UnsupportedError) String() string { return "png: unsupported feature: " + string(e) } +func (e UnsupportedError) Error() string { return "png: unsupported feature: " + string(e) } func abs(x int) int { if x < 0 { @@ -113,7 +112,7 @@ func min(a, b int) int { return b } -func (d *decoder) parseIHDR(length uint32) os.Error { +func (d *decoder) parseIHDR(length uint32) error { if length != 13 { return FormatError("bad IHDR length") } @@ -189,7 +188,7 @@ func (d *decoder) parseIHDR(length uint32) os.Error { return d.verifyChecksum() } -func (d *decoder) parsePLTE(length uint32) os.Error { +func (d *decoder) parsePLTE(length uint32) error { np := int(length / 3) // The number of palette entries. if length%3 != 0 || np <= 0 || np > 256 || np > 1<<uint(d.depth) { return FormatError("bad PLTE length") @@ -214,7 +213,7 @@ func (d *decoder) parsePLTE(length uint32) os.Error { return d.verifyChecksum() } -func (d *decoder) parsetRNS(length uint32) os.Error { +func (d *decoder) parsetRNS(length uint32) error { if length > 256 { return FormatError("bad tRNS length") } @@ -263,7 +262,7 @@ func paeth(a, b, c uint8) uint8 { // immediately before the first Read call is that d.r is positioned between the // first IDAT and xxx, and the decoder state immediately after the last Read // call is that d.r is positioned between yy and crc1. -func (d *decoder) Read(p []byte) (int, os.Error) { +func (d *decoder) Read(p []byte) (int, error) { if len(p) == 0 { return 0, nil } @@ -294,7 +293,7 @@ func (d *decoder) Read(p []byte) (int, os.Error) { } // decode decodes the IDAT data into an image. -func (d *decoder) decode() (image.Image, os.Error) { +func (d *decoder) decode() (image.Image, error) { r, err := zlib.NewReader(d) if err != nil { return nil, err @@ -517,8 +516,8 @@ func (d *decoder) decode() (image.Image, os.Error) { // Check for EOF, to verify the zlib checksum. n, err := r.Read(pr[:1]) - if err != os.EOF { - return nil, FormatError(err.String()) + if err != io.EOF { + return nil, FormatError(err.Error()) } if n != 0 || d.idatLength != 0 { return nil, FormatError("too much pixel data") @@ -527,7 +526,7 @@ func (d *decoder) decode() (image.Image, os.Error) { return img, nil } -func (d *decoder) parseIDAT(length uint32) (err os.Error) { +func (d *decoder) parseIDAT(length uint32) (err error) { d.idatLength = length d.img, err = d.decode() if err != nil { @@ -536,14 +535,14 @@ func (d *decoder) parseIDAT(length uint32) (err os.Error) { return d.verifyChecksum() } -func (d *decoder) parseIEND(length uint32) os.Error { +func (d *decoder) parseIEND(length uint32) error { if length != 0 { return FormatError("bad IEND length") } return d.verifyChecksum() } -func (d *decoder) parseChunk() os.Error { +func (d *decoder) parseChunk() error { // Read the length and chunk type. n, err := io.ReadFull(d.r, d.tmp[:8]) if err != nil { @@ -598,7 +597,7 @@ func (d *decoder) parseChunk() os.Error { return d.verifyChecksum() } -func (d *decoder) verifyChecksum() os.Error { +func (d *decoder) verifyChecksum() error { if _, err := io.ReadFull(d.r, d.tmp[:4]); err != nil { return err } @@ -608,7 +607,7 @@ func (d *decoder) verifyChecksum() os.Error { return nil } -func (d *decoder) checkHeader() os.Error { +func (d *decoder) checkHeader() error { _, err := io.ReadFull(d.r, d.tmp[:len(pngHeader)]) if err != nil { return err @@ -621,20 +620,20 @@ func (d *decoder) checkHeader() os.Error { // Decode reads a PNG 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, error) { d := &decoder{ r: r, crc: crc32.NewIEEE(), } if err := d.checkHeader(); err != nil { - if err == os.EOF { + if err == io.EOF { err = io.ErrUnexpectedEOF } return nil, err } for d.stage != dsSeenIEND { if err := d.parseChunk(); err != nil { - if err == os.EOF { + if err == io.EOF { err = io.ErrUnexpectedEOF } return nil, err @@ -645,20 +644,20 @@ func Decode(r io.Reader) (image.Image, os.Error) { // DecodeConfig returns the color model and dimensions of a PNG image without // decoding the entire image. -func DecodeConfig(r io.Reader) (image.Config, os.Error) { +func DecodeConfig(r io.Reader) (image.Config, error) { d := &decoder{ r: r, crc: crc32.NewIEEE(), } if err := d.checkHeader(); err != nil { - if err == os.EOF { + if err == io.EOF { err = io.ErrUnexpectedEOF } return image.Config{}, err } for { if err := d.parseChunk(); err != nil { - if err == os.EOF { + if err == io.EOF { err = io.ErrUnexpectedEOF } return image.Config{}, err diff --git a/libgo/go/image/png/reader_test.go b/libgo/go/image/png/reader_test.go index 48d0613..7eb1fc2 100644 --- a/libgo/go/image/png/reader_test.go +++ b/libgo/go/image/png/reader_test.go @@ -43,7 +43,7 @@ var filenamesShort = []string{ "basn6a16", } -func readPNG(filename string) (image.Image, os.Error) { +func readPNG(filename string) (image.Image, error) { f, err := os.Open(filename) if err != nil { return nil, err @@ -223,7 +223,7 @@ func TestReader(t *testing.T) { for { ps, perr := pb.ReadString('\n') ss, serr := sb.ReadString('\n') - if perr == os.EOF && serr == os.EOF { + if perr == io.EOF && serr == io.EOF { break } if perr != nil { @@ -259,7 +259,7 @@ func TestReaderError(t *testing.T) { t.Errorf("decoding %s: missing error", tt.file) continue } - if !strings.Contains(err.String(), tt.err) { + if !strings.Contains(err.Error(), tt.err) { t.Errorf("decoding %s: %s, want %s", tt.file, err, tt.err) } if img != nil { diff --git a/libgo/go/image/png/writer.go b/libgo/go/image/png/writer.go index b6103c6..48089ff 100644 --- a/libgo/go/image/png/writer.go +++ b/libgo/go/image/png/writer.go @@ -11,7 +11,6 @@ import ( "image" "image/color" "io" - "os" "strconv" ) @@ -19,7 +18,7 @@ type encoder struct { w io.Writer m image.Image cb int - err os.Error + err error header [8]byte footer [4]byte tmp [3 * 256]byte @@ -161,7 +160,7 @@ func (e *encoder) maybeWritetRNS(p color.Palette) { // // This method should only be called from writeIDATs (via writeImage). // No other code should treat an encoder as an io.Writer. -func (e *encoder) Write(b []byte) (int, os.Error) { +func (e *encoder) Write(b []byte) (int, error) { e.writeChunk(b, "IDAT") if e.err != nil { return 0, e.err @@ -263,7 +262,7 @@ func filter(cr *[nFilter][]byte, pr []byte, bpp int) int { return filter } -func writeImage(w io.Writer, m image.Image, cb int) os.Error { +func writeImage(w io.Writer, m image.Image, cb int) error { zw, err := zlib.NewWriter(w) if err != nil { return err @@ -424,7 +423,7 @@ func (e *encoder) writeIEND() { 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) error { // Obviously, negative widths and heights are invalid. Furthermore, the PNG // spec section 11.2.2 says that zero is invalid. Excessively large images are // also rejected. diff --git a/libgo/go/image/png/writer_test.go b/libgo/go/image/png/writer_test.go index e517173..1757e14 100644 --- a/libgo/go/image/png/writer_test.go +++ b/libgo/go/image/png/writer_test.go @@ -10,11 +10,10 @@ import ( "image" "image/color" "io/ioutil" - "os" "testing" ) -func diff(m0, m1 image.Image) os.Error { +func diff(m0, m1 image.Image) error { b0, b1 := m0.Bounds(), m1.Bounds() if !b0.Size().Eq(b1.Size()) { return fmt.Errorf("dimensions differ: %v vs %v", b0, b1) @@ -35,7 +34,7 @@ func diff(m0, m1 image.Image) os.Error { return nil } -func encodeDecode(m image.Image) (image.Image, os.Error) { +func encodeDecode(m image.Image) (image.Image, error) { b := bytes.NewBuffer(nil) err := Encode(b, m) if err != nil { diff --git a/libgo/go/image/tiff/buffer.go b/libgo/go/image/tiff/buffer.go index 7c07142..ce35073 100644 --- a/libgo/go/image/tiff/buffer.go +++ b/libgo/go/image/tiff/buffer.go @@ -15,7 +15,7 @@ type buffer struct { buf []byte } -func (b *buffer) ReadAt(p []byte, off int64) (int, os.Error) { +func (b *buffer) ReadAt(p []byte, off int64) (int, error) { o := int(off) end := o + len(p) if int64(end) != off+int64(len(p)) { diff --git a/libgo/go/image/tiff/buffer_test.go b/libgo/go/image/tiff/buffer_test.go index 4f3e68e..e13afb3 100644 --- a/libgo/go/image/tiff/buffer_test.go +++ b/libgo/go/image/tiff/buffer_test.go @@ -5,7 +5,7 @@ package tiff import ( - "os" + "io" "strings" "testing" ) @@ -14,13 +14,13 @@ var readAtTests = []struct { n int off int64 s string - err os.Error + err error }{ {2, 0, "ab", nil}, {6, 0, "abcdef", nil}, {3, 3, "def", nil}, - {3, 5, "f", os.EOF}, - {3, 6, "", os.EOF}, + {3, 5, "f", io.EOF}, + {3, 6, "", io.EOF}, } func TestReadAt(t *testing.T) { diff --git a/libgo/go/image/tiff/compress.go b/libgo/go/image/tiff/compress.go index e89aa6d..40c7fd8 100644 --- a/libgo/go/image/tiff/compress.go +++ b/libgo/go/image/tiff/compress.go @@ -7,7 +7,6 @@ package tiff import ( "bufio" "io" - "os" ) type byteReader interface { @@ -20,7 +19,7 @@ type byteReader interface { // // The PackBits compression format is described in section 9 (p. 42) // of the TIFF spec. -func unpackBits(r io.Reader) ([]byte, os.Error) { +func unpackBits(r io.Reader) ([]byte, error) { buf := make([]byte, 128) dst := make([]byte, 0, 1024) br, ok := r.(byteReader) @@ -31,7 +30,7 @@ func unpackBits(r io.Reader) ([]byte, os.Error) { for { b, err := br.ReadByte() if err != nil { - if err == os.EOF { + if err == io.EOF { return dst, nil } return nil, err diff --git a/libgo/go/image/tiff/reader.go b/libgo/go/image/tiff/reader.go index c452f5d..00a51db 100644 --- a/libgo/go/image/tiff/reader.go +++ b/libgo/go/image/tiff/reader.go @@ -15,13 +15,12 @@ import ( "image/color" "io" "io/ioutil" - "os" ) // A FormatError reports that the input is not a valid TIFF image. type FormatError string -func (e FormatError) String() string { +func (e FormatError) Error() string { return "tiff: invalid format: " + string(e) } @@ -29,14 +28,14 @@ func (e FormatError) String() string { // unimplemented feature. type UnsupportedError string -func (e UnsupportedError) String() string { +func (e UnsupportedError) Error() string { return "tiff: unsupported feature: " + string(e) } // An InternalError reports that an internal error was encountered. type InternalError string -func (e InternalError) String() string { +func (e InternalError) Error() string { return "tiff: internal error: " + string(e) } @@ -66,7 +65,7 @@ func (d *decoder) firstVal(tag int) uint { // ifdUint decodes the IFD entry in p, which must be of the Byte, Short // or Long type, and returns the decoded uint values. -func (d *decoder) ifdUint(p []byte) (u []uint, err os.Error) { +func (d *decoder) ifdUint(p []byte) (u []uint, err error) { var raw []byte datatype := d.byteOrder.Uint16(p[2:4]) count := d.byteOrder.Uint32(p[4:8]) @@ -103,7 +102,7 @@ func (d *decoder) ifdUint(p []byte) (u []uint, err os.Error) { // parseIFD decides whether the the IFD entry in p is "interesting" and // stows away the data in the decoder. -func (d *decoder) parseIFD(p []byte) os.Error { +func (d *decoder) parseIFD(p []byte) error { tag := d.byteOrder.Uint16(p[0:2]) switch tag { case tBitsPerSample, @@ -180,7 +179,7 @@ func (d *decoder) flushBits() { // decode decodes the raw data of an image. // It reads from d.buf and writes the strip with ymin <= y < ymax into dst. -func (d *decoder) decode(dst image.Image, ymin, ymax int) os.Error { +func (d *decoder) decode(dst image.Image, ymin, ymax int) error { d.off = 0 // Apply horizontal predictor if necessary. @@ -255,7 +254,7 @@ func (d *decoder) decode(dst image.Image, ymin, ymax int) os.Error { return nil } -func newDecoder(r io.Reader) (*decoder, os.Error) { +func newDecoder(r io.Reader) (*decoder, error) { d := &decoder{ r: newReaderAt(r), features: make(map[int][]uint), @@ -350,7 +349,7 @@ func newDecoder(r io.Reader) (*decoder, os.Error) { // DecodeConfig returns the color model and dimensions of a TIFF image without // decoding the entire image. -func DecodeConfig(r io.Reader) (image.Config, os.Error) { +func DecodeConfig(r io.Reader) (image.Config, error) { d, err := newDecoder(r) if err != nil { return image.Config{}, err @@ -360,7 +359,7 @@ func DecodeConfig(r io.Reader) (image.Config, os.Error) { // Decode reads a TIFF image from r and returns it as an image.Image. // The type of Image returned depends on the contents of the TIFF. -func Decode(r io.Reader) (img image.Image, err os.Error) { +func Decode(r io.Reader) (img image.Image, err error) { d, err := newDecoder(r) if err != nil { return diff --git a/libgo/go/image/tiff/reader_test.go b/libgo/go/image/tiff/reader_test.go index 86b7dc3..1a3d23b 100644 --- a/libgo/go/image/tiff/reader_test.go +++ b/libgo/go/image/tiff/reader_test.go @@ -13,7 +13,7 @@ import ( ) // Read makes *buffer implements io.Reader, so that we can pass one to Decode. -func (*buffer) Read([]byte) (int, os.Error) { +func (*buffer) Read([]byte) (int, error) { panic("unimplemented") } |