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.
12package 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
17import (
18	"image"
19	"image/color"
20	"image/draw"
21)
22
23// Draw calls DrawMask with a nil mask.
24func Draw(dst Image, r image.Rectangle, src image.Image, sp image.Point, op Op) {
25	draw.Draw(dst, r, src, sp, draw.Op(op))
26}
27
28// DrawMask aligns r.Min in dst with sp in src and mp in mask and then
29// replaces the rectangle r in dst with the result of a Porter-Duff
30// composition. A nil mask is treated as opaque.
31func DrawMask(dst Image, r image.Rectangle, src image.Image, sp image.Point, mask image.Image, mp image.Point, op Op) {
32	draw.DrawMask(dst, r, src, sp, mask, mp, draw.Op(op))
33}
34
35// Drawer contains the Draw method.
36type Drawer interface {
37	// Draw aligns r.Min in dst with sp in src and then replaces the
38	// rectangle r in dst with the result of drawing src on dst.
39	Draw(dst Image, r image.Rectangle, src image.Image, sp image.Point)
40}
41
42// FloydSteinberg is a Drawer that is the Src Op with Floyd-Steinberg error
43// diffusion.
44var FloydSteinberg Drawer = floydSteinberg{}
45
46type floydSteinberg struct{}
47
48func (floydSteinberg) Draw(dst Image, r image.Rectangle, src image.Image, sp image.Point) {
49	draw.FloydSteinberg.Draw(dst, r, src, sp)
50}
51
52// Image is an image.Image with a Set method to change a single pixel.
53type Image interface {
54	image.Image
55	Set(x, y int, c color.Color)
56}
57
58// Op is a Porter-Duff compositing operator.
59type Op int
60
61const (
62	// Over specifies ``(src in mask) over dst''.
63	Over Op = Op(draw.Over)
64	// Src specifies ``src in mask''.
65	Src Op = Op(draw.Src)
66)
67
68// Draw implements the Drawer interface by calling the Draw function with
69// this Op.
70func (op Op) Draw(dst Image, r image.Rectangle, src image.Image, sp image.Point) {
71	(draw.Op(op)).Draw(dst, r, src, sp)
72}
73
74// Quantizer produces a palette for an image.
75type Quantizer interface {
76	// Quantize appends up to cap(p) - len(p) colors to p and returns the
77	// updated palette suitable for converting m to a paletted image.
78	Quantize(p color.Palette, m image.Image) color.Palette
79}
80