core

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2019 License: MIT Imports: 30 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NearestNeighbor = canvas.NearestNeighbor

	Box = ResampleFilter{
		"box",
		0.5,
		func(x float64) float64 {
			if math.Abs(x) < 0.5 {
				return 1
			}
			return 0
		},
	}

	Linear = canvas.Linear

	Gaussian = ResampleFilter{
		"gaussian",
		1.0,
		func(x float64) float64 {
			x = math.Abs(x)
			if x < 1.0 {
				exp := 2.0
				x *= 2.0
				y := math.Pow(0.5, math.Pow(x, exp))
				base := math.Pow(0.5, math.Pow(2, exp))
				return (y - base) / (1 - base)
			}
			return 0
		},
	}

	MitchellNetravali = ResampleFilter{
		"mitchelnetravali",
		2.0,
		func(x float64) float64 {
			b := 1.0 / 3
			c := 1.0 / 3
			var w [4]float64
			x = math.Abs(x)

			if x < 1.0 {
				w[0] = 0
				w[1] = 6 - 2*b
				w[2] = (-18 + 12*b + 6*c) * x * x
				w[3] = (12 - 9*b - 6*c) * x * x * x
			} else if x <= 2.0 {
				w[0] = 8*b + 24*c
				w[1] = (-12*b - 48*c) * x
				w[2] = (6*b + 30*c) * x * x
				w[3] = (-b - 6*c) * x * x * x
			} else {
				return 0
			}

			return (w[0] + w[1] + w[2] + w[3]) / 6
		},
	}

	CatmullRom = ResampleFilter{
		"catmullrom",
		2.0,
		func(x float64) float64 {
			b := 0.0
			c := 0.5
			var w [4]float64
			x = math.Abs(x)

			if x < 1.0 {
				w[0] = 0
				w[1] = 6 - 2*b
				w[2] = (-18 + 12*b + 6*c) * x * x
				w[3] = (12 - 9*b - 6*c) * x * x * x
			} else if x <= 2.0 {
				w[0] = 8*b + 24*c
				w[1] = (-12*b - 48*c) * x
				w[2] = (6*b + 30*c) * x * x
				w[3] = (-b - 6*c) * x * x * x
			} else {
				return 0
			}

			return (w[0] + w[1] + w[2] + w[3]) / 6
		},
	}

	Lanczos = ResampleFilter{
		"lanczos",
		3.0,
		func(x float64) float64 {
			x = math.Abs(x)
			if x == 0 {
				return 1.0
			} else if x < 3.0 {
				return (3.0 * math.Sin(math.Pi*x) * math.Sin(math.Pi*(x/3.0))) / (math.Pi * math.Pi * x * x)
			}
			return 0.0
		},
	}

	Bartlett = ResampleFilter{
		"bartlett",
		3.0,
		func(x float64) float64 {
			x = math.Abs(x)
			if x < 3.0 {
				return sinc(x) * (3.0 - x) / 3.0
			}
			return 0
		},
	}

	Hermite = ResampleFilter{
		"hermite",
		1.0,
		func(x float64) float64 {
			x = math.Abs(x)
			if x < 1.0 {
				return bcspline(x, 0.0, 0.0)
			}
			return 0
		},
	}

	BSpline = ResampleFilter{
		"bspline",
		2.0,
		func(x float64) float64 {
			x = math.Abs(x)
			if x < 2.0 {
				return bcspline(x, 1.0, 0.0)
			}
			return 0
		},
	}

	Hann = ResampleFilter{
		"hann",
		3.0,
		func(x float64) float64 {
			x = math.Abs(x)
			if x < 3.0 {
				return sinc(x) * (0.5 + 0.5*math.Cos(math.Pi*x/3.0))
			}
			return 0
		},
	}

	Hamming = ResampleFilter{
		"hamming",
		3.0,
		func(x float64) float64 {
			x = math.Abs(x)
			if x < 3.0 {
				return sinc(x) * (0.54 + 0.46*math.Cos(math.Pi*x/3.0))
			}
			return 0
		},
	}

	Blackman = ResampleFilter{
		"blackman",
		3.0,
		func(x float64) float64 {
			x = math.Abs(x)
			if x < 3.0 {
				return sinc(x) * (0.42 - 0.5*math.Cos(math.Pi*x/3.0+math.Pi) + 0.08*math.Cos(2.0*math.Pi*x/3.0))
			}
			return 0
		},
	}

	Welch = ResampleFilter{
		"welch",
		3.0,
		func(x float64) float64 {
			x = math.Abs(x)
			if x < 3.0 {
				return sinc(x) * (1.0 - (x * x / 9.0))
			}
			return 0
		},
	}

	Cosine = ResampleFilter{
		"cosine",
		3.0,
		func(x float64) float64 {
			x = math.Abs(x)
			if x < 3.0 {
				return sinc(x) * math.Cos((math.Pi/2.0)*(x/3.0))
			}
			return 0
		},
	}

	ResampleFilters = []ResampleFilter{
		NearestNeighbor,
		Box,
		Linear,
		Gaussian,
		MitchellNetravali,
		CatmullRom,
		Lanczos,
		Bartlett,
		Hermite,
		BSpline,
		Hann,
		Hamming,
		Blackman,
		Welch,
		Cosine,
	}
)
View Source
var (
	FontsHome  string
	FontsShare = "/usr/share/fonts"
)
View Source
var Core cmdMap

