| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
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:
- look up individual cells by layer index and
(x, y)coordinates, withgetRexpaintCell(orunsafeGetRexpaintCellto skip theMaybewhen you know the indices are valid); - or walk every cell:
xpCellsfor a plain list,traverseXp_to run an action per cell,traverseXp/mapXpto rewrite cells.
Build a file with mkLayer / mkXpFile and write it back with writeXPFile.
Synopsis
- newtype RexpaintVersionNumber = RexpaintVersionNumber Int32
- newtype NumberOfLayers = NumberOfLayers Int32
- newtype LayerIndex = LayerIndex Int
- newtype ImageWidth = ImageWidth Int32
- newtype ImageHeight = ImageHeight Int32
- data Layer = Layer {}
- data Cell = Cell {}
- data XpFile = XpFile {}
- getRexpaintCell :: [Layer] -> LayerIndex -> (Int, Int) -> Maybe Cell
- unsafeGetRexpaintCell :: [Layer] -> LayerIndex -> (Int, Int) -> Cell
- parseXPFile :: MonadIO m => FilePath -> m XpFile
- decodeXPFile :: ByteString -> XpFile
- writeXPFile :: MonadIO m => FilePath -> XpFile -> m ()
- encodeXPFile :: XpFile -> ByteString
- mkLayer :: ImageWidth -> ImageHeight -> [Cell] -> Layer
- mkXpFile :: RexpaintVersionNumber -> [Layer] -> XpFile
- xpCells :: XpFile -> [(LayerIndex, (Int, Int), Cell)]
- layerCells :: Layer -> [((Int, Int), Cell)]
- cellsAt :: XpFile -> (Int, Int) -> [Cell]
- traverseXp :: Applicative f => (LayerIndex -> (Int, Int) -> Cell -> f Cell) -> XpFile -> f XpFile
- traverseXp_ :: Applicative f => (LayerIndex -> (Int, Int) -> Cell -> f b) -> XpFile -> f ()
- mapXp :: (LayerIndex -> (Int, Int) -> Cell -> Cell) -> XpFile -> XpFile
Documentation
newtype RexpaintVersionNumber Source #
Version number stored in the beginning of each xp file. This is only used by Rexpaint.
Constructors
| RexpaintVersionNumber Int32 |
Instances
| Show RexpaintVersionNumber Source # | |
Defined in Data.Rexparse Methods showsPrec :: Int -> RexpaintVersionNumber -> ShowS # show :: RexpaintVersionNumber -> String # showList :: [RexpaintVersionNumber] -> ShowS # | |
| Eq RexpaintVersionNumber Source # | |
Defined in Data.Rexparse Methods (==) :: RexpaintVersionNumber -> RexpaintVersionNumber -> Bool # (/=) :: RexpaintVersionNumber -> RexpaintVersionNumber -> Bool # | |
| Ord RexpaintVersionNumber Source # | |
Defined in Data.Rexparse Methods compare :: RexpaintVersionNumber -> RexpaintVersionNumber -> Ordering # (<) :: RexpaintVersionNumber -> RexpaintVersionNumber -> Bool # (<=) :: RexpaintVersionNumber -> RexpaintVersionNumber -> Bool # (>) :: RexpaintVersionNumber -> RexpaintVersionNumber -> Bool # (>=) :: RexpaintVersionNumber -> RexpaintVersionNumber -> Bool # max :: RexpaintVersionNumber -> RexpaintVersionNumber -> RexpaintVersionNumber # min :: RexpaintVersionNumber -> RexpaintVersionNumber -> RexpaintVersionNumber # | |
newtype NumberOfLayers Source #
Amount of layers stored in the picture.
Constructors
| NumberOfLayers Int32 |
Instances
| Show NumberOfLayers Source # | |
Defined in Data.Rexparse Methods showsPrec :: Int -> NumberOfLayers -> ShowS # show :: NumberOfLayers -> String # showList :: [NumberOfLayers] -> ShowS # | |
| Eq NumberOfLayers Source # | |
Defined in Data.Rexparse Methods (==) :: NumberOfLayers -> NumberOfLayers -> Bool # (/=) :: NumberOfLayers -> NumberOfLayers -> Bool # | |
| Ord NumberOfLayers Source # | |
Defined in Data.Rexparse Methods compare :: NumberOfLayers -> NumberOfLayers -> Ordering # (<) :: NumberOfLayers -> NumberOfLayers -> Bool # (<=) :: NumberOfLayers -> NumberOfLayers -> Bool # (>) :: NumberOfLayers -> NumberOfLayers -> Bool # (>=) :: NumberOfLayers -> NumberOfLayers -> Bool # max :: NumberOfLayers -> NumberOfLayers -> NumberOfLayers # min :: NumberOfLayers -> NumberOfLayers -> NumberOfLayers # | |
newtype LayerIndex Source #
Index of a layer within an XpFile, 0 being the bottom layer.
Constructors
| LayerIndex Int |
Instances
newtype ImageWidth Source #
Width in glyphs (not in pixel !).
Constructors
| ImageWidth Int32 |
Instances
newtype ImageHeight Source #
Height in glyphs (not in pixels !).
Constructors
| ImageHeight Int32 |
Instances
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.
Constructors
| Layer | |
Fields
| |
A single cell, containing an asciicode and rgb data for foreground (fg) and background (bg).
Constructors
| Cell | |
A full xp file. Layers are ordered bottom first, top last.
Constructors
| XpFile | |
Fields | |
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.
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.