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
This commit is contained in:
parent
5792b75123
commit
220b691d5c
4 changed files with 14 additions and 6 deletions
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue