diff options
author | Robert Griesemer <gri@golang.org> | 2009-11-09 21:23:52 -0800 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2009-11-09 21:23:52 -0800 |
commit | 9aad19327eb719775a874f8f18bb15958db1d471 (patch) | |
tree | c515081857e0b9ad897c6d35b0be64fe4c346688 /src/pkg/image/png | |
parent | 073e240233589933c43143c997247c33206bb066 (diff) | |
download | golang-9aad19327eb719775a874f8f18bb15958db1d471.tar.gz |
- replaced gofmt expression formatting algorithm with
rsc's algorithm
- applied gofmt -w misc src
- partial CL (last chunk)
R=rsc, r
http://go/go-review/1024041
Diffstat (limited to 'src/pkg/image/png')
-rw-r--r-- | src/pkg/image/png/reader.go | 36 | ||||
-rw-r--r-- | src/pkg/image/png/reader_test.go | 4 | ||||
-rw-r--r-- | src/pkg/image/png/writer.go | 44 |
3 files changed, 42 insertions, 42 deletions
diff --git a/src/pkg/image/png/reader.go b/src/pkg/image/png/reader.go index e8eba566a..ac35df810 100644 --- a/src/pkg/image/png/reader.go +++ b/src/pkg/image/png/reader.go @@ -57,7 +57,7 @@ type decoder struct { stage int; idatWriter io.WriteCloser; idatDone chan os.Error; - tmp [3*256]byte; + tmp [3 * 256]byte; } // A FormatError reports that the input is not a valid PNG. @@ -118,7 +118,7 @@ func (d *decoder) parseIHDR(r io.Reader, crc hash.Hash32, length uint32) os.Erro if w < 0 || h < 0 { return FormatError("negative dimension") } - nPixels := int64(w)*int64(h); + nPixels := int64(w) * int64(h); if nPixels != int64(int(nPixels)) { return UnsupportedError("dimension overflow") } @@ -138,11 +138,11 @@ 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. + np := int(length / 3); // The number of palette entries. if length%3 != 0 || np <= 0 || np > 256 { return FormatError("bad PLTE length") } - n, err := io.ReadFull(r, d.tmp[0 : 3*np]); + n, err := io.ReadFull(r, d.tmp[0:3*np]); if err != nil { return err } @@ -151,7 +151,7 @@ func (d *decoder) parsePLTE(r io.Reader, crc hash.Hash32, length uint32) os.Erro 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: @@ -166,10 +166,10 @@ func (d *decoder) parsePLTE(r io.Reader, crc hash.Hash32, length uint32) os.Erro // The Paeth filter function, as per the PNG specification. func paeth(a, b, c uint8) uint8 { - p := int(a)+int(b)-int(c); - pa := abs(p-int(a)); - pb := abs(p-int(b)); - pc := abs(p-int(c)); + p := int(a) + int(b) - int(c); + pa := abs(p - int(a)); + pb := abs(p - int(b)); + pc := abs(p - int(c)); if pa <= pb && pa <= pc { return a } else if pb <= pc { @@ -198,15 +198,15 @@ func (d *decoder) idatReader(idat io.Reader) os.Error { case ctPaletted: bpp = 1; paletted = d.image.(*image.Paletted); - maxPalette = uint8(len(paletted.Palette)-1); + maxPalette = uint8(len(paletted.Palette) - 1); case ctTrueColorAlpha: bpp = 4; nrgba = d.image.(*image.NRGBA); } // cr and pr are the bytes for the current and previous row. // The +1 is for the per-row filter type, which is at cr[0]. - cr := make([]uint8, 1 + bpp * d.width); - pr := make([]uint8, 1 + bpp * d.width); + cr := make([]uint8, 1+bpp*d.width); + pr := make([]uint8, 1+bpp*d.width); for y := 0; y < d.height; y++ { // Read the decompressed bytes. @@ -231,10 +231,10 @@ func (d *decoder) idatReader(idat io.Reader) os.Error { } 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++ { @@ -251,7 +251,7 @@ func (d *decoder) idatReader(idat io.Reader) os.Error { 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++ { @@ -262,7 +262,7 @@ func (d *decoder) idatReader(idat io.Reader) os.Error { } 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]}) } } @@ -293,7 +293,7 @@ func (d *decoder) parseIDAT(r io.Reader, crc hash.Hash32, length uint32) os.Erro } var buf [4096]byte; for length > 0 { - n, err1 := r.Read(buf[0 : min(len(buf), int(length))]); + n, err1 := r.Read(buf[0:min(len(buf), int(length))]); // We delay checking err1. It is possible to get n bytes and an error, // but if the n bytes themselves contain a FormatError, for example, we // want to report that error, and not the one that made the Read stop. @@ -369,7 +369,7 @@ func (d *decoder) parseChunk(r io.Reader) os.Error { // Ignore this chunk (of a known length). var ignored [4096]byte; for length > 0 { - n, err = io.ReadFull(r, ignored[0 : min(len(ignored), int(length))]); + n, err = io.ReadFull(r, ignored[0:min(len(ignored), int(length))]); if err != nil { return err } diff --git a/src/pkg/image/png/reader_test.go b/src/pkg/image/png/reader_test.go index 97b4e8ec6..2885b3344 100644 --- a/src/pkg/image/png/reader_test.go +++ b/src/pkg/image/png/reader_test.go @@ -49,7 +49,7 @@ func sng(w io.WriteCloser, filename string, png image.Image) { bitdepth := 8; // Write the filename and IHDR. - io.WriteString(w, "#SNG: from " + filename + ".png\nIHDR {\n"); + io.WriteString(w, "#SNG: from "+filename+".png\nIHDR {\n"); fmt.Fprintf(w, " width: %d; height: %d; bitdepth: %d;\n", png.Width(), png.Height(), bitdepth); cm := png.ColorModel(); var paletted *image.Paletted; @@ -122,7 +122,7 @@ func TestReader(t *testing.T) { defer piper.Close(); // Read the .sng file. - sf, err := os.Open("testdata/pngsuite/" + fn + ".sng", os.O_RDONLY, 0444); + sf, err := os.Open("testdata/pngsuite/"+fn+".sng", os.O_RDONLY, 0444); if err != nil { t.Error(fn, err); continue; diff --git a/src/pkg/image/png/writer.go b/src/pkg/image/png/writer.go index 8c8a41537..08d09f135 100644 --- a/src/pkg/image/png/writer.go +++ b/src/pkg/image/png/writer.go @@ -21,15 +21,15 @@ type encoder struct { err os.Error; header [8]byte; footer [4]byte; - tmp [3*256]byte; + tmp [3 * 256]byte; } // Big-endian. func writeUint32(b []uint8, u uint32) { - b[0] = uint8(u>>24); - b[1] = uint8(u>>16); - b[2] = uint8(u>>8); - b[3] = uint8(u>>0); + b[0] = uint8(u >> 24); + b[1] = uint8(u >> 16); + b[2] = uint8(u >> 8); + b[3] = uint8(u >> 0); } // Returns whether or not the image is fully opaque. @@ -50,7 +50,7 @@ func abs8(d uint8) int { if d < 128 { return int(d) } - return 256-int(d); + return 256 - int(d); } func (e *encoder) writeChunk(b []byte, name string) { @@ -105,11 +105,11 @@ func (e *encoder) writePLTE(p image.PalettedColorModel) { e.err = UnsupportedError("non-opaque palette color"); return; } - e.tmp[3*i + 0] = uint8(r>>24); - e.tmp[3*i + 1] = uint8(g>>24); - e.tmp[3*i + 2] = uint8(b>>24); + e.tmp[3*i+0] = uint8(r >> 24); + e.tmp[3*i+1] = uint8(g >> 24); + e.tmp[3*i+2] = uint8(b >> 24); } - e.writeChunk(e.tmp[0 : 3*len(p)], "PLTE"); + e.writeChunk(e.tmp[0:3*len(p)], "PLTE"); } // An encoder is an io.Writer that satisfies writes by writing PNG IDAT chunks, @@ -148,7 +148,7 @@ func filter(cr [][]byte, pr []byte, bpp int) int { // The up filter. sum := 0; for i := 0; i < n; i++ { - cdat2[i] = cdat0[i]-pdat[i]; + cdat2[i] = cdat0[i] - pdat[i]; sum += abs8(cdat2[i]); } best := sum; @@ -192,7 +192,7 @@ func filter(cr [][]byte, pr []byte, bpp int) int { sum += abs8(cdat1[i]); } for i := bpp; i < n; i++ { - cdat1[i] = cdat0[i]-cdat0[i-bpp]; + cdat1[i] = cdat0[i] - cdat0[i-bpp]; sum += abs8(cdat1[i]); if sum >= best { break @@ -210,7 +210,7 @@ func filter(cr [][]byte, pr []byte, bpp int) int { sum += abs8(cdat3[i]); } for i := bpp; i < n; i++ { - cdat3[i] = cdat0[i]-uint8((int(cdat0[i-bpp])+int(pdat[i]))/2); + cdat3[i] = cdat0[i] - uint8((int(cdat0[i-bpp])+int(pdat[i]))/2); sum += abs8(cdat3[i]); if sum >= best { break @@ -249,10 +249,10 @@ func writeImage(w io.Writer, m image.Image, ct uint8) os.Error { // The +1 is for the per-row filter type, which is at cr[*][0]. var cr [nFilter][]uint8; for i := 0; i < len(cr); i++ { - cr[i] = make([]uint8, 1 + bpp * m.Width()); + cr[i] = make([]uint8, 1+bpp*m.Width()); cr[i][0] = uint8(i); } - pr := make([]uint8, 1 + bpp * m.Width()); + pr := make([]uint8, 1+bpp*m.Width()); for y := 0; y < m.Height(); y++ { // Convert from colors to bytes. @@ -261,9 +261,9 @@ func writeImage(w io.Writer, m image.Image, ct uint8) os.Error { for x := 0; x < m.Width(); x++ { // We have previously verified that the alpha value is fully opaque. r, g, b, _ := m.At(x, y).RGBA(); - cr[0][3*x + 1] = uint8(r>>24); - cr[0][3*x + 2] = uint8(g>>24); - cr[0][3*x + 3] = uint8(b>>24); + cr[0][3*x+1] = uint8(r >> 24); + cr[0][3*x+2] = uint8(g >> 24); + cr[0][3*x+3] = uint8(b >> 24); } case ctPaletted: for x := 0; x < m.Width(); x++ { @@ -273,10 +273,10 @@ func writeImage(w io.Writer, m image.Image, ct uint8) os.Error { // Convert from image.Image (which is alpha-premultiplied) to PNG's non-alpha-premultiplied. for x := 0; x < m.Width(); x++ { c := image.NRGBAColorModel.Convert(m.At(x, y)).(image.NRGBAColor); - cr[0][4*x + 1] = c.R; - cr[0][4*x + 2] = c.G; - cr[0][4*x + 3] = c.B; - cr[0][4*x + 4] = c.A; + cr[0][4*x+1] = c.R; + cr[0][4*x+2] = c.G; + cr[0][4*x+3] = c.B; + cr[0][4*x+4] = c.A; } } |