From 43d4d89685c64e58d0f8e3167bdcbdb9a0734d55 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Sun, 10 Jul 2011 15:05:40 +1000 Subject: [PATCH] freetype: update for image.Pix changes. R=r CC=golang-dev http://codereview.appspot.com/4675071 --- example/gamma/main.go | 13 +------------ example/round/main.go | 8 ++------ freetype/raster/paint.go | 6 +++--- 3 files changed, 6 insertions(+), 21 deletions(-) diff --git a/example/gamma/main.go b/example/gamma/main.go index 8fe4539..652eb42 100644 --- a/example/gamma/main.go +++ b/example/gamma/main.go @@ -21,17 +21,6 @@ func p(x, y int) raster.Point { return raster.Point{raster.Fix32(x * 256), raster.Fix32(y * 256)} } -func clear(m *image.Alpha) { - b := m.Bounds() - for y := b.Min.Y; y < b.Max.Y; y++ { - base := y * m.Stride - p := m.Pix[base+b.Min.X : base+b.Max.X] - for i, _ := range p { - p[i] = image.AlphaColor{0} - } - } -} - func main() { // Draw a rounded corner that is one pixel wide. r := raster.NewRasterizer(50, 50) @@ -57,7 +46,7 @@ func main() { painter := raster.NewAlphaSrcPainter(mask) gammas := []float64{1.0 / 10.0, 1.0 / 3.0, 1.0 / 2.0, 2.0 / 3.0, 4.0 / 5.0, 1.0, 5.0 / 4.0, 3.0 / 2.0, 2.0, 3.0, 10.0} for i, g := range gammas { - clear(mask) + draw.Draw(mask, mask.Bounds(), image.Transparent, image.ZP, draw.Src) r.Rasterize(raster.NewGammaCorrectionPainter(painter, g)) x, y := 50*i+25, 25 draw.DrawMask(rgba, image.Rect(x, y, x+50, y+50), image.White, image.ZP, mask, image.ZP, draw.Over) diff --git a/example/round/main.go b/example/round/main.go index e0349ee..7e87cff 100644 --- a/example/round/main.go +++ b/example/round/main.go @@ -14,6 +14,7 @@ import ( "bufio" "fmt" "image" + "image/draw" "image/png" "log" "math" @@ -31,12 +32,7 @@ func main() { t := raster.Fix32(r * math.Tan(math.Pi/8)) m := image.NewRGBA(800, 600) - for y := 0; y < 600; y++ { - p := m.Pix[y*m.Stride : y*m.Stride+800] - for i := range p { - p[i] = image.RGBAColor{63, 63, 63, 255} - } - } + draw.Draw(m, m.Bounds(), &image.ColorImage{image.RGBAColor{63, 63, 63, 255}}, image.ZP, draw.Src) mp := raster.NewRGBAPainter(m) mp.SetColor(image.Black) z := raster.NewRasterizer(800, 600) diff --git a/freetype/raster/paint.go b/freetype/raster/paint.go index dfe53ea..e3bc50b 100644 --- a/freetype/raster/paint.go +++ b/freetype/raster/paint.go @@ -58,7 +58,7 @@ func (r AlphaOverPainter) Paint(ss []Span, done bool) { if s.X0 >= s.X1 { continue } - base := s.Y * r.Image.Stride + base := (s.Y-r.Image.Rect.Min.Y)*r.Image.Stride - r.Image.Rect.Min.X p := r.Image.Pix[base+s.X0 : base+s.X1] a := int(s.A >> 24) for i, c := range p { @@ -99,7 +99,7 @@ func (r AlphaSrcPainter) Paint(ss []Span, done bool) { if s.X0 >= s.X1 { continue } - base := s.Y * r.Image.Stride + base := (s.Y-r.Image.Rect.Min.Y)*r.Image.Stride - r.Image.Rect.Min.X p := r.Image.Pix[base+s.X0 : base+s.X1] color := image.AlphaColor{uint8(s.A >> 24)} for i := range p { @@ -141,7 +141,7 @@ func (r *RGBAPainter) Paint(ss []Span, done bool) { if s.X0 >= s.X1 { continue } - base := s.Y * r.Image.Stride + base := (s.Y-r.Image.Rect.Min.Y)*r.Image.Stride - r.Image.Rect.Min.X p := r.Image.Pix[base+s.X0 : base+s.X1] for i, rgba := range p { // This code is duplicated from drawGlyphOver in $GOROOT/src/pkg/exp/draw/draw.go.