Documentation ¶
Index ¶
- Variables
- func Decode(r io.Reader) (image.Image, error)
- func DecodeConfig(r io.Reader) (image.Config, error)
- func Encode(w io.Writer, i Info, image image.Image) error
- type BitColor
- type Bits
- func (b *Bits) At(x, y int) color.Color
- func (b *Bits) BitColorAt(x, y int) BitColor
- func (b *Bits) Bounds() image.Rectangle
- func (b *Bits) ColorModel() color.Model
- func (b *Bits) Opaque() bool
- func (b *Bits) PixOffset(x, y int) int
- func (b *Bits) Set(x, y int, c color.Color)
- func (b *Bits) SetBit(x, y int, c bool)
- func (b *Bits) SubImage(r image.Rectangle) image.Image
- type Encoder
- type FormatError
- type Info
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var BitColorModel color.Model = color.ModelFunc(toBitColor)
BitColorModel is the ColorModel associated with the BitColor type.
Functions ¶
func Decode ¶
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 ¶
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:
Types ¶
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 (*Bits) BitColorAt ¶
BitColorAt returns the BitColor at (x, y).
func (*Bits) Opaque ¶
Opaque scans the entire image and reports whether it is fully opaque. This is always true for XBM images.
func (*Bits) PixOffset ¶
PixOffset returns the index of the first element of Pix that corresponds to the pixel at (x, y).
func (*Bits) Set ¶
Set sets the binary pixel value at (x, y) to match the provided color, using BitColorModel's conversion algorithm.
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 ¶
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 ¶
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: