image

package
v3.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package image contains functions for rotations of points in a 2-dimensional space.

Index

Constants

View Source
const (
	BitFormatShort5551  = iota // BIT_FORMAT_SHORT_5_5_5_1 has 5 bits R, 5 bits G, 5 bits B, 1 bit alpha
	BitFormatInt8888Rev        // BIT_FORMAT_INT_8_8_8_8_REV has 8 bits R, 8 bits G, 8 bits B, 8 bit alpha
	BitFormatShort565          // BIT_FORMAT_SHORT_5_6_5 has 5 bits R, 6 bits G, 5 bits
)
View Source
const (
	ScaleNot              = iota // skips image interpolation
	ScaleNearestNeighbour        // nearest neighbour interpolation
	ScaleBilinear                // bilinear interpolation
)

Variables

View Source
var Angles = [5]Rotate{
	Angle0:   {Angle: Angle0, Call: Rotate0},
	Angle90:  {Angle: Angle90, Call: Rotate90, IsEven: true},
	Angle180: {Angle: Angle180, Call: Rotate180},
	Angle270: {Angle: Angle270, Call: Rotate270, IsEven: true},
	Flip180:  {Angle: Flip180, Call: Invert180},
}

Angles is a helper to choose appropriate rotation based on its angle.

Functions

func ExampleRotate

func ExampleRotate(data []uint8, w int, h int, angle Angle) []uint8

ExampleRotate is an example of rotation usage.

[1 2 3 4 5 6 7 8 9]
[7 4 1 8 5 2 9 6 3]

func Invert180

func Invert180(x, y, _, h int) (int, int)

func Resize

func Resize(scaleType int, src *image.RGBA, out *image.RGBA)

func Rotate0

func Rotate0(x, y, _, _ int) (int, int)

Rotate0 is 0° or the original orientation.

1 2 3    1 2 3
4 5 6 -> 4 5 6
7 8 9    7 8 9

func Rotate180

func Rotate180(x, y, w, h int) (int, int)

Rotate180 is 180° CCW.

1 2 3    9 8 7
4 5 6 -> 6 5 4
7 8 9    3 2 1

func Rotate270

func Rotate270(x, y, _, h int) (int, int)

Rotate270 is 270° CCW or 90° CW.

1 2 3    7 4 1
4 5 6 -> 8 5 2
7 8 9    9 6 3

func Rotate90

func Rotate90(x, y, w, _ int) (int, int)

Rotate90 is 90° CCW or 270° CW.

1 2 3    3 6 9
4 5 6 -> 2 5 8
7 8 9    1 4 7

Types

type Angle

type Angle uint
const (
	Angle0 Angle = iota
	Angle90
	Angle180
	Angle270
	Flip180
)

type Canvas

type Canvas struct {
	// contains filtered or unexported fields
}

Canvas is a stateful drawing surface, i.e. image.RGBA

func NewCanvas

func NewCanvas(w, h, size int) *Canvas

func (*Canvas) Clear

func (c *Canvas) Clear()

func (*Canvas) Draw

func (c *Canvas) Draw(encoding uint32, rot *Rotate, w, h, packedW, bpp int, data []byte, th int) *Frame

func (*Canvas) Get

func (c *Canvas) Get(w, h int) *Frame

func (*Canvas) Put

func (c *Canvas) Put(i *Frame)

type Frame

type Frame struct {
	*image.RGBA
}

func (*Frame) Copy

func (f *Frame) Copy() Frame

func (*Frame) Opaque

func (f *Frame) Opaque() bool

type Rotate

type Rotate struct {
	Angle  Angle
	Call   func(x, y, w, h int) (int, int)
	IsEven bool
}

Rotate is an interface for rotation of a given point.

With the coordinates x, y in the matrix of w x h. Returns a pair of new coordinates x, y in the resulting matrix. Be aware that w / h values are 0 index-based, and it's meant to be used with h corresponded to matrix height and y coordinate, and with w to x coordinate.

func GetRotation

func GetRotation(angle Angle) Rotate

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL