xbm

package module
v0.0.0-...-c6719e7 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2021 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var BitColorModel color.Model = color.ModelFunc(toBitColor)

BitColorModel is the ColorModel associated with the BitColor type.

Functions

func Decode

func Decode(r io.Reader) (image.Image, error)

Decode reads an XBM file from r and returns the image.

Example
n := "beholder.xbm"
f, err := os.Open(n)
if err != nil {
	panic(err)
}
defer f.Close()

m, err := Decode(f)
if err != nil {
	panic(err)
}
fmt.Printf("Read XBM: %s, size: %dx%d\n", n, m.Bounds().Max.X, m.Bounds().Max.Y)
Output:

Example (Ascii)
n := "beholder.xbm"
f, err := os.Open(n)
if err != nil {
	panic(err)
}
defer f.Close()

m, err := Decode(f)
if err != nil {
	panic(err)
}
b := m.Bounds()

for y := b.Min.Y; y < b.Max.Y; y++ {
	for x := b.Min.X; x < b.Max.X; x++ {
		v, ok := m.At(x, y).(BitColor)
		if !ok {
			continue
		}
		if v {
			fmt.Printf(".")
		} else {
			fmt.Printf(" ")
		}
	}
	fmt.Println("")
}
Output:

func DecodeConfig

func DecodeConfig(r io.Reader) (image.Config, error)

DecodeConfig returns the dimensions of an XBM image without decoding the entire image.

Example
n := "beholder.xbm"
f, err := os.Open(n)
if err != nil {
	panic(err)
}
defer f.Close()

c, err := DecodeConfig(f)
if err != nil {
	panic(err)
}
fmt.Printf("Read XBM: %s, size: %dx%d\n", n, c.Width, c.Height)
Output:

func Encode

func Encode(w io.Writer, i Info, image image.Image) error

Encode writes the Info i and Image image to w in PNG format. Any Image may be encoded, but images that are not Bits are encoded lossily.

Types

type BitColor

type BitColor bool

BitColor represents a 1-bit color value.

func (BitColor) RGBA

func (c BitColor) RGBA() (r, g, b, a uint32)

RGBA returns the RGBA value of the BitColor.

type Bits

type Bits struct {
	// Pix holds the image's pixels, as boolean values.
	Pix []bool
	// Stride is the Pix stride (in bytes) between vertically adjacent pixels.
	Stride int
	// Rect is the image's bounds.
	Rect image.Rectangle
}

Bits is an in-memory image whose At method returns color.BitColor values.

func NewBits

func NewBits(r image.Rectangle) *Bits

NewBits returns a new Bits image with the given bounds.

func (*Bits) At

func (b *Bits) At(x, y int) color.Color

At returns the Color at (x, y).

func (*Bits) BitColorAt

func (b *Bits) BitColorAt(x, y int) BitColor

BitColorAt returns the BitColor at (x, y).

func (*Bits) Bounds

func (b *Bits) Bounds() image.Rectangle

Bounds returns the image's bounds.

func (*Bits) ColorModel

func (b *Bits) ColorModel() color.Model

ColorModel returns BitColorModel.

func (*Bits) Opaque

func (b *Bits) Opaque() bool

Opaque scans the entire image and reports whether it is fully opaque. This is always true for XBM images.

func (*Bits) PixOffset

func (b *Bits) PixOffset(x, y int) int

PixOffset returns the index of the first element of Pix that corresponds to the pixel at (x, y).

func (*Bits) Set

func (b *Bits) Set(x, y int, c color.Color)

Set sets the binary pixel value at (x, y) to match the provided color, using BitColorModel's conversion algorithm.

func (*Bits) SetBit

func (b *Bits) SetBit(x, y int, c bool)

SetBit sets the binary pixel value at (x, y) to a boolean value.

func (*Bits) SubImage

func (b *Bits) SubImage(r image.Rectangle) image.Image

SubImage returns an image representing the portion of the image p visible through r. The returned value shares pixels with the original image.

type Encoder

type Encoder struct {
	Info
}

Encoder configures additional XBM encoding data.

func (*Encoder) Encode

func (enc *Encoder) Encode(w io.Writer, m image.Image) error

Encode write the Image m to w in XBM format. Any Image may be encoded, but images that are not Bits are encoded lossily.

type FormatError

type FormatError string

FormatError represents an invalid format error for the XBM format.

func (FormatError) Error

func (e FormatError) Error() string

Error returns the string of the error.

type Info

type Info struct {
	// X, Y coordinate that determines the XBM hotspot.
	Hotspot image.Point
	// Variable name used for the pixel data.
	DataName string
	// Variables names for the width and height.
	WidthName, HeightName string
	// Variable names for the x and y hotspot.
	HotspotXName, HotspotYName string
}

Info contains additional XBM metadata.

func DecodeInfo

func DecodeInfo(r io.Reader) (Info, error)

DecodeInfo returns the Info of an XBM image without decoding the entire image.

Example
n := "cursor.xbm"
f, err := os.Open(n)
if err != nil {
	panic(err)
}
defer f.Close()

info, err := DecodeInfo(f)
if err != nil {
	panic(err)
}
fmt.Printf("XBM Metadata: data=%s width=%s height=%s hotspot=%d,%d hotspotX=%s hotspotY=%s\n", info.DataName, info.WidthName, info.HeightName, info.Hotspot.X, info.Hotspot.Y, info.HotspotXName, info.HotspotYName)
Output:

func DecodeInfoAndImage

func DecodeInfoAndImage(r io.Reader) (Info, image.Image, error)

DecodeInfoAndImage returns the Info and the Image of and XBM image.

Example
n := "cursor.xbm"
f, err := os.Open(n)
if err != nil {
	panic(err)
}
defer f.Close()

info, m, err := DecodeInfoAndImage(f)
if err != nil {
	panic(err)
}
fmt.Printf("Decoded XBM Dimensions: %dx%d\n", m.Bounds().Max.X, m.Bounds().Max.Y)
fmt.Printf("Metadata: data=%s width=%s height=%s hotspot=%d,%d hotspotX=%s hotspotY=%s\n", info.DataName, info.WidthName, info.HeightName, info.Hotspot.X, info.Hotspot.Y, info.HotspotXName, info.HotspotYName)
Output:

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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