@@ 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