~alcinnz/Mondrian

ref: c5cdc91e33c1ef20ed082d6a7115eeccf213fc83 Mondrian/app/Convert.hs -rw-r--r-- 1.2 KiB
c5cdc91e — Adrian Cochrane Parse CSS borders! 1 year, 5 months ago
                                                                                
bd4c8802 Adrian Cochrane
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
module Main where

import Codec.Picture (readImage, savePngImage, DynamicImage(..), Image, PixelF)
import Codec.Picture.Types (promoteImage, convertImage, pixelMap)
import System.Environment (getArgs)

main :: IO ()
main = do
    [path] <- getArgs
    Right img <- readImage path
    savePngImage "out.png" $ convertDyn img

-- Convert pixels to some flavour of RGBA
convertDyn :: DynamicImage -> DynamicImage
convertDyn (ImageY8 img) = ImageRGBA8 $ promoteImage img
convertDyn (ImageY16 img) = ImageRGBA16 $ promoteImage img
convertDyn (ImageY32 img) =
    ImageRGBF $ promoteImage (pixelMap fromIntegral img :: Image PixelF)
convertDyn (ImageYF img) = ImageRGBF $ promoteImage img
convertDyn (ImageYA8 img) = ImageRGBA8 $ promoteImage img
convertDyn (ImageYA16 img) = ImageRGBA16 $ promoteImage img
convertDyn (ImageRGB8 img) = ImageRGB8 img
convertDyn (ImageRGB16 img) = ImageRGB16 img
convertDyn (ImageRGBF img) = ImageRGBF img
convertDyn (ImageRGBA8 img) = ImageRGBA8 img
convertDyn (ImageRGBA16 img) = ImageRGBA16 img
convertDyn (ImageYCbCr8 img) = ImageRGB8 $ convertImage img
convertDyn (ImageCMYK8 img) = ImageRGB8 $ convertImage img
convertDyn (ImageCMYK16 img) = ImageRGB16 $ convertImage img