git clone https://git.lucas.co/go_mono.git
draw/draw.go (2.2K)
1 // Copyright 2015 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // Package draw provides image composition functions.
6 //
7 // See "The Go image/draw package" for an introduction to this package:
8 // http://golang.org/doc/articles/image_draw.html
9 //
10 // This package is a superset of and a drop-in replacement for the image/draw
11 // package in the standard library.
12 package draw
13
14 // This file just contains the API exported by the image/draw package in the
15 // standard library. Other files in this package provide additional features.
16
17 import (
18 "image"
19 "image/draw"
20 )
21
22 // Draw calls DrawMask with a nil mask.
23 func Draw(dst Image, r image.Rectangle, src image.Image, sp image.Point, op Op) {
24 draw.Draw(dst, r, src, sp, draw.Op(op))
25 }
26
27 // DrawMask aligns r.Min in dst with sp in src and mp in mask and then
28 // replaces the rectangle r in dst with the result of a Porter-Duff
29 // composition. A nil mask is treated as opaque.
30 func DrawMask(dst Image, r image.Rectangle, src image.Image, sp image.Point, mask image.Image, mp image.Point, op Op) {
31 draw.DrawMask(dst, r, src, sp, mask, mp, draw.Op(op))
32 }
33
34 // Drawer contains the Draw method.
35 type Drawer = draw.Drawer
36
37 // FloydSteinberg is a Drawer that is the Src Op with Floyd-Steinberg error
38 // diffusion.
39 var FloydSteinberg Drawer = floydSteinberg{}
40
41 type floydSteinberg struct{}
42
43 func (floydSteinberg) Draw(dst Image, r image.Rectangle, src image.Image, sp image.Point) {
44 draw.FloydSteinberg.Draw(dst, r, src, sp)
45 }
46
47 // Image is an image.Image with a Set method to change a single pixel.
48 type Image = draw.Image
49
50 // RGBA64Image extends both the Image and image.RGBA64Image interfaces with a
51 // SetRGBA64 method to change a single pixel. SetRGBA64 is equivalent to
52 // calling Set, but it can avoid allocations from converting concrete color
53 // types to the color.Color interface type.
54 type RGBA64Image = draw.RGBA64Image
55
56 // Op is a Porter-Duff compositing operator.
57 type Op = draw.Op
58
59 const (
60 // Over specifies ``(src in mask) over dst''.
61 Over Op = draw.Over
62 // Src specifies ``src in mask''.
63 Src Op = draw.Src
64 )
65
66 // Quantizer produces a palette for an image.
67 type Quantizer = draw.Quantizer