canvas

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: 20 Imported by: 0

Documentation

Index

Constants

View Source
const PATHNOOP = "PathNoop"

A default path.

Variables

View Source
var (
	WorkingColorModel       = RGBA
	WorkingColorModelString = "RGBA"
	WorkingColorModelFn     = color.RGBAModel
	WorkingColorModelNew    = image.NewRGBA
)
View Source
var (
	NearestNeighbor = ResampleFilter{
		"nearestneighbor",
		0,
		nil,
	}

	Linear = ResampleFilter{
		"linear",
		1.0,
		func(x float64) float64 {
			x = math.Abs(x)
			if x < 1.0 {
				return 1.0 - x
			}
			return 0
		},
	}
)
View Source
var AvailableColorModels = []ColorModel{
	ALPHA,
	ALPHA16,
	CMYK,
	GRAY,
	GRAY16,
	NRGBA,
	NRGBA64,
	RGBA,
	RGBA64,
}
View Source
var AvailableFileType = []FileType{
	BMP,
	JPG,
	PNG,
	TIFF,
}

A variable containing a listing of available and fully functional FileType.

View Source
var (
	AvailablePPU []string = []string{defaultPPU, "mm", "inch"} //
)
View Source
var EmptyIntersectError = xrr.Xrror("Unable to crop empty intersect of %v and provided %v").Out
View Source
var NoBlendPositionError = xrr.Xrror("no blend position")
View Source
var NoDirectionError = xrr.Xrror("'%s' is not a direction to flip").Out
View Source
var SaveNoopError = xrr.Xrror("cannot save a non operational canvas")
View Source
var ZeroResizeError = xrr.Xrror("zero value prevents resizing\n\twidth %d\n\theight %d\n\tempty canvas: %t").Out

Functions

func HSLToRGB

func HSLToRGB(h, s, l float64) color.RGBA

HSLToRGB converts from HSL to RGB color model. Parameter h is the hue and its range is from 0 to 360 degrees. Parameter s is the saturation and its range is from 0.0 to 1.0. Parameter l is the lightness and its range is from 0.0 to 1.0.

func HSVToRGB

func HSVToRGB(h, s, v float64) color.RGBA

HSVToRGB converts from HSV to RGB color model. Parameter h is the hue and its range is from 0 to 360 degrees. Parameter s is the saturation and its range is from 0.0 to 1.0. Parameter v is the value and its range is from 0.0 to 1.0.

func OpenTo

func OpenTo(path string) (image.Image, error)

func RGBToHSL

func RGBToHSL(c color.RGBA) (float64, float64, float64)

RGBToHSL converts from RGB to HSL color model. Parameter c is the RGBA color and must implement the color.RGBA interface. Returned values h, s and l correspond to the hue, saturation and lightness. The hue is of range 0 to 360 and the saturation and lightness are of range 0.0 to 1.0.

func RGBToHSV

func RGBToHSV(c color.RGBA) (h, s, v float64)

RGBToHSV converts from RGB to HSV color model. Parameter c is the RGBA color and must implement the color.RGBA interface. Returned values h, s and v correspond to the hue, saturation and value. The hue is of range 0 to 360 and the saturation and value are of range 0.0 to 1.0.

func Scratch

func Scratch(cm color.Model, X, Y int) *pxl

Types

type Action

type Action int

A type indicating the action identity of the canvas: noop, new, open, clone.

const (
	ACTIONNOOP Action = iota
	ACTIONNEW
	ACTIONOPEN
	ACTIONCLONE
)

func (Action) String

func (a Action) String() string

type Adjuster

type Adjuster interface {
	Adjust(AdjustmentFunc) error
}

type AdjustmentFunc

type AdjustmentFunc func(color.RGBA) color.RGBA

type BlendFunc

type BlendFunc func(RGBA164, RGBA164) RGBA164

type BlendPosition

type BlendPosition int
const (
	NoBlendPosition BlendPosition = iota
	FG
	BG
)

type Blender

type Blender interface {
	Blend(image.Image, BlendPosition, BlendFunc) error
}

type Canvas

type Canvas interface {
	log.Logger
	Identity
	Pxl
	Nooper
	Saver
	Cloner
	Operator
}

