go1_9.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2016 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. // +build go1.9 go1.8.typealias
  5. package draw
  6. import (
  7. "image/draw"
  8. )
  9. // We use type aliases (new in Go 1.9) for the exported names from the standard
  10. // library's image/draw package. This is not merely syntactic sugar for
  11. //
  12. // type Drawer draw.Drawer
  13. //
  14. // as aliasing means that the types in this package, such as draw.Image and
  15. // draw.Op, are identical to the corresponding draw.Image and draw.Op types in
  16. // the standard library. In comparison, prior to Go 1.9, the code in go1_8.go
  17. // defines new types that mimic the old but are different types.
  18. //
  19. // The package documentation, in draw.go, explicitly gives the intent of this
  20. // package:
  21. //
  22. // This package is a superset of and a drop-in replacement for the
  23. // image/draw package in the standard library.
  24. //
  25. // Drop-in replacement means that I can replace all of my "image/draw" imports
  26. // with "golang.org/x/image/draw", to access additional features in this
  27. // package, and no further changes are required. That's mostly true, but not
  28. // completely true unless we use type aliases.
  29. //
  30. // Without type aliases, users might need to import both "image/draw" and
  31. // "golang.org/x/image/draw" in order to convert from two conceptually
  32. // equivalent but different (from the compiler's point of view) types, such as
  33. // from one draw.Op type to another draw.Op type, to satisfy some other
  34. // interface or function signature.
  35. // Drawer contains the Draw method.
  36. type Drawer = draw.Drawer
  37. // Image is an image.Image with a Set method to change a single pixel.
  38. type Image = draw.Image
  39. // Op is a Porter-Duff compositing operator.
  40. type Op = draw.Op
  41. const (
  42. // Over specifies ``(src in mask) over dst''.
  43. Over Op = draw.Over
  44. // Src specifies ``src in mask''.
  45. Src Op = draw.Src
  46. )
  47. // Quantizer produces a palette for an image.
  48. type Quantizer = draw.Quantizer