Converter implementations.
var ( MonochromeConverter = ConverterFunc(monochromeTriangleConverter) Gray2Converter = ConverterFunc(gray2Converter) Gray4Converter = ConverterFunc(gray4Converter) GrayConverter = ConverterFunc(grayConverter) Gray16Converter = ConverterFunc(gray16Converter) NRGBA16Converter = ConverterFunc(nrgba16Converter) NRGBAConverter = ConverterFunc(nrgbaConverter) NRGBA64Converter = ConverterFunc(nrgba64Converter) CMYKConverter = ConverterFunc(cmykConverter) )
Additional models for images.
var ( Gray2Model = color.ModelFunc(gray2Model) Gray4Model = color.ModelFunc(gray4Model) NRGBA16Model = color.ModelFunc(nrgba16Model) )
ErrInvalidImage is an error used when provided image is invalid.
var ErrInvalidImage = errors.New("invalid image data size for provided dimensions")
func AddDataPadding(width, height, bitsPerComponent, colorComponents int, data []byte) ([]byte, error)
AddDataPadding adds the row bit padding to the given data slice if it is required by the image parameters.
func AutoThresholdTriangle(histogram [256]int) uint8
AutoThresholdTriangle is a function that returns threshold value on the base of provided histogram. It is calculated using triangle method.
func BytesPerLine(width, bitsPerComponent, colorComponents int) int
BytesPerLine gets the number of bytes per line for given width, bits per color and color components number.
func ColorAt(x, y, width, bitsPerColor, colorComponents, bytesPerLine int, data, alpha []byte, decode []float64) (color.Color, error)
ColorAt gets the color of the image with provided parameters.
Parameters: x - horizontal coordinate of the pixel. y - vertical coordinate of the pixel. width - the width of the image. bitsPerColor - number of bits per color component. colorComponents - number of color components per pixel. bytesPerLine - number of bytes per line. data - byte slice data for given image. alpha - (optional) the alpha part data slice of the image.
func ColorAtCMYK(x, y, width int, data []byte, decode []float64) (color.CMYK, error)
ColorAtCMYK gets the color at CMYK32 colorspace at 'x' and 'y' position for an image with specific 'width'.
func ColorAtGray16BPC(x, y, bytesPerLine int, data []byte, decode []float64) (color.Gray16, error)
ColorAtGray16BPC gets the color of image in grayscale color space with 8 bits per component specific 'width', 'bytesPerLine' and 'data' at the 'x' and 'y' coordinates position.
func ColorAtGray1BPC(x, y, bytesPerLine int, data []byte, decode []float64) (color.Gray, error)
ColorAtGray1BPC gets the color of image in grayscale color space with one bit per component specific 'width', 'bytesPerLine' and 'data' at the 'x' and 'y' coordinates position.
func ColorAtGray2BPC(x, y, bytesPerLine int, data []byte, decode []float64) (color.Gray, error)
ColorAtGray2BPC gets the color of image in grayscale color space with two bits per component specific 'width', 'bytesPerLine' and 'data' at the 'x' and 'y' coordinates position.
func ColorAtGray4BPC(x, y, bytesPerLine int, data []byte, decode []float64) (color.Gray, error)
ColorAtGray4BPC gets the color of image in grayscale color space with 4 bits per component specific 'width', 'bytesPerLine' and 'data' at the 'x' and 'y' coordinates position.
func ColorAtGray8BPC(x, y, bytesPerLine int, data []byte, decode []float64) (color.Gray, error)
ColorAtGray8BPC gets the color of image in grayscale color space with 8 bits per component specific 'width', 'bytesPerLine' and 'data' at the 'x' and 'y' coordinates position.
func ColorAtGrayscale(x, y, bitsPerColor, bytesPerLine int, data []byte, decode []float64) (color.Color, error)
ColorAtGrayscale gets the color of the grayscale image with specific 'width', 'bitsPerColor' and 'data' at the 'x' and 'y' coordinates position.
func ColorAtNRGBA(x, y, width, bytesPerLine, bitsPerColor int, data, alpha []byte, decode []float64) (color.Color, error)
ColorAtNRGBA gets the color of the image with specific 'width' and 'bitsPerColor' at 'x' and 'y' coordinates. The 'data' defines image data and optional 'alpha' alpha component of the color.
func ColorAtNRGBA16(x, y, width, bytesPerLine int, data, alpha []byte, decode []float64) (color.NRGBA, error)
ColorAtNRGBA16 gets the 4 bit per component NRGBA32 color at 'x', 'y' coordinates.
func ColorAtNRGBA32(x, y, width int, data, alpha []byte, decode []float64) (color.NRGBA, error)
ColorAtNRGBA32 gets the 8 bit per component NRGBA32 color at 'x', 'y'.
func ColorAtNRGBA64(x, y, width int, data, alpha []byte, decode []float64) (color.NRGBA64, error)
ColorAtNRGBA64 gets 16 bit per component NRGBA64 color.
func GrayHistogram(g Gray) (histogram [256]int)
GrayHistogram gets histogram for the provided Gray image.
func ImgToBinary(i image.Image, threshold uint8) *image.Gray
ImgToBinary gets the binary (black/white) image from the given image 'i' and provided threshold 'threshold'
func ImgToGray(i image.Image) *image.Gray
ImgToGray gets the gray-scaled image from the given 'i' image.
func IsGrayImgBlackAndWhite(i *image.Gray) bool
IsGrayImgBlackAndWhite checks if provided gray image is BlackAndWhite - Binary image.
func LinearInterpolate(x, xmin, xmax, ymin, ymax float64) float64
LinearInterpolate is the simple linear interpolation from the PDF manual - PDF 32000-1:2008 - 7.10.2.
func MonochromeModel(threshold uint8) color.Model
MonochromeModel is the monochrome color Model that relates on given threshold.
CMYK is the interface used for getting and operation on the CMYK interface.
type CMYK interface { CMYKAt(x, y int) color.CMYK SetCMYK(x, y int, c color.CMYK) }
CMYK32 is an Image implementation for the CMYK32 color colorConverter.
type CMYK32 struct { ImageBase }
func (i *CMYK32) At(x, y int) color.Color
At implements image.Image interface.
func (i *CMYK32) Base() *ImageBase
Base implements Image interface.
func (i *CMYK32) Bounds() image.Rectangle
Bounds implements image.Image interface.
func (i *CMYK32) CMYKAt(x, y int) color.CMYK
CMYKAt implements CMYK interface.
func (i *CMYK32) ColorAt(x, y int) (color.Color, error)
ColorAt implements Image interface.
func (i *CMYK32) ColorModel() color.Model
ColorModel implements image.Image interface.
func (i *CMYK32) Copy() Image
Copy implements Image interface.
func (i *CMYK32) Set(x, y int, c color.Color)
Set implements draw.Image interface.
func (i *CMYK32) SetCMYK(x, y int, c color.CMYK)
SetCMYK implements CMYK interface.
func (i *CMYK32) Validate() error
Validate implements Image interface.
ColorConverter is an interface that allows to convert images between different color spaces.
type ColorConverter interface { // Convert converts images to given color colorConverter. Convert(src image.Image) (Image, error) }
func ConverterFunc(converterFunc func(img image.Image) (Image, error)) ColorConverter
ConverterFunc creates new colorConverter based on the provided 'paletteFunc'.
func GetConverter(bitsPerComponent, colorComponents int) (ColorConverter, error)
GetConverter gets the color converter for given bits per component (bit depth) and color components parameters.
func MonochromeThresholdConverter(threshold uint8) ColorConverter
MonochromeThresholdConverter creates a new monochrome colorConverter.
Gray is an interface that allows to get and set color.Gray for grayscale images.
type Gray interface { GrayAt(x, y int) color.Gray SetGray(x, y int, g color.Gray) }
Gray16 is a grayscale image where gray pixel is of 16-bit size.
type Gray16 struct { ImageBase }
func (i *Gray16) At(x, y int) color.Color
At implements image.Image interface.
func (i *Gray16) Base() *ImageBase
Base implements Image interface.
func (i *Gray16) Bounds() image.Rectangle
Bounds implements image.Image interface.
func (i *Gray16) ColorAt(x, y int) (color.Color, error)
ColorAt implements Image interface.
func (i *Gray16) ColorModel() color.Model
ColorModel implements image.Image interface.
func (i *Gray16) Copy() Image
Copy implements Image interface.
func (i *Gray16) GrayAt(x, y int) color.Gray
GrayAt implements Gray interface.
func (i *Gray16) Histogram() (histogram [256]int)
Histogram implements Histogramer interface.
func (i *Gray16) Set(x, y int, c color.Color)
Set implements draw.Image interface.
func (i *Gray16) SetGray(x, y int, g color.Gray)
SetGray implements Gray interface.
func (i *Gray16) Validate() error
Validate implements Image interface.
Gray2 is a 2-bit base grayscale image. It implements image.Image, draw.Image, Image and Gray interfaces.
type Gray2 struct { ImageBase }
func (i *Gray2) At(x, y int) color.Color
At implements image.Image interface.
func (i *Gray2) Base() *ImageBase
Base implements Image interface.
func (i *Gray2) Bounds() image.Rectangle
Bounds implements
func (i *Gray2) ColorAt(x, y int) (color.Color, error)
ColorAt implements Image interface.
func (i *Gray2) ColorModel() color.Model
ColorModel implements image.Image interface.
func (i *Gray2) Copy() Image
Copy implements Image interface.
func (i *Gray2) GrayAt(x, y int) color.Gray
GrayAt implements Gray interface.
func (i *Gray2) Histogram() (histogram [256]int)
Histogram implements Histogramer interface.
func (i *Gray2) Set(x, y int, c color.Color)
Set implements draw.Image interface.
func (i *Gray2) SetGray(x, y int, gray color.Gray)
SetGray implements Gray interface.
func (i *Gray2) Validate() error
Validate implements Image interface.
Gray4 is a grayscale image implementation where the gray pixel is stored in 4 bits.
type Gray4 struct { ImageBase }
func (i *Gray4) At(x, y int) color.Color
At implements image.Image interface.
func (i *Gray4) Base() *ImageBase
Base implements Image interface.
func (i *Gray4) Bounds() image.Rectangle
Bounds implements image.Image interface.
func (i *Gray4) ColorAt(x, y int) (color.Color, error)
ColorAt implements Image interface.
func (i *Gray4) ColorModel() color.Model
ColorModel implements image.Image interface.
func (i *Gray4) Copy() Image
Copy creates a copy of given image.
func (i *Gray4) GrayAt(x, y int) color.Gray
GrayAt implements Gray interface.
func (i *Gray4) Histogram() (histogram [256]int)
Histogram implements Histogramer interface.
func (i *Gray4) Set(x, y int, c color.Color)
Set for given image sets color 'c' at coordinates 'x' and 'y'.
func (i *Gray4) SetGray(x, y int, g color.Gray)
SetGray implements Gray interface.
func (i *Gray4) Validate() error
Validate implements Image interface.
Gray8 is a grayscale image with the gray pixel size of 8-bit.
type Gray8 struct { ImageBase }
func (i *Gray8) At(x, y int) color.Color
At implements image.Image interface.
func (i *Gray8) Base() *ImageBase
Base implements image interface.
func (i *Gray8) Bounds() image.Rectangle
Bounds implements image.Image interface.
func (i *Gray8) ColorAt(x, y int) (color.Color, error)
ColorAt implements Image interface.
func (i *Gray8) ColorModel() color.Model
ColorModel implements image.Image interface.`
func (i *Gray8) Copy() Image
Copy implements Image interface.
func (i *Gray8) GrayAt(x, y int) color.Gray
GrayAt implements Gray interface.
func (i *Gray8) Histogram() (histogram [256]int)
Histogram implements Histogramer interface.
func (i *Gray8) Set(x, y int, c color.Color)
Set implements draw.Image interface.
func (i *Gray8) SetGray(x, y int, g color.Gray)
SetGray implements Gray interface.
func (i *Gray8) Validate() error
Validate implements Image interface.
Histogramer is an interface that allows to get a histogram from the image.
type Histogramer interface { Histogram() [256]int }
Image is an interface used that allows to do image operations.
type Image interface { draw.Image Base() *ImageBase Copy() Image Pix() []byte ColorAt(x, y int) (color.Color, error) Validate() error }
func FromGoImage(i image.Image) (Image, error)
FromGoImage creates a new Image from provided image 'i'.
func NewImage(width, height, bitsPerComponent, colorComponents int, data, alpha []byte, decode []float64) (Image, error)
NewImage creates new image for provided image parameters and image data byte slice.
ImageBase is a structure that represents an bitmap image.
type ImageBase struct { Width, Height int BitsPerComponent, ColorComponents int Data, Alpha []byte Decode []float64 BytesPerLine int }
func NewImageBase(width int, height int, bitsPerComponent int, colorComponents int, data []byte, alpha []byte, decode []float64) ImageBase
NewImageBase creates new image base.
func (i *ImageBase) GetAlpha() []byte
GetAlpha implements SMasker interface.
func (i *ImageBase) HasAlpha() bool
HasAlpha implements SMasker interface.
func (i *ImageBase) MakeAlpha()
MakeAlpha implements SMasker interface.
func (i *ImageBase) Pix() []byte
Pix implements Image interface.
Monochrome is a grayscale image with a 1-bit per pixel.
type Monochrome struct { ImageBase ModelThreshold uint8 }
func (m *Monochrome) At(x, y int) color.Color
At implements image.Image interface.
func (m *Monochrome) Base() *ImageBase
Base implements Image interface.
func (m *Monochrome) Bounds() image.Rectangle
Bounds implements image.Image.
func (m *Monochrome) ColorAt(x, y int) (color.Color, error)
ColorAt implements Image interface.
func (m *Monochrome) ColorModel() color.Model
ColorModel implements image.Image interface.
func (m *Monochrome) Copy() Image
Copy implements Image interface.
func (m *Monochrome) GrayAt(x, y int) color.Gray
GrayAt implements Gray interface.
func (m *Monochrome) Histogram() (histogram [256]int)
Histogram implements Histogramer interface.
func (m *Monochrome) Set(x, y int, c color.Color)
Set implements draw.Image interface.
func (m *Monochrome) SetGray(x, y int, g color.Gray)
SetGray implements Gray interface.
func (m *Monochrome) Validate() error
Validate implements Image interface.
NRGBA is the interface for all NRGBA images.
type NRGBA interface { // NRGBAAt gets the NRGBA color at the coordinates 'x', 'y'. NRGBAAt(x, y int) color.NRGBA // SetNRGBA sets the NRGBA color at the coordinates 'x', 'y'. SetNRGBA(x, y int, c color.NRGBA) }
NRGBA16 implements RGB image with 4 bits.
type NRGBA16 struct { ImageBase }
func (i *NRGBA16) At(x, y int) color.Color
At implements Image interface.
func (i *NRGBA16) Base() *ImageBase
Base implements Image interface.
func (i *NRGBA16) Bounds() image.Rectangle
Bounds implements image.Image interface.
func (i *NRGBA16) ColorAt(x, y int) (color.Color, error)
ColorAt implements Image interface.
func (i *NRGBA16) ColorModel() color.Model
ColorModel implements image.Image interface.
func (i *NRGBA16) Copy() Image
Copy implements Image interface.
func (i *NRGBA16) NRGBAAt(x, y int) color.NRGBA
NRGBAAt implements NRGBA interface.
func (i *NRGBA16) Set(x, y int, c color.Color)
Set implements draw.Image interface.
func (i *NRGBA16) SetNRGBA(x, y int, c color.NRGBA)
SetNRGBA implements NRGBA interface.
func (i *NRGBA16) Validate() error
Validate implements Image interface.
NRGBA32 implements RGB image with 4 bits.
type NRGBA32 struct { ImageBase }
func (i *NRGBA32) At(x, y int) color.Color
At implements Image interface.
func (i *NRGBA32) Base() *ImageBase
Base implements Image interface.
func (i *NRGBA32) Bounds() image.Rectangle
Bounds implements image.Image interface.
func (i *NRGBA32) ColorAt(x, y int) (color.Color, error)
ColorAt implements Image interface.
func (i *NRGBA32) ColorModel() color.Model
ColorModel implements image.Image interface.
func (i *NRGBA32) Copy() Image
Copy implements Image interface.
func (i *NRGBA32) NRGBAAt(x, y int) color.NRGBA
NRGBAAt implements NRGBA implements.
func (i *NRGBA32) Set(x, y int, c color.Color)
Set implements draw.Image interface.
func (i *NRGBA32) SetNRGBA(x, y int, c color.NRGBA)
SetNRGBA implements NRGBA interface.
func (i *NRGBA32) Validate() error
Validate implements Image interface.
NRGBA64 implements RGB image with 4 bits.
type NRGBA64 struct { ImageBase }
func (i *NRGBA64) At(x, y int) color.Color
At implements image.Image interface.
func (i *NRGBA64) Base() *ImageBase
Base implements Image interface.
func (i *NRGBA64) Bounds() image.Rectangle
Bounds implements image.Image interface.
func (i *NRGBA64) ColorAt(x, y int) (color.Color, error)
ColorAt implements Image interface.
func (i *NRGBA64) ColorModel() color.Model
ColorModel implements image.Image interface.
func (i *NRGBA64) Copy() Image
Copy implements Image interface.
func (i *NRGBA64) NRGBA64At(x, y int) color.NRGBA64
NRGBA64At gets color.NRGBA64 at 'x' and 'y'.
func (i *NRGBA64) Set(x, y int, c color.Color)
Set implements draw.Image interface.
func (i *NRGBA64) SetNRGBA64(x, y int, c color.NRGBA64)
SetNRGBA64 sets the 'NRGBA64' color at 'x' and 'y' coordinates.
func (i *NRGBA64) Validate() error
Validate implements Image interface.
RGBA is the interface that allows to get and set RGBA images.
type RGBA interface { // RGBAAt gets the RGBA color at the coordinates 'x', 'y'. RGBAAt(x, y int) color.RGBA // SetRGBA sets the RGBA color at the coordinates 'x', 'y'. SetRGBA(x, y int, c color.RGBA) }
SMasker is an interface used to get and check the alpha mask from an image.
type SMasker interface { HasAlpha() bool GetAlpha() []byte MakeAlpha() }