The primary interface for all image manipulation needs.

func New

func New(cnf ...Config) (Canvas, error)

Provided Config functions, returns a new Canvas and any configuration errors.

type Cloner

type Cloner interface {
	Clone() Canvas
	CloneTo(color.Model) Canvas
}

An interface for cloning a Canvas.

type ColorModel

type ColorModel int
const (
	COLORNOOP ColorModel = iota
	ALPHA
	ALPHA16
	CMYK
	GRAY
	GRAY16
	NRGBA
	NRGBA64
	RGBA
	RGBA64
)

func (ColorModel) String

func (c ColorModel) String() string

type ColorStats

type ColorStats interface {
	Channel(string) (*image.Gray, error)
	Threshold(l uint8) (*image.Gray, error)
	RGBAHistogram() *RGBAHistogram
}

type Config

type Config interface {
	Order() int
	Configure(*canvas) error
}

func DefaultConfig

func DefaultConfig(fn ConfigFn) Config

func NewConfig

func NewConfig(order int, fn ConfigFn) Config

func SetColorModel

func SetColorModel(m string) Config

func SetFileType

func SetFileType(k string) Config

func SetLogger

func SetLogger(l log.Logger) Config

func SetMeasure

func SetMeasure(pp float64, ppu string) Config

func SetPaletteFn

func SetPaletteFn(fn PaletteFunc) Config

func SetPath

func SetPath(in, out string) Config

func SetRect

func SetRect(x, y int) Config

type ConfigFn

type ConfigFn func(*canvas) error

type Configuration

type Configuration interface {
	Add(...Config)
	AddFn(...ConfigFn)
	Configure() error
	Configured() bool
}

type Convoluter

type Convoluter interface {
	Convolve(mth.Matrix, float64, bool, bool) error
}

type Cropper

type Cropper interface {
	Crop(image.Rectangle) error
}

An interface for cropping a Canvas.

type FileType

type FileType int

Indicates the type of file the canvas is.

const (
	FILETYPENOOP FileType = iota
	BMP
	JPG
	PNG
	TIFF
)

func (FileType) String

func (t FileType) String() string

Provides a string of this FileType.

type Histogram

type Histogram struct {
	Bins []int
}

func (*Histogram) Cumulative

func (h *Histogram) Cumulative() *Histogram

Cumulative returns a new Histogram in which each bin is the cumulative value of its previous bins

func (*Histogram) Image

func (h *Histogram) Image() *image.Gray

Image returns a grayscale image representation of the Histogram. The width and height of the image will be equivalent to the number of Bins in the Histogram.

func (*Histogram) Max

func (h *Histogram) Max() int

Max returns the highest count found in the histogram bins.

func (*Histogram) Min

func (h *Histogram) Min() int

Min returns the lowest count found in the histogram bins.

type Identity

type Identity interface {
	Pather
	Action() string
	FileType() string
}

type ImageImage

type ImageImage interface {
	ColorModel() color.Model
	Bounds() image.Rectangle
	At(x, y int) color.Color
	Opaque() bool
	PixOffset(int, int) int
	Set(x, y int, c color.Color)
	SubImage(image.Rectangle) image.Image
}

The interface corresponding to the most relevant functionality of Image in the image package.

type Measure

type Measure interface {
	PP(string) float64
	SetPP(string, float64)
	Height() float64
	Width() float64
	Radius() float64
	Distance(string, Moint, Moint) float64
	Anchor(string) Moint
	SetAnchor(string, MointFunc)
}

An interface of tools for examining, manipulating, and measuring a rectangle.

type Moint

type Moint struct {
	X, Y float64
}

A struct encompassing a 2D float64 X - Y coordinate for measurement. Functionality is paralell to image.Point, but not an interface.

var ZM Moint = Moint{0, 0}

func ToMoint

func ToMoint(ip image.Point) Moint

func (Moint) Add

func (p Moint) Add(o Moint) Moint

Add other Point to this Point.

func (Moint) Distance

func (p Moint) Distance(o Moint) float64

Returns the distance from point to other point.

func (Moint) Div

func (p Moint) Div(k float64) Moint

func (Moint) Eq

func (p Moint) Eq(o Moint) bool

func (Moint) Fixed