A string key map of functions returning a flip.Command.

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func FontDirs

func FontDirs(dirs string) []string

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func NewCommand

func NewCommand(group, tag, instruction string,
	prio int,
	ffn flagSetFunc,
	cfn cmdFunc,
	x ...execution) *command

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

func ToColor

func ToColor(model, value string) color.Color

func WriteText

func WriteText(cv canvas.Canvas, o *Options) string

Given a canvas and instance of Options, will draw text to the canvas.

Types

type AlphaS

type AlphaS []string

func (AlphaS) Len

func (a AlphaS) Len() int

func (AlphaS) Less

func (a AlphaS) Less(i, j int) bool

func (AlphaS) Swap

func (a AlphaS) Swap(i, j int)

type BlendFunc

type BlendFunc = canvas.BlendFunc

type ColorRGB

type ColorRGB struct {
	R, G, B float64
}

func (ColorRGB) RGBA

func (c ColorRGB) RGBA() (r, g, b, a uint32)

type Fonts

type Fonts struct {
	// contains filtered or unexported fields
}
var LF *Fonts

local fonts

func NewFonts

func NewFonts() *Fonts

func (*Fonts) Get

func (f *Fonts) Get(k string) *truetype.Font

func (*Fonts) List

func (f *Fonts) List() []string

func (*Fonts) Set

func (f *Fonts) Set(name string, ft *truetype.Font) bool

func (*Fonts) SetByte

func (f *Fonts) SetByte(name string, fb []byte) bool

func (*Fonts) SetDir

func (f *Fonts) SetDir(paths ...string) error

func (*Fonts) SetPath

func (f *Fonts) SetPath(name, path string) bool

func (*Fonts) TextFont

func (f *Fonts) TextFont(k string,
	height, lineHeight float64,
	a align,
	c color.Color,
	o float64,
	wrap, anchor bool) *TextFont

type Options

type Options struct {
	log.Logger
	*data.Vector
}

A package level Options struct consisting of a logger and a data.Vector.

var CoreOptions *Options

A package level Options instance.

type Position

type Position = canvas.BlendPosition

type RGBA164

type RGBA164 = canvas.RGBA164

type ResampleFilter

type ResampleFilter = canvas.ResampleFilter

type Text

type Text struct {
	*TextBox
	*TextLocation
	*TextFont
	// contains filtered or unexported fields
}

func NewText

func NewText(
	msg string,
	bw, bh int,
	lx, ly float64,
	font string,
	fontSize float64,
	fontColor color.Color,
	opacity float64,
	lineHeight float64,
	alignment string,
	wrap, anchor bool) *Text

func OptionsToText

func OptionsToText(o *Options) *Text

Translates a set of Options to a Text instance.

func (*Text) DrawString

func (t *Text) DrawString(i draw.Image)

func (*Text) DrawStringAnchored

func (t *Text) DrawStringAnchored(i draw.Image)

func (*Text) DrawStringWrapped

func (t *Text) DrawStringWrapped(i draw.Image)

func (*Text) Scrive

func (t *Text) Scrive(d draw.Image)

func (*Text) String

func (t *Text) String() string

type TextBox

type TextBox struct {
	W, H int
}

func NewTextBox

func NewTextBox(bw, bh int) *TextBox

func (*TextBox) Box

func (t *TextBox) Box(d draw.Image) draw.Image

type TextFont

type TextFont struct {
	font.Face
	// contains filtered or unexported fields
}

func (*TextFont) MeasureString

func (t *TextFont) MeasureString(s string) (w, h float64)

type TextLocation

type TextLocation struct {
	X, Y float64
}

func NewTextLocation

func NewTextLocation(x, y float64) *TextLocation

func (*TextLocation) Locate

func (t *TextLocation) Locate() fixed.Point26_6

func (*TextLocation) Point

func (t *TextLocation) Point() image.Point

Jump to

Keyboard shortcuts

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