Documentation ¶
Overview ¶
Go (Image) Filtering Toolkit. It is basically non-direct fork of GIFT (https://github.com/disintegration/gift). Also some filters are taken from GIMP (https://github.com/GNOME/gimp).
Index ¶
- type ColorFilter
- type ColorLevels
- type ColorchanFilter
- type Filter
- type Interpolation
- type List
- type MergingColorFilter
- type MergingColorchanFilter
- type MergingFilter
- func CombineColorFilters(filters ...ColorFilter) MergingFilter
- func CombineColorchanFilters(filters ...ColorchanFilter) MergingFilter
- func CombineFilters(filters ...Filter) MergingFilter
- func CropRectangle(startX, startY, width, height float32) MergingFilter
- func Rotate(rad float32, interpolation Interpolation) MergingFilter
- func Scale(scaleX, scaleY float32, additive bool, rfilt ResamplingFilter, ...) MergingFilter
- func Transform(transformer Transformer) MergingFilter
- type ResamplingFilter
- type Transformer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ColorFilter ¶
type ColorFilter interface {
// Returns changed color.
Fn(pix pixel) pixel
}
This is a filter used for combining by using CombineColorFilters. Must be a pointer.
var ( // Grayscales an image. Grayscale ColorFilter = ColorFilterFunc(grayscale) )
func ColorFilterFunc ¶
func ColorFilterFunc(fn func(pix pixel) pixel) ColorFilter
type ColorLevels ¶
func (ColorLevels) Add ¶
func (cl1 ColorLevels) Add(cl2 ColorLevels) ColorLevels
func (ColorLevels) Clamp ¶
func (cl ColorLevels) Clamp() ColorLevels
func (ColorLevels) IsZero ¶
func (cl ColorLevels) IsZero() bool
func (ColorLevels) Sub ¶
func (cl1 ColorLevels) Sub(cl2 ColorLevels) ColorLevels
type ColorchanFilter ¶
type ColorchanFilter interface { // Returns changed color channel. Fn(x float32) float32 // Returns true, if it is possible to create a lookup table usign Fn. // Otherwise, returns false. UseLut() bool }
This is a filter used for combining by using CombineColorhanFilters. Must be a pointer.
func ColorchanFilterFunc ¶
func ColorchanFilterFunc(fn func(x float32) float32, useLut bool) ColorchanFilter
type Filter ¶
type Filter interface { // Returns the bounds after applying filter. Bounds(src image.Rectangle) image.Rectangle // Applies the filter to the src image and draws the result to the dst image. Apply(dst draw.Image, src image.Image, parallel bool) }
Filter is an image filter. Must be a pointer.
func CropEllipse ¶
Crops an image with an ellipse of a radii (rx, ry) with the center at a given position (cx, cy). The position and radii parameters must be in the range [0, 1].
type Interpolation ¶
type Interpolation int
const ( NearestNeighborInterpolation Interpolation = iota BilinearInterpolation BicubicInterpolation )
type List ¶
type List struct {
// contains filtered or unexported fields
}
List of filters, which allows applying multiple filters at once. And makes use of filters' Merge, Undo and Skip methods.
type MergingColorFilter ¶
type MergingColorFilter interface { ColorFilter // Prepares the filter before calling Fn multiple times. Prepare() // Returns true, if it is possible to merge one filter into an instance of interface. // Otherwise, returns false. CanMerge(filter ColorFilter) bool // Returns true, if it is possible to demerge one filter from an instance of interface. // Otherwise, returns false. CanUndo(filter ColorFilter) bool // Merges one filter into an instance of interface. Merge(filter ColorFilter) // Demerges one filter from an instance of interface. Undo(filter ColorFilter) // Returns true, if nothing will change after applying the filter. // Otherwise, returns false. Skip() bool // Returns a copy of the filter. Copy() ColorFilter }
This color filter can merge other color filters into itself.
func ColorBalance ¶
func ColorBalance(shadows, midtones, highlights ColorLevels, preserveLuminosity bool) MergingColorFilter
Adjusts color distribution in an image. Each color level must be in the range [-100, 100]. The color levels can have any value for merging purposes.
func Colorize ¶
func Colorize(h, s, l float32) MergingColorFilter
Colorizes an image. The hue parameter must be in the range [0, 360]. The saturation parameter must be in the range [0, 100]. The lightness parameter must be in the range [-100, 100].
func HSB ¶
func HSB(h, s, b float32) MergingColorFilter
Changes HSB of each color in the image. The hue parameter must be in the range [-360, 360]. The saturation and brightness parameters must be in the range [-100, 100]. Each parameter can have any value for merging purposes.
func HSL ¶
func HSL(h, s, l float32) MergingColorFilter
Changes HSL of each color in the image. The hue parameter must be in the range [-360, 360]. The saturation and lightness parameters must be in the range [-100, 100]. Each parameter can have any value for merging purposes.
func Sepia ¶
func Sepia(perc float32) MergingColorFilter
Creates sepia-toned version of an image. The percentage parameter specifies how much the image should be adjusted. It must be in the range [0, 100]. It can be any value for merging purposes.
type MergingColorchanFilter ¶
type MergingColorchanFilter interface { ColorchanFilter // Prepares the filter before calling Fn multiple times. Prepare() // Returns true, if it is possible to merge one filter into an instance of interface. // Otherwise, returns false. CanMerge(filter ColorchanFilter) bool // Returns true, if it is possible to demerge one filter from an instance of interface. // Otherwise, returns false. CanUndo(filter ColorchanFilter) bool // Merges one filter into an instance of interface. Merge(filter ColorchanFilter) // Demerges one filter from an instance of interface. Undo(filter ColorchanFilter) // Returns true, if nothing will change after applying the filter. // Otherwise, returns false. Skip() bool // Returns a copy of the filter. Copy() ColorchanFilter }
This colorhan filter can merge other colorhan filters into itself.
func Brightness ¶
func Brightness(perc float32) MergingColorchanFilter
Changes brightness of an image. The percentage parameter must be in the range [-100, 100]. It can have any value for merging purposes. The percentage = -100 gives solid black image. The percentage = 100 gives solid white image.
func Contrast ¶
func Contrast(perc float32) MergingColorchanFilter
Changes contrast of an image. The percentage parameter must be in the range [-100, 100]. It can have any value for merging purposes. The percentage = -100 gives solid gray image. The percentage = 100 gives an overcontrasted image.
func Gamma ¶
func Gamma(gamma float32) MergingColorchanFilter
Gamma creates a filter that performs a gamma correction on an image. The gamma parameter must be positive. Gamma = 1 gives the original image. Gamma less than 1 darkens the image and gamma greater than 1 lightens it.
type MergingFilter ¶
type MergingFilter interface { Filter // Returns true, if it is possible to merge one filter into an instance of interface. // Otherwise, returns false. CanMerge(filter Filter) bool // Returns true, if it is possible to demerge one filter from an instance of interface. // Otherwise, returns false. CanUndo(filter Filter) bool // Merges one filter into an instance of interface. Merge(filter Filter) // Demerges one filter from an instance of interface. // If got nothing after demerging, returns true. // Otherwise, returns false. Undo(filter Filter) bool // Returns true, if nothing will change after applying the filter. // Otherwise, returns false. Skip() bool // Returns a copy of the filter. Copy() Filter }
This filter can merge other filters into itself.
func CombineColorFilters ¶
func CombineColorFilters(filters ...ColorFilter) MergingFilter
Creates combination of color filters and returns filter.
func CombineColorchanFilters ¶
func CombineColorchanFilters(filters ...ColorchanFilter) MergingFilter
Creates combination of colorchan filters and returns filter.
func CombineFilters ¶
func CombineFilters(filters ...Filter) MergingFilter
Creates combination of filters and returns filter.
func CropRectangle ¶
func CropRectangle(startX, startY, width, height float32) MergingFilter
Crops an image starting at a given position (startX, startY) with a rectangle of a given size (width, height). The position and size parameters must be in the range [0, 1]. Example: You have an image and you want to crop the bottom-right quarter of it. Then pos will be (0.5, 0.5) and size will be (0.5, 0.5).
func Rotate ¶
func Rotate(rad float32, interpolation Interpolation) MergingFilter
Rotates the image using given interpolation method. The angle is given in radians.
func Scale ¶
func Scale(scaleX, scaleY float32, additive bool, rfilt ResamplingFilter, rfiltScaleX, rfiltScaleY float32) MergingFilter
Scales an image by scaleX horizontally and by scaleY vertically using given ResamplingFilter. The scaleX, scaleY, rfiltScaleX, rfiltScaleY parameters must be greater than 0.
If additive true, then scaleX and scaleY parameters will be summed when merging this filter into another. Otherwise, parameters will be multiplied.
The rfiltScaleX and rfiltScaleY values less than 1.0 cause aliasing, but create sharper looking mips. The values greater than 1.0 cause anti-aliasing, but create more blurred looking mips.
func Transform ¶
func Transform(transformer Transformer) MergingFilter
Transform an image using given Transformer.
type ResamplingFilter ¶
var ( NearestNeighborResampling ResamplingFilter = MakeResamplingFilter(nil, 0) BoxResampling ResamplingFilter = MakeResamplingFilter(boxKernel, 0.5) BilinearResampling ResamplingFilter = MakeResamplingFilter(bicubic5Kernel, 1) Bicubic5Resampling ResamplingFilter = MakeResamplingFilter(bicubic5Kernel, 2) Bicubic75Resampling ResamplingFilter = MakeResamplingFilter(bicubic75Kernel, 2) BSplineResampling ResamplingFilter = MakeResamplingFilter(bSplineKernel, 2) MitchellResampling ResamplingFilter = MakeResamplingFilter(mitchellKernel, 2) CatmullRomResampling ResamplingFilter = MakeResamplingFilter(catmullRomKernel, 2) Lanczos3Resampling ResamplingFilter = MakeResamplingFilter(lanczos3Kernel, 3) Lanczos4Resampling ResamplingFilter = MakeResamplingFilter(lanczos4Kernel, 4) Lanczos6Resampling ResamplingFilter = MakeResamplingFilter(lanczos4Kernel, 6) Lanczos12Resampling ResamplingFilter = MakeResamplingFilter(lanczos4Kernel, 12) )
func MakeResamplingFilter ¶
func MakeResamplingFilter(kernel func(x float32) float32, support float32) ResamplingFilter
type Transformer ¶
type Transformer interface { // Returns bounds of the image after transformation. Bounds(src image.Rectangle) image.Rectangle // Returns the new point after transformation. // Last two booleans stand for opposite direction of the x and y coordinates. // Example: if x = 10 and image width = 100, then // setting oppX to true will mean that x = 89. Transform(sx, sy int) (dx, dy int, oppX, oppY bool) // If possible, merges two transformers // and returns a new transformer with true as the second value. // May return nil transformer if got nothing after merge. // If merging isn't possible, returns false as the second value. // And the first returned value is ignored. Merge(in Transformer) (Transformer, bool) // If out := t.Merge(in) then // in := t.Recreate(out) Recreate(in Transformer) (Transformer, bool) }
var ( // Flips an image horizontally. FlipHTransformer Transformer = &fliphTransformer{} // Flips an image vertically. FlipVTransformer Transformer = &flipvTransformer{} // Changes each (x, y) pixel to (y, x) pixel. TransposeTransformer Transformer = &transposeTransformer{} // Changes each (x, y) pixel to (y, x) pixel and rotates // an image by 180 degrees. TransverseTransformer Transformer = &transverseTransformer{} // Rotates an image by 90 degrees. Rotate90Transformer Transformer = &rotate90Transformer{} // Rotates an image by 180 degrees. Rotate180Transformer Transformer = &rotate180Transformer{} // Rotates an image by 270 degrees. Rotate270Transformer Transformer = &rotate270Transformer{} )