HomeUniDoc
...

Package imageutil

Overview ▾

Package imageutil provides utility functions, structures and interfaces that allows to operate on images. The function NewImage creates a new Image implementation based on provided input parameters. The functions ColorXXXAt allows to get the the colors from provided data and parameters without the need of creating image abstraction. Image converters allows to convert between different color spaces. As Image interface implements also image.Image it was possible to use standard golang image.Image as an input for the converters.

Index ▾

Variables
func AddDataPadding(width, height, bitsPerComponent, colorComponents int, data []byte) ([]byte, error)
func AutoThresholdTriangle(histogram [256]int) uint8
func BytesPerLine(width, bitsPerComponent, colorComponents int) int
func ColorAt(x, y, width, bitsPerColor, colorComponents, bytesPerLine int, data, alpha []byte, decode []float64) (color.Color, error)
func ColorAtCMYK(x, y, width int, data []byte, decode []float64) (color.CMYK, error)
func ColorAtGray16BPC(x, y, bytesPerLine int, data []byte, decode []float64) (color.Gray16, error)
func ColorAtGray1BPC(x, y, bytesPerLine int, data []byte, decode []float64) (color.Gray, error)
func ColorAtGray2BPC(x, y, bytesPerLine int, data []byte, decode []float64) (color.Gray, error)
func ColorAtGray4BPC(x, y, bytesPerLine int, data []byte, decode []float64) (color.Gray, error)
func ColorAtGray8BPC(x, y, bytesPerLine int, data []byte, decode []float64) (color.Gray, error)
func ColorAtGrayscale(x, y, bitsPerColor, bytesPerLine int, data []byte, decode []float64) (color.Color, error)
func ColorAtNRGBA(x, y, width, bytesPerLine, bitsPerColor int, data, alpha []byte, decode []float64) (color.Color, error)
func ColorAtNRGBA16(x, y, width, bytesPerLine int, data, alpha []byte, decode []float64) (color.NRGBA, error)
func ColorAtNRGBA32(x, y, width int, data, alpha []byte, decode []float64) (color.NRGBA, error)
func ColorAtNRGBA64(x, y, width int, data, alpha []byte, decode []float64) (color.NRGBA64, error)
func ColorAtRGBA32(x, y, width int, data, alpha []byte, decode []float64) (color.RGBA, error)
func GrayHistogram(g Gray) (histogram [256]int)
func ImgToBinary(i image.Image, threshold uint8) *image.Gray
func ImgToGray(i image.Image) *image.Gray
func InDelta(expected, current, delta float64) bool
func IsGrayImgBlackAndWhite(i *image.Gray) bool
func IsPowerOf2(n uint) bool
func LinearInterpolate(x, xmin, xmax, ymin, ymax float64) float64
func MonochromeModel(threshold uint8) color.Model
func NextPowerOf2(n uint) uint
func RasterOperation(dest *Monochrome, dx, dy, dw, dh int, op RasterOperator, src *Monochrome, sx, sy int) error
func ScaleAlphaToMonochrome(data []byte, width, height int) ([]byte, error)
type CMYK
type CMYK32
    func (i *CMYK32) At(x, y int) color.Color
    func (i *CMYK32) Base() *ImageBase
    func (i *CMYK32) Bounds() image.Rectangle
    func (i *CMYK32) CMYKAt(x, y int) color.CMYK
    func (i *CMYK32) ColorAt(x, y int) (color.Color, error)
    func (i *CMYK32) ColorModel() color.Model
    func (i *CMYK32) Copy() Image
    func (i *CMYK32) Set(x, y int, c color.Color)
    func (i *CMYK32) SetCMYK(x, y int, c color.CMYK)
    func (i *CMYK32) Validate() error
type ColorConverter
    func ConverterFunc(converterFunc func(img image.Image) (Image, error)) ColorConverter
    func GetConverter(bitsPerComponent, colorComponents int) (ColorConverter, error)
    func MonochromeThresholdConverter(threshold uint8) ColorConverter
type Gray
type Gray16
    func (i *Gray16) At(x, y int) color.Color
    func (i *Gray16) Base() *ImageBase
    func (i *Gray16) Bounds() image.Rectangle
    func (i *Gray16) ColorAt(x, y int) (color.Color, error)
    func (i *Gray16) ColorModel() color.Model
    func (i *Gray16) Copy() Image
    func (i *Gray16) GrayAt(x, y int) color.Gray
    func (i *Gray16) Histogram() (histogram [256]int)
    func (i *Gray16) Set(x, y int, c color.Color)
    func (i *Gray16) SetGray(x, y int, g color.Gray)
    func (i *Gray16) Validate() error
