diff options
author | Robert Griesemer <gri@golang.org> | 2009-11-09 12:07:39 -0800 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2009-11-09 12:07:39 -0800 |
commit | e940edc7a026293153ba09ece40e8092a2fc2463 (patch) | |
tree | c94a425c84b7a48f91a5d76a222effad70c9a88c /src/pkg/image | |
parent | e067f862f1774ab89a2096a88571a94e3b9cd353 (diff) | |
download | golang-e940edc7a026293153ba09ece40e8092a2fc2463.tar.gz |
remove semis after statements in one-statement statement lists
R=rsc, r
http://go/go-review/1025029
Diffstat (limited to 'src/pkg/image')
-rw-r--r-- | src/pkg/image/color.go | 18 | ||||
-rw-r--r-- | src/pkg/image/image.go | 28 | ||||
-rw-r--r-- | src/pkg/image/png/reader.go | 110 | ||||
-rw-r--r-- | src/pkg/image/png/reader_test.go | 12 | ||||
-rw-r--r-- | src/pkg/image/png/writer.go | 44 | ||||
-rw-r--r-- | src/pkg/image/png/writer_test.go | 4 |
6 files changed, 108 insertions, 108 deletions
diff --git a/src/pkg/image/color.go b/src/pkg/image/color.go index 757be84ce..c3c5e5024 100644 --- a/src/pkg/image/color.go +++ b/src/pkg/image/color.go @@ -113,12 +113,12 @@ type ColorModel interface { type ColorModelFunc func(Color) Color func (f ColorModelFunc) Convert(c Color) Color { - return f(c); + return f(c) } func toRGBAColor(c Color) Color { if _, ok := c.(RGBAColor); ok { // no-op conversion - return c; + return c } r, g, b, a := c.RGBA(); return RGBAColor{uint8(r>>24), uint8(g>>24), uint8(b>>24), uint8(a>>24)}; @@ -126,7 +126,7 @@ func toRGBAColor(c Color) Color { func toRGBA64Color(c Color) Color { if _, ok := c.(RGBA64Color); ok { // no-op conversion - return c; + return c } r, g, b, a := c.RGBA(); return RGBA64Color{uint16(r>>16), uint16(g>>16), uint16(b>>16), uint16(a>>16)}; @@ -134,15 +134,15 @@ func toRGBA64Color(c Color) Color { func toNRGBAColor(c Color) Color { if _, ok := c.(NRGBAColor); ok { // no-op conversion - return c; + return c } r, g, b, a := c.RGBA(); a >>= 16; if a == 0xffff { - return NRGBAColor{uint8(r>>24), uint8(g>>24), uint8(b>>24), 0xff}; + return NRGBAColor{uint8(r>>24), uint8(g>>24), uint8(b>>24), 0xff} } if a == 0 { - return NRGBAColor{0, 0, 0, 0}; + return NRGBAColor{0, 0, 0, 0} } r >>= 16; g >>= 16; @@ -156,7 +156,7 @@ func toNRGBAColor(c Color) Color { func toNRGBA64Color(c Color) Color { if _, ok := c.(NRGBA64Color); ok { // no-op conversion - return c; + return c } r, g, b, a := c.RGBA(); a >>= 16; @@ -164,10 +164,10 @@ func toNRGBA64Color(c Color) Color { g >>= 16; b >>= 16; if a == 0xffff { - return NRGBA64Color{uint16(r), uint16(g), uint16(b), 0xffff}; + return NRGBA64Color{uint16(r), uint16(g), uint16(b), 0xffff} } if a == 0 { - return NRGBA64Color{0, 0, 0, 0}; + return NRGBA64Color{0, 0, 0, 0} } // Since Color.RGBA returns a alpha-premultiplied color, we should have r <= a && g <= a && b <= a. r = (r*0xffff)/a; diff --git a/src/pkg/image/image.go b/src/pkg/image/image.go index 80dbb8636..49d7f5a4d 100644 --- a/src/pkg/image/image.go +++ b/src/pkg/image/image.go @@ -25,7 +25,7 @@ func (p *RGBA) ColorModel() ColorModel { return RGBAColorModel } func (p *RGBA) Width() int { if len(p.Pixel) == 0 { - return 0; + return 0 } return len(p.Pixel[0]); } @@ -40,7 +40,7 @@ func (p *RGBA) Set(x, y int, c Color) { p.Pixel[y][x] = toRGBAColor(c).(RGBAColo func NewRGBA(w, h int) *RGBA { pixel := make([][]RGBAColor, h); for y := 0; y < int(h); y++ { - pixel[y] = make([]RGBAColor, w); + pixel[y] = make([]RGBAColor, w) } return &RGBA{pixel}; } @@ -55,7 +55,7 @@ func (p *RGBA64) ColorModel() ColorModel { return RGBA64ColorModel } func (p *RGBA64) Width() int { if len(p.Pixel) == 0 { - return 0; + return 0 } return len(p.Pixel[0]); } @@ -70,7 +70,7 @@ func (p *RGBA64) Set(x, y int, c Color) { p.Pixel[y][x] = toRGBA64Color(c).(RGBA func NewRGBA64(w, h int) *RGBA64 { pixel := make([][]RGBA64Color, h); for y := 0; y < int(h); y++ { - pixel[y] = make([]RGBA64Color, w); + pixel[y] = make([]RGBA64Color, w) } return &RGBA64{pixel}; } @@ -85,7 +85,7 @@ func (p *NRGBA) ColorModel() ColorModel { return NRGBAColorModel } func (p *NRGBA) Width() int { if len(p.Pixel) == 0 { - return 0; + return 0 } return len(p.Pixel[0]); } @@ -100,7 +100,7 @@ func (p *NRGBA) Set(x, y int, c Color) { p.Pixel[y][x] = toNRGBAColor(c).(NRGBAC func NewNRGBA(w, h int) *NRGBA { pixel := make([][]NRGBAColor, h); for y := 0; y < int(h); y++ { - pixel[y] = make([]NRGBAColor, w); + pixel[y] = make([]NRGBAColor, w) } return &NRGBA{pixel}; } @@ -115,7 +115,7 @@ func (p *NRGBA64) ColorModel() ColorModel { return NRGBA64ColorModel } func (p *NRGBA64) Width() int { if len(p.Pixel) == 0 { - return 0; + return 0 } return len(p.Pixel[0]); } @@ -130,7 +130,7 @@ func (p *NRGBA64) Set(x, y int, c Color) { p.Pixel[y][x] = toNRGBA64Color(c).(NR func NewNRGBA64(w, h int) *NRGBA64 { pixel := make([][]NRGBA64Color, h); for y := 0; y < int(h); y++ { - pixel[y] = make([]NRGBA64Color, w); + pixel[y] = make([]NRGBA64Color, w) } return &NRGBA64{pixel}; } @@ -140,7 +140,7 @@ type PalettedColorModel []Color func diff(a, b uint32) uint32 { if a > b { - return a-b; + return a-b } return b-a; } @@ -148,7 +148,7 @@ func diff(a, b uint32) uint32 { // Convert returns the palette color closest to c in Euclidean R,G,B space. func (p PalettedColorModel) Convert(c Color) Color { if len(p) == 0 { - return nil; + return nil } // TODO(nigeltao): Revisit the "pick the palette color which minimizes sum-squared-difference" // algorithm when the premultiplied vs unpremultiplied issue is resolved. @@ -186,7 +186,7 @@ func (p *Paletted) ColorModel() ColorModel { return p.Palette } func (p *Paletted) Width() int { if len(p.Pixel) == 0 { - return 0; + return 0 } return len(p.Pixel[0]); } @@ -196,18 +196,18 @@ func (p *Paletted) Height() int { return len(p.Pixel) } func (p *Paletted) At(x, y int) Color { return p.Palette[p.Pixel[y][x]] } func (p *Paletted) ColorIndexAt(x, y int) uint8 { - return p.Pixel[y][x]; + return p.Pixel[y][x] } func (p *Paletted) SetColorIndex(x, y int, index uint8) { - p.Pixel[y][x] = index; + p.Pixel[y][x] = index } // 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 < int(h); y++ { - pixel[y] = make([]uint8, w); + pixel[y] = make([]uint8, w) } return &Paletted{pixel, m}; } diff --git a/src/pkg/image/png/reader.go b/src/pkg/image/png/reader.go index 9ea338d07..e8eba566a 100644 --- a/src/pkg/image/png/reader.go +++ b/src/pkg/image/png/reader.go @@ -81,57 +81,57 @@ func (e UnsupportedError) String() string { return "unsupported PNG feature: " + // Big-endian. func parseUint32(b []uint8) uint32 { - return uint32(b[0])<<24 | uint32(b[1])<<16 | uint32(b[2])<<8 | uint32(b[3]); + return uint32(b[0])<<24 | uint32(b[1])<<16 | uint32(b[2])<<8 | uint32(b[3]) } func abs(x int) int { if x < 0 { - return -x; + return -x } return x; } func min(a, b int) int { if a < b { - return a; + return a } return b; } func (d *decoder) parseIHDR(r io.Reader, crc hash.Hash32, length uint32) os.Error { if length != 13 { - return FormatError("bad IHDR length"); + return FormatError("bad IHDR length") } _, err := io.ReadFull(r, d.tmp[0:13]); if err != nil { - return err; + return err } crc.Write(d.tmp[0:13]); if d.tmp[8] != 8 { - return UnsupportedError("bit depth"); + return UnsupportedError("bit depth") } if d.tmp[10] != 0 || d.tmp[11] != 0 || d.tmp[12] != 0 { - return UnsupportedError("compression, filter or interlace method"); + return UnsupportedError("compression, filter or interlace method") } w := int32(parseUint32(d.tmp[0:4])); h := int32(parseUint32(d.tmp[4:8])); if w < 0 || h < 0 { - return FormatError("negative dimension"); + return FormatError("negative dimension") } nPixels := int64(w)*int64(h); if nPixels != int64(int(nPixels)) { - return UnsupportedError("dimension overflow"); + return UnsupportedError("dimension overflow") } d.colorType = d.tmp[9]; switch d.colorType { case ctTrueColor: - d.image = image.NewRGBA(int(w), int(h)); + d.image = image.NewRGBA(int(w), int(h)) case ctPaletted: - d.image = image.NewPaletted(int(w), int(h), nil); + d.image = image.NewPaletted(int(w), int(h), nil) case ctTrueColorAlpha: - d.image = image.NewNRGBA(int(w), int(h)); + d.image = image.NewNRGBA(int(w), int(h)) default: - return UnsupportedError("color type"); + return UnsupportedError("color type") } d.width, d.height = int(w), int(h); return nil; @@ -140,26 +140,26 @@ func (d *decoder) parseIHDR(r io.Reader, crc hash.Hash32, length uint32) os.Erro func (d *decoder) parsePLTE(r io.Reader, crc hash.Hash32, length uint32) os.Error { np := int(length/3); // The number of palette entries. if length%3 != 0 || np <= 0 || np > 256 { - return FormatError("bad PLTE length"); + return FormatError("bad PLTE length") } n, err := io.ReadFull(r, d.tmp[0 : 3*np]); if err != nil { - return err; + return err } crc.Write(d.tmp[0:n]); switch d.colorType { case ctPaletted: palette := make([]image.Color, np); for i := 0; i < np; i++ { - palette[i] = image.RGBAColor{d.tmp[3*i + 0], d.tmp[3*i + 1], d.tmp[3*i + 2], 0xff}; + palette[i] = image.RGBAColor{d.tmp[3*i + 0], d.tmp[3*i + 1], d.tmp[3*i + 2], 0xff} } d.image.(*image.Paletted).Palette = image.PalettedColorModel(palette); case ctTrueColor, ctTrueColorAlpha: // As per the PNG spec, a PLTE chunk is optional (and for practical purposes, // ignorable) for the ctTrueColor and ctTrueColorAlpha color types (section 4.1.2). - return nil; + return nil default: - return FormatError("PLTE, color type mismatch"); + return FormatError("PLTE, color type mismatch") } return nil; } @@ -171,9 +171,9 @@ func paeth(a, b, c uint8) uint8 { pb := abs(p-int(b)); pc := abs(p-int(c)); if pa <= pb && pa <= pc { - return a; + return a } else if pb <= pc { - return b; + return b } return c; } @@ -181,7 +181,7 @@ func paeth(a, b, c uint8) uint8 { func (d *decoder) idatReader(idat io.Reader) os.Error { r, err := zlib.NewInflater(idat); if err != nil { - return err; + return err } defer r.Close(); bpp := 0; // Bytes per pixel. @@ -212,7 +212,7 @@ func (d *decoder) idatReader(idat io.Reader) os.Error { // Read the decompressed bytes. _, err := io.ReadFull(r, cr); if err != nil { - return err; + return err } // Apply the filter. @@ -223,46 +223,46 @@ func (d *decoder) idatReader(idat io.Reader) os.Error { // No-op. case ftSub: for i := bpp; i < len(cdat); i++ { - cdat[i] += cdat[i-bpp]; + cdat[i] += cdat[i-bpp] } case ftUp: for i := 0; i < len(cdat); i++ { - cdat[i] += pdat[i]; + cdat[i] += pdat[i] } case ftAverage: for i := 0; i < bpp; i++ { - cdat[i] += pdat[i]/2; + cdat[i] += pdat[i]/2 } for i := bpp; i < len(cdat); i++ { - cdat[i] += uint8((int(cdat[i-bpp])+int(pdat[i]))/2); + cdat[i] += uint8((int(cdat[i-bpp])+int(pdat[i]))/2) } case ftPaeth: for i := 0; i < bpp; i++ { - cdat[i] += paeth(0, pdat[i], 0); + cdat[i] += paeth(0, pdat[i], 0) } for i := bpp; i < len(cdat); i++ { - cdat[i] += paeth(cdat[i-bpp], pdat[i], pdat[i-bpp]); + cdat[i] += paeth(cdat[i-bpp], pdat[i], pdat[i-bpp]) } default: - return FormatError("bad filter type"); + return FormatError("bad filter type") } // Convert from bytes to colors. switch d.colorType { case ctTrueColor: for x := 0; x < d.width; x++ { - rgba.Set(x, y, image.RGBAColor{cdat[3*x + 0], cdat[3*x + 1], cdat[3*x + 2], 0xff}); + rgba.Set(x, y, image.RGBAColor{cdat[3*x + 0], cdat[3*x + 1], cdat[3*x + 2], 0xff}) } case ctPaletted: for x := 0; x < d.width; x++ { if cdat[x] > maxPalette { - return FormatError("palette index out of range"); + return FormatError("palette index out of range") } paletted.SetColorIndex(x, y, cdat[x]); } case ctTrueColorAlpha: for x := 0; x < d.width; x++ { - nrgba.Set(x, y, image.NRGBAColor{cdat[4*x + 0], cdat[4*x + 1], cdat[4*x + 2], cdat[4*x + 3]}); + nrgba.Set(x, y, image.NRGBAColor{cdat[4*x + 0], cdat[4*x + 1], cdat[4*x + 2], cdat[4*x + 3]}) } } @@ -285,7 +285,7 @@ func (d *decoder) parseIDAT(r io.Reader, crc hash.Hash32, length uint32) os.Erro go func() { err := d.idatReader(pr); if err == os.EOF { - err = FormatError("too little IDAT"); + err = FormatError("too little IDAT") } pr.CloseWithError(FormatError("too much IDAT")); d.idatDone <- err; @@ -299,10 +299,10 @@ func (d *decoder) parseIDAT(r io.Reader, crc hash.Hash32, length uint32) os.Erro // want to report that error, and not the one that made the Read stop. n, err2 := d.idatWriter.Write(buf[0:n]); if err2 != nil { - return err2; + return err2 } if err1 != nil { - return err1; + return err1 } crc.Write(buf[0:n]); length -= uint32(n); @@ -312,7 +312,7 @@ func (d *decoder) parseIDAT(r io.Reader, crc hash.Hash32, length uint32) os.Erro func (d *decoder) parseIEND(r io.Reader, crc hash.Hash32, length uint32) os.Error { if length != 0 { - return FormatError("bad IEND length"); + return FormatError("bad IEND length") } return nil; } @@ -321,20 +321,20 @@ func (d *decoder) parseChunk(r io.Reader) os.Error { // Read the length. n, err := io.ReadFull(r, d.tmp[0:4]); if err == os.EOF { - return io.ErrUnexpectedEOF; + return io.ErrUnexpectedEOF } if err != nil { - return err; + return err } length := parseUint32(d.tmp[0:4]); // Read the chunk type. n, err = io.ReadFull(r, d.tmp[0:4]); if err == os.EOF { - return io.ErrUnexpectedEOF; + return io.ErrUnexpectedEOF } if err != nil { - return err; + return err } crc := crc32.NewIEEE(); crc.Write(d.tmp[0:4]); @@ -343,25 +343,25 @@ func (d *decoder) parseChunk(r io.Reader) os.Error { switch string(d.tmp[0:4]) { case "IHDR": if d.stage != dsStart { - return chunkOrderError; + return chunkOrderError } d.stage = dsSeenIHDR; err = d.parseIHDR(r, crc, length); case "PLTE": if d.stage != dsSeenIHDR { - return chunkOrderError; + return chunkOrderError } d.stage = dsSeenPLTE; err = d.parsePLTE(r, crc, length); case "IDAT": if d.stage < dsSeenIHDR || d.stage > dsSeenIDAT || (d.colorType == ctPaletted && d.stage == dsSeenIHDR) { - return chunkOrderError; + return chunkOrderError } d.stage = dsSeenIDAT; err = d.parseIDAT(r, crc, length); case "IEND": if d.stage != dsSeenIDAT { - return chunkOrderError; + return chunkOrderError } d.stage = dsSeenIEND; err = d.parseIEND(r, crc, length); @@ -371,26 +371,26 @@ func (d *decoder) parseChunk(r io.Reader) os.Error { for length > 0 { n, err = io.ReadFull(r, ignored[0 : min(len(ignored), int(length))]); if err != nil { - return err; + return err } crc.Write(ignored[0:n]); length -= uint32(n); } } if err != nil { - return err; + return err } // Read the checksum. n, err = io.ReadFull(r, d.tmp[0:4]); if err == os.EOF { - return io.ErrUnexpectedEOF; + return io.ErrUnexpectedEOF } if err != nil { - return err; + return err } if parseUint32(d.tmp[0:4]) != crc.Sum32() { - return FormatError("invalid checksum"); + return FormatError("invalid checksum") } return nil; } @@ -398,10 +398,10 @@ func (d *decoder) parseChunk(r io.Reader) os.Error { func (d *decoder) checkHeader(r io.Reader) os.Error { _, err := io.ReadFull(r, d.tmp[0:8]); if err != nil { - return err; + return err } if string(d.tmp[0:8]) != pngHeader { - return FormatError("not a PNG file"); + return FormatError("not a PNG file") } return nil; } @@ -412,23 +412,23 @@ func Decode(r io.Reader) (image.Image, os.Error) { var d decoder; err := d.checkHeader(r); if err != nil { - return nil, err; + return nil, err } for d.stage = dsStart; d.stage != dsSeenIEND; { err = d.parseChunk(r); if err != nil { - break; + break } } if d.idatWriter != nil { d.idatWriter.Close(); err1 := <-d.idatDone; if err == nil { - err = err1; + err = err1 } } if err != nil { - return nil, err; + return nil, err } return d.image, nil; } diff --git a/src/pkg/image/png/reader_test.go b/src/pkg/image/png/reader_test.go index 97383fdbd..97b4e8ec6 100644 --- a/src/pkg/image/png/reader_test.go +++ b/src/pkg/image/png/reader_test.go @@ -36,7 +36,7 @@ var filenames = []string{ func readPng(filename string) (image.Image, os.Error) { f, err := os.Open(filename, os.O_RDONLY, 0444); if err != nil { - return nil, err; + return nil, err } defer f.Close(); return Decode(f); @@ -56,14 +56,14 @@ func sng(w io.WriteCloser, filename string, png image.Image) { cpm, _ := cm.(image.PalettedColorModel); switch { case cm == image.RGBAColorModel: - io.WriteString(w, " using color;\n"); + io.WriteString(w, " using color;\n") case cm == image.NRGBAColorModel: - io.WriteString(w, " using color alpha;\n"); + io.WriteString(w, " using color alpha;\n") case cpm != nil: io.WriteString(w, " using color palette;\n"); paletted = png.(*image.Paletted); default: - io.WriteString(w, "unknown PNG decoder color model\n"); + io.WriteString(w, "unknown PNG decoder color model\n") } io.WriteString(w, "}\n"); @@ -100,7 +100,7 @@ func sng(w io.WriteCloser, filename string, png image.Image) { } case cpm != nil: for x := 0; x < png.Width(); x++ { - fmt.Fprintf(w, "%02x", paletted.ColorIndexAt(x, y)); + fmt.Fprintf(w, "%02x", paletted.ColorIndexAt(x, y)) } } io.WriteString(w, "\n"); @@ -139,7 +139,7 @@ func TestReader(t *testing.T) { ps, perr := pb.ReadString('\n'); ss, serr := sb.ReadString('\n'); if perr == os.EOF && serr == os.EOF { - break; + break } if perr != nil { t.Error(fn, perr); diff --git a/src/pkg/image/png/writer.go b/src/pkg/image/png/writer.go index ceb72598e..8c8a41537 100644 --- a/src/pkg/image/png/writer.go +++ b/src/pkg/image/png/writer.go @@ -38,7 +38,7 @@ func opaque(m image.Image) bool { for x := 0; x < m.Width(); x++ { _, _, _, a := m.At(x, y).RGBA(); if a != 0xffffffff { - return false; + return false } } } @@ -48,14 +48,14 @@ func opaque(m image.Image) bool { // The absolute value of a byte interpreted as a signed int8. func abs8(d uint8) int { if d < 128 { - return int(d); + return int(d) } return 256-int(d); } func (e *encoder) writeChunk(b []byte, name string) { if e.err != nil { - return; + return } n := uint32(len(b)); if int(n) != len(b) { @@ -74,11 +74,11 @@ func (e *encoder) writeChunk(b []byte, name string) { _, e.err = e.w.Write(e.header[0:8]); if e.err != nil { - return; + return } _, e.err = e.w.Write(b); if e.err != nil { - return; + return } _, e.err = e.w.Write(e.footer[0:4]); } @@ -125,7 +125,7 @@ func (e *encoder) writePLTE(p image.PalettedColorModel) { func (e *encoder) Write(b []byte) (int, os.Error) { e.writeChunk(b, "IDAT"); if e.err != nil { - return 0, e.err; + return 0, e.err } return len(b), nil; } @@ -164,7 +164,7 @@ func filter(cr [][]byte, pr []byte, bpp int) int { cdat4[i] = cdat0[i] - paeth(cdat0[i-bpp], pdat[i], pdat[i-bpp]); sum += abs8(cdat4[i]); if sum >= best { - break; + break } } if sum < best { @@ -177,7 +177,7 @@ func filter(cr [][]byte, pr []byte, bpp int) int { for i := 0; i < n; i++ { sum += abs8(cdat0[i]); if sum >= best { - break; + break } } if sum < best { @@ -195,7 +195,7 @@ func filter(cr [][]byte, pr []byte, bpp int) int { cdat1[i] = cdat0[i]-cdat0[i-bpp]; sum += abs8(cdat1[i]); if sum >= best { - break; + break } } if sum < best { @@ -213,7 +213,7 @@ func filter(cr [][]byte, pr []byte, bpp int) int { cdat3[i] = cdat0[i]-uint8((int(cdat0[i-bpp])+int(pdat[i]))/2); sum += abs8(cdat3[i]); if sum >= best { - break; + break } } if sum < best { @@ -227,7 +227,7 @@ func filter(cr [][]byte, pr []byte, bpp int) int { func writeImage(w io.Writer, m image.Image, ct uint8) os.Error { zw, err := zlib.NewDeflater(w); if err != nil { - return err; + return err } defer zw.Close(); @@ -235,12 +235,12 @@ func writeImage(w io.Writer, m image.Image, ct uint8) os.Error { var paletted *image.Paletted; switch ct { case ctTrueColor: - bpp = 3; + bpp = 3 case ctPaletted: bpp = 1; paletted = m.(*image.Paletted); case ctTrueColorAlpha: - bpp = 4; + bpp = 4 } // cr[*] and pr are the bytes for the current and previous row. // cr[0] is unfiltered (or equivalently, filtered with the ftNone filter). @@ -267,7 +267,7 @@ func writeImage(w io.Writer, m image.Image, ct uint8) os.Error { } case ctPaletted: for x := 0; x < m.Width(); x++ { - cr[0][x+1] = paletted.ColorIndexAt(x, y); + cr[0][x+1] = paletted.ColorIndexAt(x, y) } case ctTrueColorAlpha: // Convert from image.Image (which is alpha-premultiplied) to PNG's non-alpha-premultiplied. @@ -286,7 +286,7 @@ func writeImage(w io.Writer, m image.Image, ct uint8) os.Error { // Write the compressed bytes. _, err = zw.Write(cr[f]); if err != nil { - return err; + return err } // The current row for y is the previous row for y+1. @@ -298,16 +298,16 @@ func writeImage(w io.Writer, m image.Image, ct uint8) os.Error { // Write the actual image data to one or more IDAT chunks. func (e *encoder) writeIDATs() { if e.err != nil { - return; + return } var bw *bufio.Writer; bw, e.err = bufio.NewWriterSize(e, 1<<15); if e.err != nil { - return; + return } e.err = writeImage(bw, e.m, e.colorType); if e.err != nil { - return; + return } e.err = bw.Flush(); } @@ -322,7 +322,7 @@ func Encode(w io.Writer, m image.Image) os.Error { // also rejected. mw, mh := int64(m.Width()), int64(m.Height()); 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)) } var e encoder; @@ -331,15 +331,15 @@ func Encode(w io.Writer, m image.Image) os.Error { e.colorType = uint8(ctTrueColorAlpha); pal, _ := m.(*image.Paletted); if pal != nil { - e.colorType = ctPaletted; + e.colorType = ctPaletted } else if opaque(m) { - e.colorType = ctTrueColor; + e.colorType = ctTrueColor } _, e.err = io.WriteString(w, pngHeader); e.writeIHDR(); if pal != nil { - e.writePLTE(pal.Palette); + e.writePLTE(pal.Palette) } e.writeIDATs(); e.writeIEND(); diff --git a/src/pkg/image/png/writer_test.go b/src/pkg/image/png/writer_test.go index b832f1c26..db50a9872 100644 --- a/src/pkg/image/png/writer_test.go +++ b/src/pkg/image/png/writer_test.go @@ -14,14 +14,14 @@ import ( func diff(m0, m1 image.Image) os.Error { if m0.Width() != m1.Width() || m0.Height() != m1.Height() { - return os.NewError(fmt.Sprintf("dimensions differ: %dx%d vs %dx%d", m0.Width(), m0.Height(), m1.Width(), m1.Height())); + return os.NewError(fmt.Sprintf("dimensions differ: %dx%d vs %dx%d", m0.Width(), m0.Height(), m1.Width(), m1.Height())) } for y := 0; y < m0.Height(); y++ { for x := 0; x < m0.Width(); x++ { r0, g0, b0, a0 := m0.At(x, y).RGBA(); r1, g1, b1, a1 := m1.At(x, y).RGBA(); if r0 != r1 || g0 != g1 || b0 != b1 || a0 != a1 { - return os.NewError(fmt.Sprintf("colors differ at (%d, %d): %v vs %v", x, y, m0.At(x, y), m1.At(x, y))); + return os.NewError(fmt.Sprintf("colors differ at (%d, %d): %v vs %v", x, y, m0.At(x, y), m1.At(x, y))) } } } |