~alcinnz/Mondrian

bd4c8802145a324967cba2e10fb1fe6f5a7bf117 — Adrian Cochrane 1 year, 6 months ago cde2102
Upload Juicy Pixels test script.
1 files changed, 29 insertions(+), 0 deletions(-)

A app/Convert.hs
A app/Convert.hs => app/Convert.hs +29 -0
@@ 0,0 1,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