type Gray2
    func (i *Gray2) At(x, y int) color.Color
    func (i *Gray2) Base() *ImageBase
    func (i *Gray2) Bounds() image.Rectangle
    func (i *Gray2) ColorAt(x, y int) (color.Color, error)
    func (i *Gray2) ColorModel() color.Model
    func (i *Gray2) Copy() Image
    func (i *Gray2) GrayAt(x, y int) color.Gray
    func (i *Gray2) Histogram() (histogram [256]int)
    func (i *Gray2) Set(x, y int, c color.Color)
    func (i *Gray2) SetGray(x, y int, gray color.Gray)
    func (i *Gray2) Validate() error
type Gray4
    func (i *Gray4) At(x, y int) color.Color
    func (i *Gray4) Base() *ImageBase
    func (i *Gray4) Bounds() image.Rectangle
    func (i *Gray4) ColorAt(x, y int) (color.Color, error)
    func (i *Gray4) ColorModel() color.Model
    func (i *Gray4) Copy() Image
    func (i *Gray4) GrayAt(x, y int) color.Gray
    func (i *Gray4) Histogram() (histogram [256]int)
    func (i *Gray4) Set(x, y int, c color.Color)
    func (i *Gray4) SetGray(x, y int, g color.Gray)
    func (i *Gray4) Validate() error
type Gray8
    func (i *Gray8) At(x, y int) color.Color
    func (i *Gray8) Base() *ImageBase
    func (i *Gray8) Bounds() image.Rectangle
    func (i *Gray8) ColorAt(x, y int) (color.Color, error)
    func (i *Gray8) ColorModel() color.Model
    func (i *Gray8) Copy() Image
    func (i *Gray8) GrayAt(x, y int) color.Gray
    func (i *Gray8) Histogram() (histogram [256]int)
    func (i *Gray8) Set(x, y int, c color.Color)
    func (i *Gray8) SetGray(x, y int, g color.Gray)
    func (i *Gray8) Validate() error
type Histogramer
type Image
    func FromGoImage(i image.Image) (Image, error)
    func NewImage(width, height, bitsPerComponent, colorComponents int, data, alpha []byte, decode []float64) (Image, error)
type ImageBase
    func NewImageBase(width int, height int, bitsPerComponent int, colorComponents int, data []byte, alpha []byte, decode []float64) ImageBase
    func (i *ImageBase) GetAlpha() []byte
    func (i *ImageBase) HasAlpha() bool
    func (i *ImageBase) MakeAlpha()
    func (i *ImageBase) Pix() []byte
type Monochrome
    func (m *Monochrome) AddPadding() (err error)
    func (m *Monochrome) At(x, y int) color.Color
    func (m *Monochrome) Base() *ImageBase
    func (m *Monochrome) Bounds() image.Rectangle
    func (m *Monochrome) ColorAt(x, y int) (color.Color, error)
    func (m *Monochrome) ColorModel() color.Model
    func (m *Monochrome) Copy() Image
    func (m *Monochrome) ExpandBinary(factor int) (*Monochrome, error)
    func (m *Monochrome) GrayAt(x, y int) color.Gray
    func (m *Monochrome) Histogram() (histogram [256]int)
    func (m *Monochrome) InverseData() error
    func (m *Monochrome) IsUnpadded() bool
    func (m *Monochrome) RasterOperation(dx, dy, dw, dh int, op RasterOperator, src *Monochrome, sx, sy int) error
    func (m *Monochrome) ReduceBinary(factor float64) (*Monochrome, error)
    func (m *Monochrome) ResolveDecode() error
    func (m *Monochrome) Scale(scale float64) (*Monochrome, error)
    func (m *Monochrome) ScaleLow(width, height int) (*Monochrome, error)
    func (m *Monochrome) Set(x, y int, c color.Color)
    func (m *Monochrome) SetGray(x, y int, g color.Gray)
    func (m *Monochrome) Validate() error
