Visitar URL original
Data.Rexparse
rexparse
Safe HaskellNone
LanguageHaskell2010

Data.Rexparse

Description

Rexparse is a simple library to read the REXPaint .xp format.

For efficiency, cells are stored in arrays. Read a file with parseXPFile; from the resulting XpFile you can either:

Build a file with mkLayer / mkXpFile and write it back with writeXPFile.

Synopsis

Documentation

newtype LayerIndex Source #

Index of a layer within an XpFile, 0 being the bottom layer.

Constructors

LayerIndex Int 

Instances

Instances details
Enum LayerIndex Source # 
Instance details

Defined in Data.Rexparse

Num LayerIndex Source # 
Instance details

Defined in Data.Rexparse

Integral LayerIndex Source # 
Instance details

Defined in Data.Rexparse

Real LayerIndex Source # 
Instance details

Defined in Data.Rexparse

Show LayerIndex Source # 
Instance details

Defined in Data.Rexparse

Eq LayerIndex Source # 
Instance details

Defined in Data.Rexparse

Ord LayerIndex Source # 
Instance details

Defined in Data.Rexparse

newtype ImageWidth Source #

Width in glyphs (not in pixel !).

Constructors

ImageWidth Int32 

Instances

Instances details
Enum ImageWidth Source # 
Instance details

Defined in Data.Rexparse

Num ImageWidth Source # 
Instance details

Defined in Data.Rexparse

Integral ImageWidth Source # 
Instance details

Defined in Data.Rexparse

Real ImageWidth Source # 
Instance details

Defined in Data.Rexparse

Show ImageWidth Source # 
Instance details

Defined in Data.Rexparse

Eq ImageWidth Source # 
Instance details

Defined in Data.Rexparse

Ord ImageWidth Source # 
Instance details

Defined in Data.Rexparse

newtype ImageHeight Source #

Height in glyphs (not in pixels !).

Constructors

ImageHeight Int32 

Instances

Instances details
Enum ImageHeight Source # 
Instance details

Defined in Data.Rexparse

Num ImageHeight Source # 
Instance details

Defined in Data.Rexparse

Integral ImageHeight Source # 
Instance details

Defined in Data.Rexparse

Real ImageHeight Source # 
Instance details

Defined in Data.Rexparse

Show ImageHeight Source # 
Instance details

Defined in Data.Rexparse

Eq ImageHeight Source # 
Instance details

Defined in Data.Rexparse

Ord ImageHeight Source # 
Instance details

Defined in Data.Rexparse

data Layer Source #

A single layer. Width and height are repeated on each layer, as per xp file specifications. Cells are stored in a single array, as in the xp file itself.

Instances

Instances details
Show Layer Source # 
Instance details

Defined in Data.Rexparse

Methods

showsPrec :: Int -> Layer -> ShowS #

show :: Layer -> String #

showList :: [Layer] -> ShowS #

Eq Layer Source # 
Instance details

Defined in Data.Rexparse

Methods

(==) :: Layer -> Layer -> Bool #

(/=) :: Layer -> Layer -> Bool #

Ord Layer Source # 
Instance details

Defined in Data.Rexparse

Methods

compare :: Layer -> Layer -> Ordering #

(<) :: Layer -> Layer -> Bool #

(<=) :: Layer -> Layer -> Bool #

(>) :: Layer -> Layer -> Bool #

(>=) :: Layer -> Layer -> Bool #

max :: Layer -> Layer -> Layer #

min :: Layer -> Layer -> Layer #

data Cell Source #

A single cell, containing an asciicode and rgb data for foreground (fg) and background (bg).

Constructors

Cell 

Instances

Instances details
Show Cell Source # 
Instance details

Defined in Data.Rexparse

Methods

showsPrec :: Int -> Cell -> ShowS #

show :: Cell -> String #

showList :: [Cell] -> ShowS #

Eq Cell Source # 
Instance details

Defined in Data.Rexparse

Methods

(==) :: Cell -> Cell -> Bool #

(/=) :: Cell -> Cell -> Bool #

Ord Cell Source # 
Instance details

Defined in Data.Rexparse

Methods

compare :: Cell -> Cell -> Ordering #

(<) :: Cell -> Cell -> Bool #

(<=) :: Cell -> Cell -> Bool #

(>) :: Cell -> Cell -> Bool #

(>=) :: Cell -> Cell -> Bool #

max :: Cell -> Cell -> Cell #

min :: Cell -> Cell -> Cell #

data XpFile Source #

A full xp file. Layers are ordered bottom first, top last.

Instances

Instances details
Show XpFile Source # 
Instance details

Defined in Data.Rexparse

Eq XpFile Source # 
Instance details

Defined in Data.Rexparse

Methods

(==) :: XpFile -> XpFile -> Bool #

(/=) :: XpFile -> XpFile -> Bool #

Ord XpFile Source # 
Instance details

Defined in Data.Rexparse

getRexpaintCell :: [Layer] -> LayerIndex -> (Int, Int) -> Maybe Cell Source #

Fetch a given cell in a list of layers, given a layer number and a set of coords (x, y).

unsafeGetRexpaintCell :: [Layer] -> LayerIndex -> (Int, Int) -> Cell Source #

Equivalent of getRexpaintCell but without safety.

parseXPFile :: MonadIO m => FilePath -> m XpFile Source #

Parse a xp file. This doesn't include proper error management, so you might want to call this with some try.

decodeXPFile :: ByteString -> XpFile Source #

Decode the gzip-compressed on-disk representation of a xp file. Inverse of encodeXPFile. Partial on malformed input, like parseXPFile.

writeXPFile :: MonadIO m => FilePath -> XpFile -> m () Source #

Write an XpFile to disk in REXPaint's format.

encodeXPFile :: XpFile -> ByteString Source #

Serialise an XpFile to REXPaint's gzip-compressed on-disk format. The layer count written is derived from the layers list, not from the numberOfLayers field.

mkLayer :: ImageWidth -> ImageHeight -> [Cell] -> Layer Source #

Build a Layer from its cells in the on-disk order: column x = 0 top to bottom, then x = 1, and so on. The list must hold exactly width * height cells.

mkXpFile :: RexpaintVersionNumber -> [Layer] -> XpFile Source #

Assemble an XpFile from its layers, bottom first. numberOfLayers is derived from the list.

xpCells :: XpFile -> [(LayerIndex, (Int, Int), Cell)] Source #

List all the content of a xp file: bottom layer first; per layer, we then iterate in a column-major fashion, top to bottom then left to right.

layerCells :: Layer -> [((Int, Int), Cell)] Source #

List all the cells in a given layer.

cellsAt :: XpFile -> (Int, Int) -> [Cell] Source #

Fetch the cell at a given set of coords in every layer that has one, bottom layer first.

traverseXp :: Applicative f => (LayerIndex -> (Int, Int) -> Cell -> f Cell) -> XpFile -> f XpFile Source #

Traversal of an xp file. Useful if you need to alter the content of a file and need some applicative to do so.

traverseXp_ :: Applicative f => (LayerIndex -> (Int, Int) -> Cell -> f b) -> XpFile -> f () Source #

Traversal of an xp file. Typical use case would be to call a display function for each cell.

mapXp :: (LayerIndex -> (Int, Int) -> Cell -> Cell) -> XpFile -> XpFile Source #

Map over an xpfile. Useful if you need to alter an xp file without needing any kind of applicative in your process.