~alcinnz/Mondrian

ref: 7564554b3527f7e220c09c24cc9f8035d3f196b0 Mondrian/app/Convert.hs -rw-r--r-- 1.2 KiB
7564554b — Adrian Cochrane Commit border renderer, make them trapazoidal. 1 year, 3 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