type NRGBA
type NRGBA16
    func (i *NRGBA16) At(x, y int) color.Color
    func (i *NRGBA16) Base() *ImageBase
    func (i *NRGBA16) Bounds() image.Rectangle
    func (i *NRGBA16) ColorAt(x, y int) (color.Color, error)
    func (i *NRGBA16) ColorModel() color.Model
    func (i *NRGBA16) Copy() Image
    func (i *NRGBA16) NRGBAAt(x, y int) color.NRGBA
    func (i *NRGBA16) Set(x, y int, c color.Color)
    func (i *NRGBA16) SetNRGBA(x, y int, c color.NRGBA)
    func (i *NRGBA16) Validate() error
type NRGBA32
    func (i *NRGBA32) At(x, y int) color.Color
    func (i *NRGBA32) Base() *ImageBase
    func (i *NRGBA32) Bounds() image.Rectangle
    func (i *NRGBA32) ColorAt(x, y int) (color.Color, error)
    func (i *NRGBA32) ColorModel() color.Model
    func (i *NRGBA32) Copy() Image
    func (i *NRGBA32) NRGBAAt(x, y int) color.NRGBA
    func (i *NRGBA32) Set(x, y int, c color.Color)
    func (i *NRGBA32) SetNRGBA(x, y int, c color.NRGBA)
    func (i *NRGBA32) Validate() error
type NRGBA64
    func (i *NRGBA64) At(x, y int) color.Color
    func (i *NRGBA64) Base() *ImageBase
    func (i *NRGBA64) Bounds() image.Rectangle
    func (i *NRGBA64) ColorAt(x, y int) (color.Color, error)
    func (i *NRGBA64) ColorModel() color.Model
    func (i *NRGBA64) Copy() Image
    func (i *NRGBA64) NRGBA64At(x, y int) color.NRGBA64
    func (i *NRGBA64) Set(x, y int, c color.Color)
    func (i *NRGBA64) SetNRGBA64(x, y int, c color.NRGBA64)
    func (i *NRGBA64) Validate() error
type RGBA
type RGBA32
    func (i *RGBA32) At(x, y int) color.Color
    func (i *RGBA32) Base() *ImageBase
    func (i *RGBA32) Bounds() image.Rectangle
    func (i *RGBA32) ColorAt(x, y int) (color.Color, error)
    func (i *RGBA32) ColorModel() color.Model
    func (i *RGBA32) Copy() Image
    func (i *RGBA32) RGBAAt(x, y int) color.RGBA
    func (i *RGBA32) Set(x, y int, c color.Color)
    func (i *RGBA32) SetRGBA(x, y int, c color.RGBA)
    func (i *RGBA32) Validate() error
type RasterOperator
type SMasker

Package files

alpha.go bin-expand.go bin-reduce.go cmyk.go colors.go doc.go grayscale.go image.go interpolate.go math.go padding.go raster.go rgb.go rgbtobw.go

Variables

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

func ColorAtNRGBA64(x, y, width int, data, alpha []byte, decode []float64) (color.NRGBA64, error)

ColorAtNRGBA64 gets 16 bit per component NRGBA64 color.

func ColorAtRGBA32

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

func GrayHistogram(g Gray) (histogram [256]int)

GrayHistogram gets histogram for the provided Gray image.

func ImgToBinary

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

func ImgToGray(i image.Image) *image.Gray

ImgToGray gets the gray-scaled image from the given 'i' image.

func InDelta

func InDelta(expected, current, delta float64) bool

InDelta checks if current float value is within 'delta' to the expected one.

func IsGrayImgBlackAndWhite

func IsGrayImgBlackAndWhite(i *image.Gray) bool

IsGrayImgBlackAndWhite checks if provided gray image is BlackAndWhite - Binary image.

func IsPowerOf2

func IsPowerOf2(n uint) bool

IsPowerOf2 checks if provided integer is the power of 2.

func LinearInterpolate

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

func MonochromeModel(threshold uint8) color.Model

MonochromeModel is the monochrome color Model that relates on given threshold.

func NextPowerOf2

func NextPowerOf2(n uint) uint

NextPowerOf2 gets the next power of 2 from provided integer 'n'.

func RasterOperation

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

func ScaleAlphaToMonochrome(data []byte, width, height int) ([]byte, error)

type CMYK

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)
}

type CMYK32

CMYK32 is an Image implementation for the CMYK32 color colorConverter.

