reximage

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2025 License: MIT Imports: 5 Imported by: 1

README

reximage

A Go package for importing REXPaint's .xp images

REXPaint is a fabulous program for creating ASCII art, made by ultra-famous roguelike developer Kyzrati. This package allows you to decode and import image data from the .xp file format produced by REXPaint for use in your project. It was made as part of the larger Tyumi engine, but doesn't depend on it at all and is fine to be used standalone!

Documentation

Obtain this package in the usual way:

go get github.com/bennicholls/reximage

To use, import the package and call

image, err := reximage.Import(pathname)

ensuring that pathname is a string describing a path to an .xp file. It will throw an error if the pathname is invalid or the file cannot be read for some other reason.

Access the cell data using:

cell, err := image.GetCell(x, y)

where x and y are coordinates to a cell in the image (bounded by image.Width, image.Height). It will throw an error if (x,y) is not in bounds or if the image hasn't been imported yet. My engine Tyumi was originally built around SDL, so reximage follows SDL's convention of setting the (0,0) coordinate in the top-left of the image.

cell consists of a Glyph (ASCII codepoint) and RGB components for both foreground and background colours. Each colour component is 8bits (0-255). You can extract 32bit colours using some helper functions:

foregroundRGBA, backgroundRGBA := cell.RGBA()
foregroundARGB, backgroundARGB := cell.ARGB()

I imagine these are the most popular colour formats but I don't have the research to back that up. Of course, if your program uses a different colour format you can access the individual components and form the colour yourself.

Complete(-ish) documentation can be found on GoDoc.org.

Future

This is all my engine needs at the moment so I'm not sure what else would be helpful here. On the off-chance someone else is using this, let me know if there's anything you think it could use. Conceivably, the package could be expanded to write changes to .xp files I suppose?

License

reximage is licensed under the MIT license (see LICENSE file).

Documentation

Overview

A package for decoding and handling .xp files produced by Kyzrati's fabulous REXPaint program, the gold-standard in ASCII art drawing programs. It can be found at www.gridsagegames.com/rexpaint.

reximage is part of the Tyumi engine by Benjamin Nicholls, but feel free to use it as a standalone package!

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CellData

type CellData struct {
	Glyph uint32 // ASCII code for glyph
	R_f   uint8  // Foreground Colour - Red channel
	G_f   uint8  // Foreground Colour - Green channel
	B_f   uint8  // Foreground Colour - Blue channel
	R_b   uint8  // Background Colour - Red channel
	G_b   uint8  // Background Colour - Green channel
	B_b   uint8  // Background Colour - Blue channel
}

CellData holds the decoded data for a single cell. Colours are split into uint8 components so the user can combine them into whatever colour format they need. Some popular colour format conversion functions are provided as well.

func (CellData) ARGB

func (cd CellData) ARGB() (fore, back uint32)

ARGB returns the foreground and background colours of the cell in ARGB format. Alpha in this case is always set to maximum (255).

func (CellData) RGBA

func (cd CellData) RGBA() (fore, back uint32)

RGBA returns the foreground and background colours of the cell in RGBA format. Alpha in this case is always set to maximum (255).

func (CellData) Undrawn

func (cd CellData) Undrawn() bool

Undrawn returns whether the cell is "undrawn" or empty, which in XP files is identified by the background colour (255, 0, 255).

type ImageData

type ImageData struct {
	Width  int
	Height int
	Cells  []CellData //will have Width*Height Elements
}

ImageData is the struct holding the decoded and exported image data.

func Import

func Import(path string) (image ImageData, err error)

Import imports an image from the xp file at the provided path. Returns the Imagedata and an error. If an error is present, ImageData will be no good.

func (ImageData) GetCell

func (id ImageData) GetCell(x, y int) (cd CellData, err error)

GetCell returns the CellData at coordinate (x, y) of the decoded image, with (0,0) at the top-left of the image.

Jump to

Keyboard shortcuts

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