sbm

package module
v0.7.17 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2025 License: GPL-3.0 Imports: 10 Imported by: 0

README

SBM

Simple Bit Map

This package provides a model and methods to work with the SBM format. "SBM" is an acronym for "simple bit map". The SBM format is a format for two-level (monochrome, black-&-white, bi-level) raster graphical images.

The SBM format is used to store a raw uncompressed array of binary pixels together with basic meta-data describing the size of the pixel array. SBM format is stored in a mixed encoding. This means that meta-data is encoded as plain ASCII text symbols and pixel array is encoded using the binary format.

The array of pixels is composed of pixels row by row, starting with the top row, and having the bottom row at the end. Each row is composed of W pixels, where W is the array's width. Total number of rows is H, where H is the array's height. The array contains A pixels total, where A is the array's area, the multiple of W and H. Each pixel in the array is a separate bit, where zero bit (0) is black (dark colour) and one bit (1) is white (light colour). Due to the limitations of current hardware, the order of bits in each byte is not controlled by this library (package). The least significant bit is considered to be the first bit, the most significant bit is the last bit.

The internal SBM model type stores both fields: an array of bits (as separate objects) and an array of bytes which are created by the concatenation of all the bits as real machine's bits (not as objects). This is done for convenience of various internal manipulations with either bits or bytes. When the object of the SBM model type is stored into the stream, it stores only the bytes array and omits the internal array of bit objects. The same happens when the SBM model type is read from the stream – bytes are received from the stream, not the bits.

Documentation

Index

Constants

View Source
const (
	CR = '\r'
	LF = '\n'
	NL = string(CR) + string(LF)
)

ASCII symbols.

View Source
const (
	HeaderPartsSeparator    = " "
	HeaderPartsBracketLeft  = "("
	HeaderPartsBracketRight = ")"
	HeaderPartsPlus         = "+"

	Header_FormatName = "SBM (SIMPLE BIT MAP)" + NL

	HeaderPrefix_Version = "VERSION"
	HeaderFormat_Version = HeaderPrefix_Version +
		HeaderPartsSeparator +
		"%v" +
		NL

	HeaderPrefix_Width = "WIDTH"
	HeaderFormat_Width = HeaderPrefix_Width +
		HeaderPartsSeparator +
		"%v" +
		HeaderPartsSeparator +
		HeaderPartsBracketLeft +
		"%v" +
		HeaderPartsSeparator +
		HeaderPartsPlus +
		HeaderPartsSeparator +
		"%v" +
		HeaderPartsBracketRight +
		NL

	HeaderPrefix_Height = "HEIGHT"
	HeaderFormat_Height = HeaderPrefix_Height +
		HeaderPartsSeparator +
		"%v" +
		HeaderPartsSeparator +
		HeaderPartsBracketLeft +
		"%v" +
		HeaderPartsSeparator +
		HeaderPartsPlus +
		HeaderPartsSeparator +
		"%v" +
		HeaderPartsBracketRight +
		NL

	HeaderPrefix_Area = "AREA"
	HeaderFormat_Area = HeaderPrefix_Area +
		HeaderPartsSeparator +
		"%v" +
		HeaderPartsSeparator +
		HeaderPartsBracketLeft +
		"%v" +
		HeaderPartsSeparator +
		HeaderPartsPlus +
		HeaderPartsSeparator +
		"%v" +
		HeaderPartsBracketRight +
		NL
)

Meta-data header parameters.

View Source
const (
	ErrFormat            = "format is unrecognized"
	ErrHeaderSyntax      = "header syntax error"
	ErrfHeaderUnexpected = "unexpected header: '%v'"
	ErrOverflow          = "overflow"
	ErrIntegrity         = "integrity failure"
)

Errors.

View Source
const (
	ErrBottomHeaderMismatch = "bottom header mismatch"
	ErrBadSeparator         = "bad separator"
	ErrAreaMismatch         = "area mismatch"
)

Errors.

View Source
const (
	ErrHeaderSize   = "header is too short"
	ErrHeaderEnding = "header ending syntax error"
)

Errors.

View Source
const (
	ErrDimension = "array dimension error"
)
View Source
const (
	ErrVersion = "version error"
)
View Source
const (
	MimeType = "image/x-portable-bitmap"
)

MimeType is the MIME type. This MIME type is not official, it is not registered in IANA.

View Source
const (
	SbmFormatVersion1 = 1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type HeaderDataSize

type HeaderDataSize struct {
	// contains filtered or unexported fields
}

HeaderDataSize is a data size header.

type HeaderDataVersion

type HeaderDataVersion struct {
	// contains filtered or unexported fields
}

HeaderDataVersion is a data version header.

type Sbm

type Sbm struct {
	// contains filtered or unexported fields
}

Sbm is a Simple Bit Map.

func NewFromBitsArray

func NewFromBitsArray(
	arrayBits []bit.Bit,
	arrayWidth uint,
	arrayHeight uint,
) (sbm *Sbm, err error)

NewFromBitsArray creates a new SBM from an array of bits. Performs the fool checks.

func NewFromBytesArray

func NewFromBytesArray(
	arrayBytes []byte,
	arrayWidth uint,
	arrayHeight uint,
) (sbm *Sbm, err error)

NewFromBytesArray creates a new SBM from an array of bytes. Performs the fool checks.

func NewFromStream

func NewFromStream(reader io.Reader) (sbm *Sbm, err error)

NewFromStream reads an SBM object from the stream.

func (*Sbm) GetArrayArea

func (sbm *Sbm) GetArrayArea() uint

func (*Sbm) GetArrayBits

func (sbm *Sbm) GetArrayBits() []bit.Bit

func (*Sbm) GetArrayBytes

func (sbm *Sbm) GetArrayBytes() []byte

func (*Sbm) GetArrayHeight

func (sbm *Sbm) GetArrayHeight() uint

func (*Sbm) GetArrayWidth

func (sbm *Sbm) GetArrayWidth() uint

func (*Sbm) GetFormat

func (sbm *Sbm) GetFormat() SbmFormat

func (*Sbm) Write

func (sbm *Sbm) Write(writer io.Writer) (err error)

Write writes an SBM object into the stream.

type SbmFormat

type SbmFormat struct {
	// contains filtered or unexported fields
}

SbmFormat is the format of SBM.

type SbmPixelArray

type SbmPixelArray struct {
	// contains filtered or unexported fields
}

SbmPixelArray is the pixel array data & parameters.

type SbmPixelArrayData

type SbmPixelArrayData struct {
	// contains filtered or unexported fields
}

SbmPixelArrayData contains pixel array data.

type SbmPixelArrayMetaData

type SbmPixelArrayMetaData struct {
	// contains filtered or unexported fields
}

SbmPixelArrayMetaData is meta-data for a pixel array.

type SbmPixelArrayMetaDataHeader

type SbmPixelArrayMetaDataHeader struct {
	// contains filtered or unexported fields
}

SbmPixelArrayMetaDataHeader is a pixel array meta-data header.

type SbmPixelArrayMetaDataHeaderData

type SbmPixelArrayMetaDataHeaderData struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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