type CMYK32 struct {
    ImageBase
}

func (*CMYK32) At

func (i *CMYK32) At(x, y int) color.Color

At implements image.Image interface.

func (*CMYK32) Base

func (i *CMYK32) Base() *ImageBase

Base implements Image interface.

func (*CMYK32) Bounds

func (i *CMYK32) Bounds() image.Rectangle

Bounds implements image.Image interface.

func (*CMYK32) CMYKAt

func (i *CMYK32) CMYKAt(x, y int) color.CMYK

CMYKAt implements CMYK interface.

func (*CMYK32) ColorAt

func (i *CMYK32) ColorAt(x, y int) (color.Color, error)

ColorAt implements Image interface.

func (*CMYK32) ColorModel

func (i *CMYK32) ColorModel() color.Model

ColorModel implements image.Image interface.

func (*CMYK32) Copy

func (i *CMYK32) Copy() Image

Copy implements Image interface.

func (*CMYK32) Set

func (i *CMYK32) Set(x, y int, c color.Color)

Set implements draw.Image interface.

func (*CMYK32) SetCMYK

func (i *CMYK32) SetCMYK(x, y int, c color.CMYK)

SetCMYK implements CMYK interface.

func (*CMYK32) Validate

func (i *CMYK32) Validate() error

Validate implements Image interface.

type ColorConverter

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

func ConverterFunc(converterFunc func(img image.Image) (Image, error)) ColorConverter

ConverterFunc creates new colorConverter based on the provided 'paletteFunc'.

func GetConverter

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

func MonochromeThresholdConverter(threshold uint8) ColorConverter

MonochromeThresholdConverter creates a new monochrome colorConverter.

type Gray

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)
}

type Gray16

Gray16 is a grayscale image where gray pixel is of 16-bit size.

type Gray16 struct {
    ImageBase
}

func (*Gray16) At

func (i *Gray16) At(x, y int) color.Color

At implements image.Image interface.

func (*Gray16) Base

func (i *Gray16) Base() *ImageBase

Base implements Image interface.

func (*Gray16) Bounds

func (i *Gray16) Bounds() image.Rectangle

Bounds implements image.Image interface.

func (*Gray16) ColorAt

func (i *Gray16) ColorAt(x, y int) (color.Color, error)

ColorAt implements Image interface.

func (*Gray16) ColorModel

func (i *Gray16) ColorModel() color.Model

ColorModel implements image.Image interface.

func (*Gray16) Copy

func (i *Gray16) Copy() Image

Copy implements Image interface.

func (*Gray16) GrayAt

func (i *Gray16) GrayAt(x, y int) color.Gray

GrayAt implements Gray interface.

func (*Gray16) Histogram

func (i *Gray16) Histogram() (histogram [256]int)

Histogram implements Histogramer interface.

func (*Gray16) Set

func (i *Gray16) Set(x, y int, c color.Color)

Set implements draw.Image interface.

func (*Gray16) SetGray

func (i *Gray16) SetGray(x, y int, g color.Gray)

SetGray implements Gray interface.

func (*Gray16) Validate

func (i *Gray16) Validate() error

Validate implements Image interface.

type Gray2

Gray2 is a 2-bit base grayscale image. It implements image.Image, draw.Image, Image and Gray interfaces.

type Gray2 struct {
    ImageBase
}

func (*Gray2) At

func (i *Gray2) At(x, y int) color.Color

At implements image.Image interface.

func (*Gray2) Base

func (i *Gray2) Base() *ImageBase

Base implements Image interface.

func (*Gray2) Bounds

func (i *Gray2) Bounds() image.Rectangle

Bounds implements

func (*Gray2) ColorAt

func (i *Gray2) ColorAt(x, y int) (color.Color, error)

ColorAt implements Image interface.

func (*Gray2) ColorModel

func (i *Gray2) ColorModel() color.Model

ColorModel implements image.Image interface.

func (*Gray2) Copy

func (i *Gray2) Copy() Image

Copy implements Image interface.

func (*Gray2) GrayAt

func (i *Gray2) GrayAt(x, y int) color.Gray

GrayAt implements Gray interface.

func (*Gray2) Histogram

func (i *Gray2) Histogram() (histogram [256]int)

Histogram implements Histogramer interface.

func (*Gray2) Set

