strategy

package
v0.0.0-...-bbf78bc Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2020 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var VecZero = Vec(0, 0)

VecZero is a constant vector that represents a point vector (magnitude 0)

Functions

func AlphaEval

func AlphaEval(c color.Color) uint8

LightnessEval returns a value based on alpha channel

func BoxBlurKernel

func BoxBlurKernel(radius uint) utils.Kernel

func ChannelDifference

func ChannelDifference(c1, c2 color.Color) color.Color

ChannelDifference returns a ColorDifference that returns the absolute value of the effective difference of 2 colors, channel by channel; for example, the difference for red and blue will be magenta, as both channels will be returned at maximum value

func CornerPixelsSampling

func CornerPixelsSampling(img image.Image, x, y int, factor ScaleFactor) color.Color

CornerPixelsSampling is an implementation of ColorSampling that uses a bilinear interpolation between the corners of the rectangle obtained by scaling back a pixel from the destination image to the source image; the scaled rectangle can actually be smaller than a single pixel would for factors greater than 1

func DividedColorCorrection

func DividedColorCorrection(c color.Color, val int16) color.Color

DividedColorCorrection modifies all 3 color channels by equal part of shifting value, clamping the result

func Extend

func Extend(bounds image.Rectangle, x, y int) (int, int)

Extend returns the color of the closest pixel of the image

func GaussianBlurKernel

func GaussianBlurKernel(sigma float64) utils.Kernel

func Grayscale

func Grayscale(in color.Color) color.Color

Grayscale maps the given color to a gray shade using the standard library default color converter logic

func Identity

func Identity(in color.Color) color.Color

Identity returns the given color

func Lightness

func Lightness(in color.Color) color.Color

Lightness returns a grayscale color for the given color calculated based on lightness equation

func LightnessCorrection

func LightnessCorrection(c color.Color, val int16) color.Color

LightnessCorrection modifies all 3 color channels with respect the lightness ratios

func LightnessEval

func LightnessEval(c color.Color) uint8

LightnessEval returns a value based on lightness equation

func Mirror

func Mirror(bounds image.Rectangle, x, y int) (int, int)

Mirror returns the color of the pixel as if the image is conceptually mirrored at the edges

func Negative

func Negative(in color.Color) color.Color

Negative maps the given color to its negative

func None

func None(_ image.Rectangle, x, y int) (int, int)

None returns the color of the pixel requested, without alterations

func Sepia

func Sepia(in color.Color) color.Color

Sepia maps the given color to a sepia shade

func SinglePixelSampling

func SinglePixelSampling(img image.Image, destX, destY int, factor ScaleFactor) color.Color

SinglePixelSampling is an implementation of ColorSampling that uses the color of a single pixel (the closest to the target) from the source image

func SobelKernels

func SobelKernels() []utils.Kernel

func SobelMerge

func SobelMerge(results []color.Color) color.Color

SobelMerge defines the rule used to merge results for sobel operator; despite sobel using only 2 kernels, the function handles more values

func UniformColorCorrection

func UniformColorCorrection(c color.Color, val int16) color.Color

UniformColorCorrection modifies all 3 color channels with the entire value

func ValueEval

func ValueEval(c color.Color) uint8

LightnessEval returns a value based on average between color channels

func Wrap

func Wrap(bounds image.Rectangle, x, y int) (int, int)

Wrap returns the color of the pixel as if the image is conceptually wrapped (or tiled) and values are taken from the opposite edge or corner

Types

type ColorCorrection

type ColorCorrection func(color.Color, int16) color.Color

ColorCorrection is a function that shifts the value of a color by a certain degree, be it negative or positive

type ColorDifference

type ColorDifference func(color.Color, color.Color) color.Color

ColorDifference takes 2 colors and return a difference between them based on the logic it contains

func BinaryDifference

func BinaryDifference(delta float64, same, difference color.Color) ColorDifference

BinaryDifference returns a ColorDifference that for 2 colors that are more different (in matter of color channels) than a threshold, returns a predefined color, otherwise returns other predefined color, reducing the image to only 2 colors

type ColorEvaluation

type ColorEvaluation func(color.Color) uint8

ColorEvaluation is a function that transform a given color with multiple color channels into a single numerical value, easier to index

type ColorMerger

type ColorMerger func([]color.Color) color.Color

ColorMerger defines an interface for all functions used to determine the merged result of multiple applied filters for MultiKernel

type ColorSampling

type ColorSampling func(image.Image, int, int, ScaleFactor) color.Color

ColorSampling encapsulates a strategy used to decide what color the pixel at the given position from the destination image will have

type Condition

type Condition func(color.Color) bool

Condition filters colors based on contained logic

type EdgeHandling

type EdgeHandling func(image.Rectangle, int, int) (int, int)

EdgeHandling defines an interface for all functions used to determine the behaviour of filtering around the edge of the image