func (p Moint) Fixed() fixed.Point26_6

Returns a fixed.Point26_6 representation of Point.

func (Moint) IPoint

func (p Moint) IPoint() image.Point

func (Moint) In

func (p Moint) In(r image.Rectangle) bool

func (Moint) Interpolate

func (p Moint) Interpolate(o Moint, t float64) Moint

Interpolate other Point to provided float64.

func (Moint) Mod

func (p Moint) Mod(r image.Rectangle) Moint

func (Moint) Mul

func (p Moint) Mul(k float64) Moint

func (Moint) String

func (p Moint) String() string

func (Moint) Sub

func (p Moint) Sub(o Moint) Moint

Subtract other Moint from this Moint

type MointFunc

type MointFunc func(f Measure) Moint

A function type that takes a Measure and returns a Point.

type NoiseFunc

type NoiseFunc func() uint8

type Noiser

type Noiser interface {
	Noise(NoiseFunc, bool) error
}

type Nooper

type Nooper interface {
	Noop() bool
}

An interface for denoting a non operational Canvas.

type Operator

type Operator interface {
	Adjuster
	Blender
	Convoluter
	Noiser
	Transformer
	Translater
}

An interface for performing (relatively default & easy) operations on an image.

type PaletteFunc

type PaletteFunc func(color.Color) color.Color

type Paletter

type Paletter interface {
	Palettize(color.Color) color.Color
}

type Paster

type Paster interface {
	Paste(draw.Image, image.Point)
	Overlay(draw.Image, image.Point, float64)
}

An interface for pasting.

type Pather

type Pather interface {
	Path() string
	SetPath(string)
}

An interface for encapsulating a string path.

type Pix

type Pix interface {
	Pix() []uint8
	SetPix([]uint8)
	Stride() int
}

An interface for direct pix manipulation.

type Pxl

type Pxl interface {
	ImageImage
	Measure
	Paletter
	Paster
	Pix
}

Interface for core image data. Encapsulates image.Image plus other image package image functionality in addition to direct pixel access, paletting, pasting, and physical measurement.

type RGBA164

type RGBA164 struct {
	R, G, B, A float64
}

RGBA color using the range of 0-1 in float64

func AlphaComp

func AlphaComp(bg, fg RGBA164) RGBA164

func (*RGBA164) Clamp

func (c *RGBA164) Clamp()

type RGBAHistogram

type RGBAHistogram struct {
	R Histogram
	G Histogram
	B Histogram
	A Histogram
}

func NewRGBAHistogram

func NewRGBAHistogram(img image.Image) *RGBAHistogram

NewRGBAHistogram constructs a RGBAHistogram out of the provided image. A sub-histogram is created per RGBA channel with 256 bins each.

func (*RGBAHistogram) Cumulative

func (h *RGBAHistogram) Cumulative() *RGBAHistogram

Cumulative returns a new RGBAHistogram in which each bin is the cumulative value of its previous bins per channel.

func (*RGBAHistogram) Image

func (h *RGBAHistogram) Image() *image.RGBA

Image returns an RGBA image representation of the RGBAHistogram. An image width of 256 represents the 256 Bins per channel and the image height of 256 represents the max normalized histogram value per channel. Each RGB channel from the histogram is mapped to its corresponding channel in the image, so that for example if the red channel is extracted from the image, it corresponds to the red channel histogram.

type ResampleFilter

type ResampleFilter struct {
	Key     string
	Support float64
	Fn      ResampleFilterFunc
}

func (ResampleFilter) String

func (r ResampleFilter) String() string

type ResampleFilterFunc

type ResampleFilterFunc func(float64) float64

type Resizer

type Resizer interface {
	Resize(w, h int, f ResampleFilter) error
}

type Saver

type Saver interface {
	Save() error
	SaveTo(string) error
}

An interface for saving a canvas.

type TDir

type TDir int
const (
	NoTDir TDir = iota
	THorizontal
	TVertical
)

type Transformer

type Transformer interface {
	Cropper
	Resizer
}

type Translater

type Translater interface {
	Flip(TDir) error
	Rotate(float64, bool, image.Point) error
	Shear(TDir, float64) error
	Translate(int, int) error
}

Jump to

Keyboard shortcuts

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