func (i *Gray2) Set(x, y int, c color.Color)

Set implements draw.Image interface.

func (*Gray2) SetGray

func (i *Gray2) SetGray(x, y int, gray color.Gray)

SetGray implements Gray interface.

func (*Gray2) Validate

func (i *Gray2) Validate() error

Validate implements Image interface.

type Gray4

Gray4 is a grayscale image implementation where the gray pixel is stored in 4 bits.

type Gray4 struct {
    ImageBase
}

func (*Gray4) At

func (i *Gray4) At(x, y int) color.Color

At implements image.Image interface.

func (*Gray4) Base

func (i *Gray4) Base() *ImageBase

Base implements Image interface.

func (*Gray4) Bounds

func (i *Gray4) Bounds() image.Rectangle

Bounds implements image.Image interface.

func (*Gray4) ColorAt

func (i *Gray4) ColorAt(x, y int) (color.Color, error)

ColorAt implements Image interface.

func (*Gray4) ColorModel

func (i *Gray4) ColorModel() color.Model

ColorModel implements image.Image interface.

func (*Gray4) Copy

func (i *Gray4) Copy() Image

Copy creates a copy of given image.

func (*Gray4) GrayAt

func (i *Gray4) GrayAt(x, y int) color.Gray

GrayAt implements Gray interface.

func (*Gray4) Histogram

func (i *Gray4) Histogram() (histogram [256]int)

Histogram implements Histogramer interface.

func (*Gray4) Set

func (i *Gray4) Set(x, y int, c color.Color)

Set for given image sets color 'c' at coordinates 'x' and 'y'.

func (*Gray4) SetGray

func (i *Gray4) SetGray(x, y int, g color.Gray)

SetGray implements Gray interface.

func (*Gray4) Validate

func (i *Gray4) Validate() error

Validate implements Image interface.

type Gray8

Gray8 is a grayscale image with the gray pixel size of 8-bit.

type Gray8 struct {
    ImageBase
}

func (*Gray8) At

func (i *Gray8) At(x, y int) color.Color

At implements image.Image interface.

func (*Gray8) Base

func (i *Gray8) Base() *ImageBase

Base implements image interface.

func (*Gray8) Bounds

func (i *Gray8) Bounds() image.Rectangle

Bounds implements image.Image interface.

func (*Gray8) ColorAt

func (i *Gray8) ColorAt(x, y int) (color.Color, error)

ColorAt implements Image interface.

func (*Gray8) ColorModel

func (i *Gray8) ColorModel() color.Model

