img1b

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2020 License: BSD-3-Clause Imports: 4 Imported by: 0

README

img1b

Package img1b is a fork of the standard Go image package modified for 1-bit images. Images are kept packed so they take up to 8 times less memory and may be processed faster.

It provides an Image type that is in most aspects very similar to image.Paletted with palette limited to two colors.

img1b.Image implements image.PalettedImage and can be encoded with image/png and probably other encoders but that is not very efficient due to all the bit shuffling involved. Subpackage img1b/png is a modified png codec that processes whole rows which is several times faster.

Documentation

Overview

Package img1b is a fork of the standard Go image package modified for 1-bit images. Images are kept packed so they take up to 8 times less memory and may be processed faster.

There is currently no img1b.Decode. To read a PNG file use Decode from img1b/png.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Image

type Image struct {
	// Pix is a bitmap of image pixels. Bytes represent up to 8 horizontally adjacent
	// pixels (there may be unused bits in the last byte of a row) with the most
	// significant bit corresponding to leftmost pixel.
	Pix []byte
	// Stride is the Pix stride (in bytes) between vertically adjacent pixels.
	Stride int
	// Rect is the image's bounds.
	Rect image.Rectangle
	// Palette is the image's palette.
	Palette color.Palette
}

Image implements the image.PalettedImage interface and is mostly analogous to image.Paletted except that Pix is a bitmap, so only color indices 0 and 1 can be used.

func New

func New(r image.Rectangle, p color.Palette) *Image

New returns a new Image with given dimensions and palette.

func (*Image) At

func (p *Image) At(x, y int) color.Color

At returns the color of the pixel at (x, y).

func (*Image) Bounds

func (p *Image) Bounds() image.Rectangle

Bounds returns the domain for which At can return non-zero color. The bounds do not necessarily contain the point (0, 0).

func (*Image) ColorIndexAt

func (p *Image) ColorIndexAt(x, y int) uint8

ColorIndexAt returns the palette index of the pixel at (x, y).

func (*Image) ColorModel

func (p *Image) ColorModel() color.Model

ColorModel returns the Image's color model.

func (*Image) Opaque

func (p *Image) Opaque() bool

Opaque scans the entire image and reports whether it is fully opaque.

func (*Image) PixBitOffset

func (p *Image) PixBitOffset(x, y int) (ofs, bit int)

PixBitOffset returns the index of the byte of Pix that corresponds to the pixel at (x, y) and bit offset (7 for MSB) in that byte.

func (*Image) SetColorIndex

func (p *Image) SetColorIndex(x, y int, index uint8)

SetColorIndex sets color index for the pixel at (x, y). Index should be 0 or 1.

func (*Image) SubImage

func (p *Image) SubImage(r image.Rectangle) *Image

SubImage returns an image representing the portion of the image p visible through r. The returned value shares pixels with the original image. Left edge has to be byte aligned.

Directories

Path Synopsis
Package png implements a PNG image decoder and encoder.
Package png implements a PNG image decoder and encoder.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL