image

package
v0.0.0-...-09a3b47 Latest Latest
Warning

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

Go to latest
Published: May 16, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TL_SINGLE = iota // Default.  A single 8x8 tile.
	TL_8X16          // 8x16 sprites.
	TL_ROW           // Row sequential
	TL_COLUMN        // Column sequential
	TL_ASIS          // Don't transform.  This will break things if there's meta tiles that are not the same size.
)

Variables

View Source
var DefaultPalette color.Palette = color.Palette{
	color.RGBA{R: 0x00, G: 0x39, B: 0x73, A: 0xFF},
	color.RGBA{R: 0xAD, G: 0xB5, B: 0x31, A: 0xFF},
	color.RGBA{R: 0x84, G: 0x5E, B: 0x21, A: 0xFF},
	color.RGBA{R: 0xC6, G: 0xE7, B: 0x9C, A: 0xFF},
}

This is that ugly palette from YYCHR. Currently only used when saving a pattern table to a PNG image. Override this with the --palette command line option.

Note: this variable isn't actually used as the default colors are defined for the --palette option.

View Source
var NESModel color.Model = color.ModelFunc(nesModel)

Functions

func ParseHexColor

func ParseHexColor(input string) (color.RGBA, error)

ParseHexColor takes a single color represented in hexidecimal format and returns a color.RGBA object on success, and an error otherwise.

Shorthand notation can be used (eg, #000 is expanded to #000000).

func ParseHexPalette

func ParseHexPalette(input string) (color.Palette, error)

ParseHexPalette takes a palette from a string in hex in the from of "#003973,#ADB531,#845E21,#C6E79C" and returns a color palette.

The input must have exactly four colors defined or an error will be returned.

Types

type Arrangement

type Arrangement uint
const (
	ARR_SINGLE  Arrangement = iota
	ARR_DBLHIGH             // 8x16 sprite mode

)

type FileHeader

type FileHeader struct {
	Size   int // size of file in bytes
	Offset int // offset to start of pixel data
}

func ParseFileHeader

func ParseFileHeader(input []byte) (*FileHeader, error)

Size, offset, error

func (FileHeader) String

func (f FileHeader) String() string

type ImageHeader

type ImageHeader struct {
	Width       int
	Height      int
	BitDepth    int
	Compression int
	Size        int // image size

	ColorMapEntries   int
	SignificantColors int
	// contains filtered or unexported fields
}

func ParseImageHeader

func ParseImageHeader(input []byte) (*ImageHeader, error)

func (ImageHeader) String

func (i ImageHeader) String() string

type PatternTable

type PatternTable struct {
	Patterns   []*Tile
	Layout     Arrangement
	ReducedIds []int

	// Dimensions are in pixels
	SourceWidth  int
	SourceHeight int

	// Width in tiles
	TableWidth int
}

A PatternTable is the data that will be written as the CHR. It can only be in 1k, 2k, 4k, or 8k sizes; or 64, 128, 256, or 512 tiles; or 128x32, 128x64, 128x128, or 128x256 pixels; or 4, 8, 16, or 32 rows of tiles.

func LoadBitmap

func LoadBitmap(filename string) (*PatternTable, error)

func LoadCHR

func LoadCHR(filename string) (*PatternTable, error)

func NewPatternTable

func NewPatternTable() *PatternTable

func ReadCHR

func ReadCHR(reader io.Reader) (*PatternTable, error)

func (*PatternTable) AddPatternTable

func (pt *PatternTable) AddPatternTable(newPt *PatternTable)

func (*PatternTable) AddTile

func (pt *PatternTable) AddTile(tile *Tile)

func (*PatternTable) Asm

func (pt *PatternTable) Asm(firstPlane bool) string

WriteFile writes the CHR data of all the tiles in assembly format to the given file.

func (*PatternTable) At

func (pt *PatternTable) At(x, y int) color.Color

TODO: Verify this actually works

func (*PatternTable) Bounds

func (pt *PatternTable) Bounds() image.Rectangle

func (*PatternTable) Chr

func (pt *PatternTable) Chr(firstPlane bool) []byte

Chr returns the pattern table data as bytes in the CHR format.

func (*PatternTable) ColorModel

func (pt *PatternTable) ColorModel() color.Model

Implement the image.Image interface

func (*PatternTable) Debug

func (pt *PatternTable) Debug() string

func (*PatternTable) PadTileCount

func (pt *PatternTable) PadTileCount(count int)

PadTileCount ensures that at least count number of tiles exist in the pattern table

func (*PatternTable) PadTiles

func (pt *PatternTable) PadTiles()

PadTiles ensures that all rows have 16 tiles in them.

func (*PatternTable) RemoveDuplicates

func (pt *PatternTable) RemoveDuplicates(removeEmpty bool) (int, int)

Returns before/after count

func (*PatternTable) RemoveEmpty

func (pt *PatternTable) RemoveEmpty() (int, int)

Returns before/after count

func (*PatternTable) Set

func (pt *PatternTable) Set(x, y int, c color.Color)

TODO: Verify this works

func (*PatternTable) SetPalette

func (pt *PatternTable) SetPalette(pal color.Palette)

type Tile

type Tile struct {
	image.Paletted
	OrigId int

	PaletteId int // 0-3
	// contains filtered or unexported fields
}

Data is a list of palette indexes. One ID per pixel. A single tile is always 8x8 pixels. Larger meta tiles (eg, 8*16) will be made up of multiple tiles of 64 total pixels. type Tile [64]byte

func NewTile

func NewTile(id int) *Tile

func (*Tile) ASCII

func (t *Tile) ASCII() string

func (*Tile) Asm

func (t *Tile) Asm(half, binary bool) string

Asm takes two parameters: Setting `half` to true will only return the first bitplane of the tile. Setting `binary` to true will use the binary notation, otherwise it will use the hexidecimal notation.

func (*Tile) At

func (t *Tile) At(x, y int) color.Color

func (*Tile) Bounds

func (t *Tile) Bounds() image.Rectangle

func (*Tile) CharacterWidth

func (t *Tile) CharacterWidth() int

func (*Tile) Chr

func (t *Tile) Chr(firstPlane bool) []byte

Chr returns a slice of bytes that contain both the bit planes of a tile's CHR data.

func (*Tile) ColorModel

func (t *Tile) ColorModel() color.Model

image.Image implementation

func (*Tile) FillBackground

func (t *Tile) FillBackground(index uint8)

func (*Tile) IsEmpty

func (t *Tile) IsEmpty() bool

func (*Tile) IsIdentical

func (thisTile *Tile) IsIdentical(otherTile *Tile) bool

func (*Tile) IsNotEmpty

func (t *Tile) IsNotEmpty() bool

func (*Tile) Set

func (t *Tile) Set(x, y int, c color.Color)

drawer.Image implementation

func (*Tile) SetBackgroundIndex

func (t *Tile) SetBackgroundIndex(index uint8)

func (*Tile) SetPaletteIndex

func (t *Tile) SetPaletteIndex(x, y int, idx uint8)

SetPaletteIndex works like Set(), but uses an index instead of a color as input.

func (Tile) ToChr

func (t Tile) ToChr() []byte

CHR

each byte is a single row of pixels
each tile is 16 bytes long
first 8 bytes are the first half of the plane	(color 0 & 1)
second 8 bytes are the second half of the plane	(color 2 & 3)

type TileLayout

type TileLayout int

Ideally, each tile or object will be in its own input file and is assembled into the final CHR layout during assemble time.

Jump to

Keyboard shortcuts

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