rotate.go 826 B

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright 2011 The Graphics-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. package graphics
  5. import (
  6. "code.google.com/p/graphics-go/graphics/interp"
  7. "errors"
  8. "image"
  9. "image/draw"
  10. )
  11. // RotateOptions are the rotation parameters.
  12. // Angle is the angle, in radians, to rotate the image clockwise.
  13. type RotateOptions struct {
  14. Angle float64
  15. }
  16. // Rotate produces a rotated version of src, drawn onto dst.
  17. func Rotate(dst draw.Image, src image.Image, opt *RotateOptions) error {
  18. if dst == nil {
  19. return errors.New("graphics: dst is nil")
  20. }
  21. if src == nil {
  22. return errors.New("graphics: src is nil")
  23. }
  24. angle := 0.0
  25. if opt != nil {
  26. angle = opt.Angle
  27. }
  28. return I.Rotate(angle).TransformCenter(dst, src, interp.Bilinear)
  29. }