Exemple #1
0
// Draw implements the Drawer interface from the standard library's image/draw
// package.
//
// The vector paths previously added via the XxxTo calls become the mask for
// drawing src onto dst.
func (z *Rasterizer) Draw(dst draw.Image, r image.Rectangle, src image.Image, sp image.Point) {
	// TODO: adjust r and sp (and mp?) if src.Bounds() doesn't contain
	// r.Add(sp.Sub(r.Min)).

	if src, ok := src.(*image.Uniform); ok {
		srcR, srcG, srcB, srcA := src.RGBA()
		switch dst := dst.(type) {
		case *image.Alpha:
			// Fast path for glyph rendering.
			if srcA == 0xffff {
				if z.DrawOp == draw.Over {
					z.rasterizeDstAlphaSrcOpaqueOpOver(dst, r)
				} else {
					z.rasterizeDstAlphaSrcOpaqueOpSrc(dst, r)
				}
				return
			}
		case *image.RGBA:
			if z.DrawOp == draw.Over {
				z.rasterizeDstRGBASrcUniformOpOver(dst, r, srcR, srcG, srcB, srcA)
			} else {
				z.rasterizeDstRGBASrcUniformOpSrc(dst, r, srcR, srcG, srcB, srcA)
			}
			return
		}
	}

	if z.DrawOp == draw.Over {
		z.rasterizeOpOver(dst, r, src, sp)
	} else {
		z.rasterizeOpSrc(dst, r, src, sp)
	}
}
Exemple #2
0
// Draw implements the Drawer interface from the standard library's image/draw
// package.
//
// The vector paths previously added via the XxxTo calls become the mask for
// drawing src onto dst.
func (z *Rasterizer) Draw(dst draw.Image, r image.Rectangle, src image.Image, sp image.Point) {
	if src, ok := src.(*image.Uniform); ok {
		_, _, _, srcA := src.RGBA()
		switch dst := dst.(type) {
		case *image.Alpha:
			// Fast path for glyph rendering.
			if srcA == 0xffff && z.DrawOp == draw.Src {
				z.rasterizeDstAlphaSrcOpaqueOpSrc(dst, r)
				return
			}
		}
	}
	println("TODO: the general case")
}
Exemple #3
0
// NewPainter returns a Painter that will draw from src onto
// dst using the Porter-Duff composition operator op.
func NewPainter(dst draw.Image, src image.Image, op draw.Op) (p raster.Painter) {
	defer func() { fmt.Printf("newpainter %T\n", p) }()
	if src, ok := src.(*image.Uniform); ok {
		switch dst := dst.(type) {
		case *image.Alpha:
			if _, _, _, a := src.RGBA(); a == 0xffff {
				switch op {
				case draw.Src:
					return &raster.AlphaSrcPainter{dst}
				case draw.Over:
					return &raster.AlphaOverPainter{dst}
				}
			}

		case *image.RGBA:
			p := raster.NewRGBAPainter(dst)
			p.SetColor(src)
			p.Op = op
			return p
		}
	}
	return &genericImagePainter{dst, src, op}
}