image2bit

package
v3.7.2 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package image2bit implements two bit gray scale (white, light gray, dark gray, black) 2D graphics.

It is compatible with package image/draw.

The bit packing format is the same as used by waveshare e-Paper displays such as the 4.2 inch display.

Index

Constants

This section is empty.

Variables

View Source
var GrayModel = color.ModelFunc(convert)

GrayModel is the color Model for 2 bit gray scale.

Functions

This section is empty.

Types

type BitPlane

type BitPlane struct {
	// PixMSB holds the image's most significant bit as a horizontally packed bitmap.
	PixMSB []byte
	// PixLSB holds the image's least significant bit as a horizontally packed bitmap.
	PixLSB []byte
	// Rect is the image's bounds.
	Rect image.Rectangle

	// Stride is the number of pixels on each horizontal line, including padding
	Stride int
}

BitPlane is a 2 bit gray scale image. To match the wire format for waveshare e-Paper the two bits per pixel is stored across two bitmaps. PixMSB contains the most significant bit, PixLSB contains the least significant bit.

        White LightGray DarkGray Black
PixMSB   1     1         0        0
PixLSB   1     0         1        0

The following example shows the stored data for an 8 pixel wide image, 1 pixel high: PixMSB []byte{0b10100000} PixLSB []byte{0b10000000}

It has a black background, the first pixel is white, and the third pixel LightGray.

func NewBitPlane

func NewBitPlane(r image.Rectangle) *BitPlane

NewBitPlane returns an initialized BitPlane instance, all black.

func (*BitPlane) At

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

At implements image.Image.

func (*BitPlane) Bounds

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

Bounds implements image.Image.

func (*BitPlane) ColorModel

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

ColorModel implements image.Image.

func (*BitPlane) GrayAt

func (i *BitPlane) GrayAt(x, y int) Gray

GrayAt is the optimized version of At().

func (*BitPlane) Opaque

func (i *BitPlane) Opaque() bool

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

func (*BitPlane) Set

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

Set implements draw.Image

func (*BitPlane) SetGray

func (i *BitPlane) SetGray(x, y int, b Gray)

SetGray is the optimized version of Set().

type Gray

type Gray byte

Gray implements a 2 bit color.

const (
	White     Gray = 3
	LightGray Gray = 2
	DarkGray  Gray = 1
	Black     Gray = 0
)

All possible colors

func (Gray) RGBA

func (b Gray) RGBA() (uint32, uint32, uint32, uint32)

RGBA returns either black, dark gray, light gray or white.

func (Gray) String

func (b Gray) String() string

Jump to

Keyboard shortcuts

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