ColorModel implements image.Image interface.`

func (*Gray8) Copy

func (i *Gray8) Copy() Image

Copy implements Image interface.

func (*Gray8) GrayAt

func (i *Gray8) GrayAt(x, y int) color.Gray

GrayAt implements Gray interface.

func (*Gray8) Histogram

func (i *Gray8) Histogram() (histogram [256]int)

Histogram implements Histogramer interface.

func (*Gray8) Set

func (i *Gray8) Set(x, y int, c color.Color)

Set implements draw.Image interface.

func (*Gray8) SetGray

func (i *Gray8) SetGray(x, y int, g color.Gray)

SetGray implements Gray interface.

func (*Gray8) Validate

func (i *Gray8) Validate() error

Validate implements Image interface.

type Histogramer

Histogramer is an interface that allows to get a histogram from the image.

type Histogramer interface {
    Histogram() [256]int
}

type Image

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

func FromGoImage(i image.Image) (Image, error)

FromGoImage creates a new Image from provided image 'i'.

func NewImage

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.

type ImageBase

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

func NewImageBase(width int, height int, bitsPerComponent int, colorComponents int, data []byte, alpha []byte, decode []float64) ImageBase

NewImageBase creates new image base.

func (*ImageBase) GetAlpha

func (i *ImageBase) GetAlpha() []byte

GetAlpha implements SMasker interface.

func (*ImageBase) HasAlpha

func (i *ImageBase) HasAlpha() bool

HasAlpha implements SMasker interface.

func (*ImageBase) MakeAlpha

func (i *ImageBase) MakeAlpha()

MakeAlpha implements SMasker interface.

func (*ImageBase) Pix

func (i *ImageBase) Pix() []byte

Pix implements Image interface.

type Monochrome

Monochrome is a grayscale image with a 1-bit per pixel.

type Monochrome struct {
    ImageBase
    ModelThreshold uint8
}

func (*Monochrome) AddPadding

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 (*Monochrome) At

func (m *Monochrome) At(x, y int) color.Color

At implements image.Image interface.

func (*Monochrome) Base

func (m *Monochrome) Base() *ImageBase

Base implements Image interface.

func (*Monochrome) Bounds

func (m *Monochrome) Bounds() image.Rectangle

Bounds implements image.Image.

func (*Monochrome) ColorAt

func (m *Monochrome) ColorAt(x, y int) (color.Color, error)

ColorAt implements Image interface.

func (*Monochrome) ColorModel

func (m *Monochrome) ColorModel() color.Model

ColorModel implements image.Image interface.

func (*Monochrome) Copy

func (m *Monochrome) Copy() Image

Copy implements Image interface.

func (*Monochrome) ExpandBinary

func (m *Monochrome) ExpandBinary(factor int) (*Monochrome, error)

ExpandBinary expands the monochrome image by the factor of 2.

func (*Monochrome) GrayAt

func (m *Monochrome) GrayAt(x, y int) color.Gray

GrayAt implements Gray interface.

func (*Monochrome) Histogram

func (m *Monochrome) Histogram() (histogram [256]int)

Histogram implements Histogramer interface.

func (*Monochrome) InverseData

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 (*Monochrome) IsUnpadded

func (m *Monochrome) IsUnpadded() bool

IsUnpadded checks if the input image has unpadded data.

func (*Monochrome) RasterOperation

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 (*Monochrome) ReduceBinary

func (m *Monochrome) ReduceBinary(factor float64) (*Monochrome, error)

ReduceBinary scales the binary image to be used for given width and height.

func (*Monochrome) ResolveDecode

func (m *Monochrome) ResolveDecode() error

ResolveDecode resolves the Decode filter for given image.

func (*Monochrome) Scale

func (m *Monochrome) Scale(scale float64) (*Monochrome, error)

Scale scales provided input monochrome image.

func (*Monochrome) ScaleLow

func (m *Monochrome) ScaleLow(width, height int) (*Monochrome, error)

ScaleLow is a function that monochrome image into provided width and height.

func (*Monochrome) Set

func (m *Monochrome) Set(x, y int, c color.Color)

Set implements draw.Image interface.

func (*Monochrome) SetGray

func (m *Monochrome) SetGray(x, y int, g color.Gray)

SetGray implements Gray interface.

func (*Monochrome) Validate

func (m *Monochrome) Validate() error

Validate implements Image interface.

type NRGBA

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)
}

type NRGBA16

NRGBA16 implements RGB image with 4 bits.

type NRGBA16 struct {
    ImageBase
}

func (*NRGBA16) At

func (i *NRGBA16) At(x, y int) color.Color

At implements Image interface.

func (*NRGBA16) Base

func (i *NRGBA16) Base() *ImageBase

Base implements Image interface.

func (*NRGBA16) Bounds

func (i *NRGBA16) Bounds() image.Rectangle

Bounds implements image.Image interface.

func (*NRGBA16) ColorAt

func (i *NRGBA16) ColorAt(x, y int) (color.Color, error)

ColorAt implements Image interface.

func (*NRGBA16) ColorModel

func (i *NRGBA16) ColorModel() color.Model

ColorModel implements image.Image interface.

func (*NRGBA16) Copy

func (i *NRGBA16) Copy() Image

Copy implements Image interface.

func (*NRGBA16) NRGBAAt

func (i *NRGBA16) NRGBAAt(x, y int) color.NRGBA

NRGBAAt implements NRGBA interface.

func (*NRGBA16) Set

func (i *NRGBA16) Set(x, y int, c color.Color)

Set implements draw.Image interface.

func (*NRGBA16) SetNRGBA

func (i *NRGBA16) SetNRGBA(x, y int, c color.NRGBA)

SetNRGBA implements NRGBA interface.

func (*NRGBA16) Validate

func (i *NRGBA16) Validate() error

Validate implements Image interface.

type NRGBA32

NRGBA32 implements RGB image with 4 bits.

type NRGBA32 struct {
    ImageBase
}

func (*NRGBA32) At

func (i *NRGBA32) At(x, y int) color.Color

At implements Image interface.

func (*NRGBA32) Base

func (i *NRGBA32) Base() *ImageBase

Base implements Image interface.

func (*NRGBA32) Bounds

func (i *NRGBA32) Bounds() image.Rectangle

Bounds implements image.Image interface.

func (*NRGBA32) ColorAt

func (i *NRGBA32) ColorAt(x, y int) (color.Color, error)

ColorAt implements Image interface.

func (*NRGBA32) ColorModel

func (i *NRGBA32) ColorModel() color.Model

ColorModel implements image.Image interface.

func (*NRGBA32) Copy

func (i *NRGBA32) Copy() Image

Copy implements Image interface.

func (*NRGBA32) NRGBAAt

func (i *NRGBA32) NRGBAAt(x, y int) color.NRGBA

NRGBAAt implements NRGBA implements.

func (*NRGBA32) Set

func (i *NRGBA32) Set(x, y int, c color.Color)

Set implements draw.Image interface.

func (*NRGBA32) SetNRGBA

func (i *NRGBA32) SetNRGBA(x, y int, c color.NRGBA)

SetNRGBA implements NRGBA interface.

func (*NRGBA32) Validate

func (i *NRGBA32) Validate() error

Validate implements Image interface.

type NRGBA64

NRGBA64 implements RGB image with 4 bits.

type NRGBA64 struct {
    ImageBase
}

func (*NRGBA64) At

func (i *NRGBA64) At(x, y int) color.Color

At implements image.Image interface.

func (*NRGBA64) Base

func (i *NRGBA64) Base() *ImageBase

Base implements Image interface.

func (*NRGBA64) Bounds

func (i *NRGBA64) Bounds() image.Rectangle

Bounds implements image.Image interface.

func (*NRGBA64) ColorAt

func (i *NRGBA64) ColorAt(x, y int) (color.Color, error)

ColorAt implements Image interface.

func (*NRGBA64) ColorModel

func (i *NRGBA64) ColorModel() color.Model

ColorModel implements image.Image interface.

func (*NRGBA64) Copy

func (i *NRGBA64) Copy() Image

Copy implements Image interface.

func (*NRGBA64) NRGBA64At

func (i *NRGBA64) NRGBA64At(x, y int) color.NRGBA64

NRGBA64At gets color.NRGBA64 at 'x' and 'y'.

func (*NRGBA64) Set

func (i *NRGBA64) Set(x, y int, c color.Color)

Set implements draw.Image interface.

func (*NRGBA64) SetNRGBA64

func (i *NRGBA64) SetNRGBA64(x, y int, c color.NRGBA64)

SetNRGBA64 sets the 'NRGBA64' color at 'x' and 'y' coordinates.

func (*NRGBA64) Validate

func (i *NRGBA64) Validate() error

Validate implements Image interface.

type RGBA

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)
}

type RGBA32

RGBA32 implements RGB image with 4 bits.

type RGBA32 struct {
    ImageBase
}

func (*RGBA32) At

func (i *RGBA32) At(x, y int) color.Color

At implements Image interface.

func (*RGBA32) Base

func (i *RGBA32) Base() *ImageBase

Base implements Image interface.

func (*RGBA32) Bounds

func (i *RGBA32) Bounds() image.Rectangle

Bounds implements image.Image interface.

func (*RGBA32) ColorAt

func (i *RGBA32) ColorAt(x, y int) (color.Color, error)

ColorAt implements Image interface.

func (*RGBA32) ColorModel

func (i *RGBA32) ColorModel() color.Model

ColorModel implements image.Image interface.

func (*RGBA32) Copy

func (i *RGBA32) Copy() Image

Copy implements Image interface.

func (*RGBA32) RGBAAt

func (i *RGBA32) RGBAAt(x, y int) color.RGBA

RGBAAt implements RGBA implements.

func (*RGBA32) Set

func (i *RGBA32) Set(x, y int, c color.Color)

Set implements draw.Image interface.

func (*RGBA32) SetRGBA

func (i *RGBA32) SetRGBA(x, y int, c color.RGBA)

SetRGBA implements RGBA interface.

func (*RGBA32) Validate

func (i *RGBA32) Validate() error

Validate implements Image interface.

type RasterOperator

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
)

type SMasker

SMasker is an interface used to get and check the alpha mask from an image.

type SMasker interface {
    HasAlpha() bool
    GetAlpha() []byte
    MakeAlpha()
}