Documentation ¶
Overview ¶
Package binimg proposes an in-memory binary image format, implementing the image.Image interface, alongside a set of efficient tools to scan rectangular regions of such images. A binary image has only two possible colors for each pixel, generally Black and White, though any two colors can be used.
Though the information represented by each pixel could be stored as a single bit, and thus has a reduced memory footprint, choice has been made to represent Bit pixels as byte values, that can either be 0 (Black or Off) or 255 (White or On), mostly for simplicity reasons.
binimg.Image images are created either by calling functions such as New and NewFromImage.
Index ¶
- Variables
- type Bit
- type Image
- func (b *Image) At(x, y int) color.Color
- func (b *Image) BitAt(x, y int) Bit
- func (b *Image) Bounds() image.Rectangle
- func (b *Image) ColorModel() color.Model
- func (b *Image) Opaque() bool
- func (b *Image) PixOffset(x, y int) int
- func (b *Image) Set(x, y int, c color.Color)
- func (b *Image) SetBit(x, y int, c Bit)
- func (b *Image) SetRect(r image.Rectangle, c Bit)
- func (b *Image) SubImage(r image.Rectangle) image.Image
Constants ¶
This section is empty.
Variables ¶
var ( Black = Bit{0} White = Bit{255} )
Black and White are the only colors that a Binary image pixel can have.
var ( Off = Black On = White )
Alias colors for Black and White
var Model = color.ModelFunc(model)
Model is the color model for binary images.
Functions ¶
This section is empty.
Types ¶
type Image ¶
type Image struct { // Pix holds the image's pixels, as 0 or 1 uint8 values. The pixel at // (x, y) starts at Pix[(y-Rect.Min.Y)*Stride + (x-Rect.Min.X)*1]. Pix []uint8 // Stride is the Pix stride (in bytes) between vertically adjacent pixels. Stride int // Rect is the image's bounds. Rect image.Rectangle }
Image is an in-memory image whose At method returns Bit values.
func NewFromImage ¶
NewFromImage returns a new binary image that is the conversion of src image.
func (*Image) At ¶
At returns the color of the pixel at (x, y). At(Bounds().Min.X, Bounds().Min.Y) returns the upper-left pixel of the grid. At(Bounds().Max.X-1, Bounds().Max.Y-1) returns the lower-right one.
func (*Image) BitAt ¶
BitAt returns the Bit color of the pixel at (x, y). BitAt(Bounds().Min.X, Bounds().Min.Y) returns the upper-left pixel of the grid. BitAt(Bounds().Max.X-1, Bounds().Max.Y-1) returns the lower-right one.
func (*Image) Bounds ¶
Bounds returns the domain for which At can return non-zero color. The bounds do not necessarily contain the point (0, 0).
func (*Image) ColorModel ¶
ColorModel returns the image.Image's color model.
func (*Image) PixOffset ¶
PixOffset returns the index of the first element of Pix that corresponds to the pixel at (x, y).
func (*Image) Set ¶
Set sets the color of the pixel at (x, y).
c is converted to Bit using the image color model.