Overview

Package draw provides image composition functions.

See “The Go image/draw package” for an introduction to this package:
https://golang.org/doc/articles/image_draw.html

Index

draw.go

Draw calls DrawMask with a nil mask.

func

  1. func DrawMask(dst , r image., src image., sp image., mask image., mp image., op Op)

DrawMask aligns r.Min in dst with sp in src and mp in mask and then replaces the
rectangle r in dst with the result of a Porter-Duff composition. A nil mask is
treated as opaque.

type

  1. type Drawer interface {
  2. // Draw aligns r.Min in dst with sp in src and then replaces the
  3. // rectangle r in dst with the result of drawing src on dst.
  4. Draw(dst , r image., src image., sp image.)
  5. }

Drawer contains the Draw method.

FloydSteinberg is a Drawer that is the Src Op with Floyd-Steinberg error
diffusion.


Example:

  1. const width = 130
  2. im := image.NewGray(image.Rectangle{Max: image.Point{X: width, Y: height}})
  3. for x := 0; x < width; x++ {
  4. for y := 0; y < height; y++ {
  5. dist := math.Sqrt(math.Pow(float64(x-width/2), 2)/3+math.Pow(float64(y-height/2), 2)) / (height / 1.5) * 255
  6. var gray uint8
  7. if dist > 255 {
  8. gray = 255
  9. gray = uint8(dist)
  10. }
  11. im.SetGray(x, y, color.Gray{Y: 255 - gray})
  12. }
  13. }
  14. pi := image.NewPaletted(im.Bounds(), []color.Color{
  15. color.Gray{Y: 255},
  16. color.Gray{Y: 160},
  17. color.Gray{Y: 70},
  18. color.Gray{Y: 35},
  19. })
  20. draw.FloydSteinberg.Draw(pi, im.Bounds(), im, image.ZP)
  21. shade := []string{" ", "░", "▒", "▓", "█"}
  22. for i, p := range pi.Pix {
  23. fmt.Print(shade[p])
  24. if (i+1)%width == 0 {
  25. fmt.Print("\n")
  26. }
  27. }

  1. type Image interface {
  2. .Image
  3. Set(x, y , c color.)
  4. }

type Op

Op is a Porter-Duff compositing operator.

  1. const (
  2. // Over specifies ``(src in mask) over dst''.
  3. Over Op =
  4. // Src specifies ``src in mask''.
  5. Src

  1. func (op Op) Draw(dst , r image., src image., sp image.)

Draw implements the Drawer interface by calling the Draw function with this Op.

type Quantizer