UTFTConverter-0.1.0.1: Processing popular picture formats into .c or .raw format in RGB565

LicenseMIT
MaintainerAlexander Isenko <alex.isenko@googlemail.com>
Safe HaskellNone
LanguageHaskell2010

Format.Converter

Description

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)

Synopsis

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
 

data Format Source

Currently supported picture formats (by JuicyPixels)

Constructors

Jpeg 
Bmp 
Png 
Gif 
Tga