diff options
author | Russ Cox <rsc@golang.org> | 2009-10-06 19:41:51 -0700 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2009-10-06 19:41:51 -0700 |
commit | 6c2652e6fd54ce34ca3be95540c54cebb52bfece (patch) | |
tree | 2366cc62ab4dee2e5698d6d6e5b299d6819a7edd /src/pkg/image | |
parent | db62e99a735a036afda2098f1a721fe8dbf6ce76 (diff) | |
download | golang-6c2652e6fd54ce34ca3be95540c54cebb52bfece.tar.gz |
apply gofmt to go, gob, hash, http, image, io, json, log
R=gri
DELTA=1359 (138 added, 32 deleted, 1189 changed)
OCL=35408
CL=35420
Diffstat (limited to 'src/pkg/image')
-rw-r--r-- | src/pkg/image/color.go | 37 | ||||
-rw-r--r-- | src/pkg/image/image.go | 23 | ||||
-rw-r--r-- | src/pkg/image/png/reader.go | 83 | ||||
-rw-r--r-- | src/pkg/image/png/writer.go | 41 |
4 files changed, 90 insertions, 94 deletions
diff --git a/src/pkg/image/color.go b/src/pkg/image/color.go index 6f2abc6d0..757be84ce 100644 --- a/src/pkg/image/color.go +++ b/src/pkg/image/color.go @@ -121,7 +121,7 @@ func toRGBAColor(c Color) Color { return c; } r, g, b, a := c.RGBA(); - return RGBAColor{ uint8(r>>24), uint8(g>>24), uint8(b>>24), uint8(a>>24) }; + return RGBAColor{uint8(r>>24), uint8(g>>24), uint8(b>>24), uint8(a>>24)}; } func toRGBA64Color(c Color) Color { @@ -129,7 +129,7 @@ func toRGBA64Color(c Color) Color { return c; } r, g, b, a := c.RGBA(); - return RGBA64Color{ uint16(r>>16), uint16(g>>16), uint16(b>>16), uint16(a>>16) }; + return RGBA64Color{uint16(r>>16), uint16(g>>16), uint16(b>>16), uint16(a>>16)}; } func toNRGBAColor(c Color) Color { @@ -139,19 +139,19 @@ func toNRGBAColor(c Color) Color { 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; b >>= 16; // Since Color.RGBA returns a alpha-premultiplied color, we should have r <= a && g <= a && b <= a. - r = (r * 0xffff) / a; - g = (g * 0xffff) / a; - b = (b * 0xffff) / a; - return NRGBAColor{ uint8(r>>8), uint8(g>>8), uint8(b>>8), uint8(a>>8) }; + r = (r*0xffff)/a; + g = (g*0xffff)/a; + b = (b*0xffff)/a; + return NRGBAColor{uint8(r>>8), uint8(g>>8), uint8(b>>8), uint8(a>>8)}; } func toNRGBA64Color(c Color) Color { @@ -164,27 +164,26 @@ 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; - g = (g * 0xffff) / a; - b = (b * 0xffff) / a; - return NRGBA64Color{ uint16(r), uint16(g), uint16(b), uint16(a) }; + r = (r*0xffff)/a; + g = (g*0xffff)/a; + b = (b*0xffff)/a; + return NRGBA64Color{uint16(r), uint16(g), uint16(b), uint16(a)}; } // The ColorModel associated with RGBAColor. -var RGBAColorModel ColorModel = ColorModelFunc(toRGBAColor); +var RGBAColorModel ColorModel = ColorModelFunc(toRGBAColor) // The ColorModel associated with RGBA64Color. -var RGBA64ColorModel ColorModel = ColorModelFunc(toRGBA64Color); +var RGBA64ColorModel ColorModel = ColorModelFunc(toRGBA64Color) // The ColorModel associated with NRGBAColor. -var NRGBAColorModel ColorModel = ColorModelFunc(toNRGBAColor); +var NRGBAColorModel ColorModel = ColorModelFunc(toNRGBAColor) // The ColorModel associated with NRGBA64Color. -var NRGBA64ColorModel ColorModel = ColorModelFunc(toNRGBA64Color); - +var NRGBA64ColorModel ColorModel = ColorModelFunc(toNRGBA64Color) diff --git a/src/pkg/image/image.go b/src/pkg/image/image.go index 10f959da8..2b5d09642 100644 --- a/src/pkg/image/image.go +++ b/src/pkg/image/image.go @@ -50,7 +50,7 @@ func NewRGBA(w, h int) *RGBA { for y := 0; y < int(h); y++ { pixel[y] = make([]RGBAColor, w); } - return &RGBA{ pixel }; + return &RGBA{pixel}; } // An RGBA64 is an in-memory image backed by a 2-D slice of RGBA64Color values. @@ -88,7 +88,7 @@ func NewRGBA64(w, h int) *RGBA64 { for y := 0; y < int(h); y++ { pixel[y] = make([]RGBA64Color, w); } - return &RGBA64{ pixel }; + return &RGBA64{pixel}; } // A NRGBA is an in-memory image backed by a 2-D slice of NRGBAColor values. @@ -126,7 +126,7 @@ func NewNRGBA(w, h int) *NRGBA { for y := 0; y < int(h); y++ { pixel[y] = make([]NRGBAColor, w); } - return &NRGBA{ pixel }; + return &NRGBA{pixel}; } // A NRGBA64 is an in-memory image backed by a 2-D slice of NRGBA64Color values. @@ -164,17 +164,17 @@ func NewNRGBA64(w, h int) *NRGBA64 { for y := 0; y < int(h); y++ { pixel[y] = make([]NRGBA64Color, w); } - return &NRGBA64{ pixel }; + return &NRGBA64{pixel}; } // A PalettedColorModel represents a fixed palette of colors. -type PalettedColorModel []Color; +type PalettedColorModel []Color func diff(a, b uint32) uint32 { if a > b { - return a - b; + return a-b; } - return b - a; + return b-a; } // Convert returns the palette color closest to c in Euclidean R,G,B space. @@ -198,7 +198,7 @@ func (p PalettedColorModel) Convert(c Color) Color { vg >>= 17; vb >>= 17; dr, dg, db := diff(cr, vr), diff(cg, vg), diff(cb, vb); - ssd := (dr * dr) + (dg * dg) + (db * db); + ssd := (dr*dr)+(dg*dg)+(db*db); if ssd < bestSSD { bestSSD = ssd; result = v; @@ -210,8 +210,8 @@ func (p PalettedColorModel) Convert(c Color) Color { // A Paletted is an in-memory image backed by a 2-D slice of uint8 values and a PalettedColorModel. type Paletted struct { // The Pixel field's indices are y first, then x, so that At(x, y) == Palette[Pixel[y][x]]. - Pixel [][]uint8; - Palette PalettedColorModel; + Pixel [][]uint8; + Palette PalettedColorModel; } func (p *Paletted) ColorModel() ColorModel { @@ -247,6 +247,5 @@ func NewPaletted(w, h int, m PalettedColorModel) *Paletted { for y := 0; y < int(h); y++ { pixel[y] = make([]uint8, w); } - return &Paletted{ pixel, m }; + return &Paletted{pixel, m}; } - diff --git a/src/pkg/image/png/reader.go b/src/pkg/image/png/reader.go index ed13abe78..8e6ae489b 100644 --- a/src/pkg/image/png/reader.go +++ b/src/pkg/image/png/reader.go @@ -18,20 +18,20 @@ import ( // Color type, as per the PNG spec. const ( - ctGrayscale = 0; - ctTrueColor = 2; - ctPaletted = 3; - ctGrayscaleAlpha = 4; - ctTrueColorAlpha = 6; + ctGrayscale = 0; + ctTrueColor = 2; + ctPaletted = 3; + ctGrayscaleAlpha = 4; + ctTrueColorAlpha = 6; ) // Filter type, as per the PNG spec. const ( - ftNone = 0; - ftSub = 1; - ftUp = 2; - ftAverage = 3; - ftPaeth = 4; + ftNone = 0; + ftSub = 1; + ftUp = 2; + ftAverage = 3; + ftPaeth = 4; ) // Decoding stage. @@ -40,23 +40,23 @@ const ( // IDAT chunks must be sequential (i.e. they may not have any other chunks // between them). const ( - dsStart = iota; + dsStart = iota; dsSeenIHDR; dsSeenPLTE; dsSeenIDAT; dsSeenIEND; ) -const pngHeader = "\x89PNG\r\n\x1a\n"; +const pngHeader = "\x89PNG\r\n\x1a\n" type decoder struct { - width, height int; - image image.Image; - colorType uint8; - stage int; - idatWriter io.WriteCloser; - idatDone chan os.Error; - tmp [3*256]byte; + width, height int; + image image.Image; + colorType uint8; + stage int; + idatWriter io.WriteCloser; + idatDone chan os.Error; + tmp [3*256]byte; } // A FormatError reports that the input is not a valid PNG. @@ -123,7 +123,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"); } @@ -143,11 +143,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. - if length % 3 != 0 || np <= 0 || np > 256 { + 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; } @@ -156,7 +156,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: @@ -171,10 +171,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 { @@ -192,10 +192,10 @@ func (d *decoder) idatReader(idat io.Reader) os.Error { bpp := 0; // Bytes per pixel. maxPalette := uint8(0); var ( - rgba *image.RGBA; - nrgba *image.NRGBA; - paletted *image.Paletted; - ); + rgba *image.RGBA; + nrgba *image.NRGBA; + paletted *image.Paletted; + ) switch d.colorType { case ctTrueColor: bpp = 3; @@ -227,10 +227,10 @@ func (d *decoder) idatReader(idat io.Reader) os.Error { // Apply the filter. switch filter[0] { case ftNone: - // No-op. + // No-op. case ftSub: for i := bpp; i < n; i++ { - cr[i] += cr[i - bpp]; + cr[i] += cr[i-bpp]; } case ftUp: for i := 0; i < n; i++ { @@ -238,17 +238,17 @@ func (d *decoder) idatReader(idat io.Reader) os.Error { } case ftAverage: for i := 0; i < bpp; i++ { - cr[i] += pr[i] / 2; + cr[i] += pr[i]/2; } for i := bpp; i < n; i++ { - cr[i] += uint8((int(cr[i - bpp]) + int(pr[i])) / 2); + cr[i] += uint8((int(cr[i-bpp])+int(pr[i]))/2); } case ftPaeth: for i := 0; i < bpp; i++ { cr[i] += paeth(0, pr[i], 0); } for i := bpp; i < n; i++ { - cr[i] += paeth(cr[i - bpp], pr[i], pr[i - bpp]); + cr[i] += paeth(cr[i-bpp], pr[i], pr[i-bpp]); } default: return FormatError("bad filter type"); @@ -258,7 +258,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{ cr[3*x+0], cr[3*x+1], cr[3*x+2], 0xff }); + rgba.Set(x, y, image.RGBAColor{cr[3*x + 0], cr[3*x + 1], cr[3*x + 2], 0xff}); } case ctPaletted: for x := 0; x < d.width; x++ { @@ -269,7 +269,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{ cr[4*x+0], cr[4*x+1], cr[4*x+2], cr[4*x+3] }); + nrgba.Set(x, y, image.NRGBAColor{cr[4*x + 0], cr[4*x + 1], cr[4*x + 2], cr[4*x + 3]}); } } @@ -300,7 +300,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. @@ -376,7 +376,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; } @@ -437,4 +437,3 @@ func Decode(r io.Reader) (image.Image, os.Error) { } return d.image, nil; } - diff --git a/src/pkg/image/png/writer.go b/src/pkg/image/png/writer.go index 8ed5e7094..2dbcb1567 100644 --- a/src/pkg/image/png/writer.go +++ b/src/pkg/image/png/writer.go @@ -15,21 +15,21 @@ import ( ) type encoder struct { - w io.Writer; - m image.Image; - colorType uint8; - err os.Error; - header [8]byte; - footer [4]byte; - tmp [3*256]byte; + w io.Writer; + m image.Image; + colorType uint8; + err os.Error; + header [8]byte; + footer [4]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. @@ -97,11 +97,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, @@ -160,13 +160,13 @@ 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[3*x + 1] = uint8(r >> 24); - cr[3*x + 2] = uint8(g >> 24); - cr[3*x + 3] = uint8(b >> 24); + cr[3*x + 1] = uint8(r>>24); + cr[3*x + 2] = uint8(g>>24); + cr[3*x + 3] = uint8(b>>24); } case ctPaletted: for x := 0; x < m.Width(); x++ { - cr[x + 1] = paletted.ColorIndexAt(x, y); + cr[x+1] = paletted.ColorIndexAt(x, y); } case ctTrueColorAlpha: // Convert from image.Image (which is alpha-premultiplied) to PNG's non-alpha-premultiplied. @@ -200,7 +200,7 @@ func (e *encoder) writeIDATs() { return; } var bw *bufio.Writer; - bw, e.err = bufio.NewWriterSize(e, 1 << 15); + bw, e.err = bufio.NewWriterSize(e, 1<<15); if e.err != nil { return; } @@ -243,4 +243,3 @@ func Encode(w io.Writer, m image.Image) os.Error { e.writeIEND(); return e.err; } - |