License | MIT |
---|---|
Maintainer | Alexander Isenko <alex.isenko@googlemail.com> |
Safe Haskell | None |
Language | Haskell2010 |
Format.Converter
exports the functions that create the .c
or .raw
files when the FilePath
is given
Both pictureToRaw
and pictureToC
accept these picture formats
.gif
.png
.jpg / .jpe / .jpeg
.bmp
.tga
If it's not any of those formats, an error gets thrown and if there is an error while decoding the pictures it only gets printed out (it gets skipped)
Documentation
pictureToRaw :: FilePath -> (Format, FilePath) -> IO () Source
pictureToRaw takes a picture, decodes it, parses every pixel to a 4 digit RGB565 hex and saves it to
a file with the same name and a .raw
extention in the specified directory
This function takes two arguments
- first
FilePath
is the directory to save the file to - second
(Format, FilePath)
is the format and filepath of the picture
Possible errors:
- Can throw an error if the picture format is not supported
- If there is an error while decoding the pictures the file gets skipped and an error message is printed out
Results:
If the conversion was successful, a message gets printed
cat_01_bmp_120x120.bmp --> cat_01_bmp_120x120.raw
Example usage: (assumed that the picture is in the directory where ghci was started)
λ> dir <- getCurrentDirectory λ> pictureToRaw dir (Bmp, "cat_01_bmp_120x120.bmp") cat_01_bmp_120x120.bmp --> cat_01_bmp_120x120.raw
pictureToC :: Platform -> FilePath -> (Format, FilePath) -> IO () Source
pictureToC takes a picture, decodes it, parses every pixel to a 4 digit RGB565 hex, adds the header
based on the desired platform and saves it to a file with the same name and a .c
extention in the specified
directory
This function takes three arguments
Platform
is the desired platform to convert to- first
FilePath
is the directory to save the file to - second
(Format, FilePath)
is the format and filepath of the picture
Possible errors:
- Can throw an error if the picture format is not supported
- If there is an error while decoding the pictures the file gets skipped and an error message is printed out
Results:
If the conversion was successful, a message gets printed
cat_01_bmp_120x120.bmp --> cat_01_bmp_120x120.c
Example usage: (assumed that the picture is in the directory where ghci was started)
λ> dir <- getCurrentDirectory λ> pictureToC AVR dir (Bmp, "cat_01_bmp_120x120.bmp") cat_01_bmp_120x120.bmp --> cat_01_bmp_120x120.c
toMaybeFormat :: FilePath -> IO (Maybe Format) Source
Checking if the format is supported via magic bytes safe checking for everything unless .tga
Possible errors:
- It will be problematic in the future if you try to read the file as .tga if it's not encoded as one
Example usage:
λ> toMaybeFormat "cat_01_bmp_120x120.bmp" Just Bmp λ> toMaybeFormat "cat_01_bmp_120x120.jpeg" Just Jpeg λ> toMaybeFormat "cat_01_bmp_120x120.jpe" Just Jpeg