type FishEyeLens

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

FishEyeLens encapsulates logic for a fish eye distortion

func NewFishEyeLens

func NewFishEyeLens(center geometry.Point2D, radius, strength float64) *FishEyeLens

NewFishEyeLens returns a FishEyeLens with the given center, radius and strength

func (FishEyeLens) VecAt

func (lens FishEyeLens) VecAt(x, y int) Vector

VecAt returns the Vector for the given cooridinates obtained from the fish-eye effect

type HorizontalWavesLens

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

HorizontalWavesLens encapsulates logic for a wave distortion on the horizontal direction

func NewHorizontalWavesLens

func NewHorizontalWavesLens(frequency, magnitude, translation float64) *HorizontalWavesLens

NewHorizontalWavesLens returns a HorizontalWavesLens with the given frequency, magnitude and translation

func (HorizontalWavesLens) VecAt

func (lens HorizontalWavesLens) VecAt(x, y int) Vector

VecAt returns the Vector for the given cooridinates obtained from the horizontal wave distortion

type Lens

type Lens interface {
	// VecAt returns the given distortion vector for a given position
	VecAt(x, y int) Vector
}

Lens encapsulates the logic needed obtain distortion vectors for an image

type LensAssembly

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

LensAssembly encapsulates 2 Lenses and a LensOperation used to compose the two Lens

func (LensAssembly) VecAt

func (asm LensAssembly) VecAt(x, y int) Vector

VecAt returns the Vector for the given cooridinates obtained by navigation the Lens and LensOperation in the LensAssembly

type LensOperation

type LensOperation func(Vector, Vector) Vector

LensOperation defines a general method of composing lens

type MappingRule

type MappingRule func(color.Color) color.Color

MappingRule modifies a color using contained logic

func AddCondition

func AddCondition(rule MappingRule, condition Condition) MappingRule

AddCondition returns MappingRule that execute the given MappingRule only if the given Condition evaluates to true

func BlackAndWhite

func BlackAndWhite(evaluation ColorEvaluation, threshold uint8) MappingRule

BlackAndWhite maps the given color to black or white depending on a color evaluation function and its output to the color input relative to the given threshold

func BrightnessMapping

func BrightnessMapping(brightnessFactor float64) MappingRule

BrightnessMapping maps the given color to a brighter or darker color depending on the given brightness factor

func ComposeRule

func ComposeRule(condition Condition, ruleTrue, ruleFalse MappingRule) MappingRule

ComposeRule returns a MappingRule that executes the first MappingRule if the given Condition returns true, or second MappingRule for false

func CorrectionMapping

func CorrectionMapping(correction ColorCorrection, factor int16) MappingRule

CorrectionMapping maps the given color to a color obtained by applying the correction strategy with a given factor on each color pixel

func GrayscaleRatioFactory

func GrayscaleRatioFactory(redRatio, greenRatio, blueRatio float64) MappingRule

GrayscaleRatioFactory returns a grayscale mapper that uses the given ration to calculate the resulting shade of gray

type PlanoLens

type PlanoLens struct{}

PlanoLens encapsulates logic for a Plano lens (0.0 magnitude) that does not alter the image at all

func NewPlanoLens

func NewPlanoLens() *PlanoLens

func (PlanoLens) VecAt

func (lens PlanoLens) VecAt(x, y int) Vector

type RotationLens

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

RotationLens encapsulates logic for a fish eye distortion

func NewRotationLens

func NewRotationLens(anchor geometry.Point2D, radians float64) *RotationLens

NewRotationLens returns a RotationLens with the given anchor and rotation

func (RotationLens) VecAt

func (lens RotationLens) VecAt(x, y int) Vector

VecAt returns the Vector for the given cooridinates obtained from the rotation distortion

type ScaleFactor

type ScaleFactor struct {
	X, Y float64
}

ScaleFactor represents the value a point must be multiplied by in order to obtain its color coordinates on the source image

func (ScaleFactor) GetSourcePx

func (factor ScaleFactor) GetSourcePx(x, y float64) (float64, float64)

GetSourcePx returns the color coordinates of the source image for the given color coordinates of the destination image

type ScalingTarget

type ScalingTarget func(image.Rectangle) (ScaleFactor, image.Rectangle)

ScalingTarget encapsulates a strategy used to obtain the scale factor of an image and the target size of the said image

type Vector

type Vector struct {
	X, Y float64
}

Vector is a struct than encapsulates an Euclidean vector that starts from origin of the space and is defined by its terminal point

func Add

func Add(a, b Vector) Vector

Add returns the addition of two vectors

func Diff

func Diff(a, b Vector) Vector

Diff returns the subtraction of two vectors

func Merge

func Merge(a, b Vector) Vector

Merge returns the mean value of two vectors

func Vec

func Vec(x, y float64) Vector

Vec returns a Vector from the given values

Jump to

Keyboard shortcuts

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