xpm

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2023 License: BSD-3-Clause Imports: 7 Imported by: 3

README

xpm

Build Status Go Report Card GoDoc License

Encode images to the X PixMap (XPM3) image format.

The resulting images are smaller than the ones from GIMP, since the question mark character is also used, while at the same time avoiding double question marks, which could result in a trigraph (like ??=, which has special meaning in C).

The png2xpm utility is included.

Example use

Converting from a PNG to an XPM file:

// Open the PNG file
f, err := os.Open(inputFilename)
if err != nil {
    fmt.Fprintf(os.Stderr, "error: %s\n", err)
    os.Exit(1)
}
m, err := png.Decode(f)
if err != nil {
    fmt.Fprintf(os.Stderr, "error: %s\n", err)
    os.Exit(1)
}
f.Close()

// Create a new XPM encoder
enc := xpm.NewEncoder(imageName)

// Prepare to output the XPM data to either stdout or to file
if outputFilename == "-" {
    f = os.Stdout
} else {
    f, err = os.Create(outputFilename)
    if err != nil {
        fmt.Fprintf(os.Stderr, "error: %s\n", err)
        os.Exit(1)
    }
    defer f.Close()
}

// Generate and output the XPM data
err = enc.Encode(f, m)
if err != nil {
    fmt.Fprintf(os.Stderr, "error: %s\n", err)
    os.Exit(1)
}

Reference documentation

General info

Documentation

Overview

Example (Hexify)
fmt.Println(hexify([]byte{0, 7, 0x80, 0xff}))
Output:

[0x00 0x07 0x80 0xff]

Index

Examples

Constants

View Source
const (
	// VersionString contains the current package name and version
	VersionString = "xpm 1.3.0"

	// AllowedLetters is the 93 available ASCII letters
	// ref: https://en.wikipedia.org/wiki/X_PixMap
	// They are in the same order as GIMP, but with the question mark character as
	// well. Double question marks may result in trigraphs in C, but this is
	// avoided by checking specifically for this.
	// ref: https://en.wikipedia.org/wiki/Digraphs_and_trigraphs#C
	AllowedLetters = " .+@#$%&*=-;>,')!~{]^/(_:<[}|1234567890" + azAZ + "`?"
)

Variables

This section is empty.

Functions

func Encode

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

Encode will encode the image as XBM, using "img" as the image name

Types

type Encoder

type Encoder struct {
	// The internal image name
	ImageName string

	// With comments?
	Comments bool

	// The alpha threshold
	AlphaThreshold float64

	// These are used when encoding the color ID as ASCII
	AllowedLetters []rune

	// MaxColors is the maximum allowed number of colors, or -1 for no limit. The default is 256.
	MaxColors int
}

Encoder contains encoding configuration that is used by the Encode method

func NewEncoder added in v1.2.0

func NewEncoder(imageName string) *Encoder

NewEncoder creates a new Encoder configuration struct

func (*Encoder) Encode

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

Encode will encode the given image as XBM, using a custom image name from the Encoder struct.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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