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) RGBAConverter = ConverterFunc(rgbaConverter) 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 ColorAtRGBA32(x, y, width int, data, alpha []byte, decode []float64) (color.RGBA, error)
ColorAtRGBA32 gets the 8 bit per component RGBA32 color at 'x', 'y'.
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 InDelta(expected, current, delta float64) bool
InDelta checks if current float value is within 'delta' to the expected one.
func IsGrayImgBlackAndWhite(i *image.Gray) bool
IsGrayImgBlackAndWhite checks if provided gray image is BlackAndWhite - Binary image.
func IsPowerOf2(n uint) bool
IsPowerOf2 checks if provided integer is the power of 2.
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.
func NextPowerOf2(n uint) uint
NextPowerOf2 gets the next power of 2 from provided integer 'n'.
func RasterOperation(dest *Monochrome, dx, dy, dw, dh int, op RasterOperator, src *Monochrome, sx, sy int) error
RasterOperation does the rastering operation on the provided 'dest' bitmap. There are 18 operations, described by the 'op' RasterOperator. The PixDst is a no-op.
PixClr, PixSet, PixNotPixDst operate only on the 'dest'.
The other 14 involve both 'src' and 'dest' bitmaps and depends on the bit values of either just the src or the both 'src' and 'dest'. Out of these 14 operators there are only 12 unique logical combinations. ~(s) ^ d) == ~(s ^ d) == s ^ ~(d). Parameters:
'dest' 'dest' bitmap 'dx' x val of UL corner of 'dest' bitmap 'dy' y val of UL corner of 'dest' bitmap 'dw' is the width of the operational rectangle on the bitmap 'dest' 'dh' is the height of the operational rectangle on the bitmap 'dest' 'op' raster operator code 'src' 'src' bitmap 'sx' x val of UL corner of 'src' bitmap 'sy' y val of UL corner of 'src' bitmap
func ScaleAlphaToMonochrome(data []byte, width, height int) ([]byte, error)
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) AddPadding() (err error)
AddPadding changes the input image data and adds extra padding to last byte of each row, if the number of columns is not divisible by 8.
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) ExpandBinary(factor int) (*Monochrome, error)
ExpandBinary expands the monochrome image by the factor of 2.
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) InverseData() error
InverseData gets the monochrome data inverted - each '1' bit will be '0' and '0' will be '1' besides the additional padding bits.
func (m *Monochrome) IsUnpadded() bool
IsUnpadded checks if the input image has unpadded data.
func (m *Monochrome) RasterOperation(dx, dy, dw, dh int, op RasterOperator, src *Monochrome, sx, sy int) error
RasterOperation has the same function as the RasterOperation package function, where the 'b' bitmap is the 'dest'.
func (m *Monochrome) ReduceBinary(factor float64) (*Monochrome, error)
ReduceBinary scales the binary image to be used for given width and height.
func (m *Monochrome) ResolveDecode() error
ResolveDecode resolves the Decode filter for given image.
func (m *Monochrome) Scale(scale float64) (*Monochrome, error)
Scale scales provided input monochrome image.
func (m *Monochrome) ScaleLow(width, height int) (*Monochrome, error)
ScaleLow is a function that monochrome image into provided width and height.
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) }
RGBA32 implements RGB image with 4 bits.
type RGBA32 struct { ImageBase }
func (i *RGBA32) At(x, y int) color.Color
At implements Image interface.
func (i *RGBA32) Base() *ImageBase
Base implements Image interface.
func (i *RGBA32) Bounds() image.Rectangle
Bounds implements image.Image interface.
func (i *RGBA32) ColorAt(x, y int) (color.Color, error)
ColorAt implements Image interface.
func (i *RGBA32) ColorModel() color.Model
ColorModel implements image.Image interface.
func (i *RGBA32) Copy() Image
Copy implements Image interface.
func (i *RGBA32) RGBAAt(x, y int) color.RGBA
RGBAAt implements RGBA implements.
func (i *RGBA32) Set(x, y int, c color.Color)
Set implements draw.Image interface.
func (i *RGBA32) SetRGBA(x, y int, c color.RGBA)
SetRGBA implements RGBA interface.
func (i *RGBA32) Validate() error
Validate implements Image interface.
RasterOperator is the raster operation flag operator. There are following raster operations:
PixClr 0000 0x0 PixSet 1111 0xf PixSrc s 1100 0xc PixDst d 1010 0xa PixNotSrc ~s 0011 0x3 PixNotDst ~d 0101 0x5 PixSrcOrDst s | d 1110 0xe PixSrcAndDst s & d 1000 0x8 PixSrcXorDst s ^ d 0110 0x6 PixNotSrcOrDst ~s | d 1011 0xb PixNotSrcAndDst ~s & d 0010 0x2 PixSrcOrNotDst s | ~d 1101 0xd PixSrcAndNotDst s & ~d 0100 0x4 PixNotPixSrcOrDst ~(s | d) 0001 0x1 PixNotPixSrcAndDst ~(s & d) 0111 0x7 PixNotPixSrcXorDst ~(s ^ d) 1001 0X9
type RasterOperator int
Raster operator constant definitions.
const ( PixSrc RasterOperator = 0xc PixDst RasterOperator = 0xa PixNotSrc RasterOperator = 0x3 PixNotDst RasterOperator = 0x5 PixClr RasterOperator = 0x0 PixSet RasterOperator = 0xf PixSrcOrDst RasterOperator = 0xe PixSrcAndDst RasterOperator = 0x8 PixSrcXorDst RasterOperator = 0x6 PixNotSrcOrDst RasterOperator = 0xb PixNotSrcAndDst RasterOperator = 0x2 PixSrcOrNotDst RasterOperator = 0xd PixSrcAndNotDst RasterOperator = 0x4 PixNotPixSrcOrDst RasterOperator = 0x1 PixNotPixSrcAndDst RasterOperator = 0x7 PixNotPixSrcXorDst RasterOperator = 0x9 PixPaint = PixSrcOrDst PixSubtract = PixNotSrcAndDst PixMask = PixSrcAndDst )
SMasker is an interface used to get and check the alpha mask from an image.
type SMasker interface { HasAlpha() bool GetAlpha() []byte MakeAlpha() }