From 220b691d5c0f28545dd3e8caa6a65a0ad2360ec1 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Tue, 12 Oct 2010 16:55:01 +1100 Subject: [PATCH] freetype: add NewAlpha{Src,Over}Painter constructor function for consistency with existing NewFooPainter functions. Unbreak build from ColorImage change in the core image package. R=adg CC=golang-dev http://codereview.appspot.com/2450041 --- example/gamma/main.go | 3 +-- example/raster/main.go | 5 ++--- freetype/freetype.go | 2 +- freetype/raster/paint.go | 10 ++++++++++ 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/example/gamma/main.go b/example/gamma/main.go index be6ec3e..c0c5521 100644 --- a/example/gamma/main.go +++ b/example/gamma/main.go @@ -54,8 +54,7 @@ func main() { draw.Draw(rgba, image.Rect(0, 0, w, h/2), image.Black, image.ZP) draw.Draw(rgba, image.Rect(0, h/2, w, h), image.White, image.ZP) mask := image.NewAlpha(50, 50) - painter := raster.NewAlphaPainter(mask) - painter.Op = draw.Src + painter := raster.NewAlphaSrcPainter(mask) gammas := []float{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) diff --git a/example/raster/main.go b/example/raster/main.go index fb0d0b0..225f1c9 100644 --- a/example/raster/main.go +++ b/example/raster/main.go @@ -141,13 +141,12 @@ func main() { contour(r, outside) contour(r, inside) mask := image.NewAlpha(w, h) - p := raster.NewAlphaPainter(mask) - p.Op = draw.Src + p := raster.NewAlphaSrcPainter(mask) r.Rasterize(p) // Draw the mask image (in gray) onto an RGBA image. rgba := image.NewRGBA(w, h) - gray := image.ColorImage{image.AlphaColor{0x1f}} + gray := image.NewColorImage(image.AlphaColor{0x1f}) draw.Draw(rgba, rgba.Bounds(), image.Black, image.ZP) draw.DrawMask(rgba, rgba.Bounds(), gray, image.ZP, mask, image.ZP, draw.Over) showNodes(rgba, outside) diff --git a/freetype/freetype.go b/freetype/freetype.go index 0daa810..b35e769 100644 --- a/freetype/freetype.go +++ b/freetype/freetype.go @@ -178,7 +178,7 @@ func (c *Context) rasterize(glyph truetype.Index, fx, fy raster.Fix32) (*image.A e0 = e1 } a := image.NewAlpha(xmax-xmin, ymax-ymin) - c.r.Rasterize(raster.AlphaSrcPainter{a}) + c.r.Rasterize(raster.NewAlphaSrcPainter(a)) return a, image.Point{xmin, ymin}, nil } diff --git a/freetype/raster/paint.go b/freetype/raster/paint.go index 39d2e41..c924115 100644 --- a/freetype/raster/paint.go +++ b/freetype/raster/paint.go @@ -69,6 +69,11 @@ func (r AlphaOverPainter) Paint(ss []Span, done bool) { } } +// NewAlphaOverPainter creates a new AlphaOverPainter for the given image. +func NewAlphaOverPainter(m *image.Alpha) AlphaOverPainter { + return AlphaOverPainter{m} +} + // An AlphaSrcPainter is a Painter that paints Spans onto an image.Alpha // using the Src Porter-Duff composition operator. type AlphaSrcPainter struct { @@ -103,6 +108,11 @@ func (r AlphaSrcPainter) Paint(ss []Span, done bool) { } } +// NewAlphaSrcPainter creates a new AlphaSrcPainter for the given image. +func NewAlphaSrcPainter(m *image.Alpha) AlphaSrcPainter { + return AlphaSrcPainter{m} +} + type RGBAPainter struct { // The image to compose onto. Image *image.RGBA