small cleanup-work

This commit is contained in:
Nicole Dresselhaus 2015-12-02 01:16:08 +01:00
parent 89061f9a15
commit 7671db99b5

View File

@ -39,19 +39,12 @@ run (Options src w h) = do
src' <- if src == "-" then B.getContents else B.readFile src
case decodeImage src' of
Left err -> putStrLn err
Right img -> do
src <- return $ extractDynImage img
case src of
(Just s) -> do
pix <- return $ pixelize s w h
case pix of
Right img ->
case extractDynImage img >>= pixelize w h of
Nothing -> return ()
Just (f,b) -> do
--savePngImage "test.png" (ImageRGB8 b)
str <- return $ img2ascii conv (f,b)
mapM_ (\x -> putStr x >> putStrLn "\x1b[0m") (concat <$> str)
Nothing -> return ()
Just (f,b) ->
let str = img2ascii conv (f,b)
in mapM_ (\x -> putStr x >> putStrLn "\x1b[0m") (concat <$> str)
chunksof :: Int -> [a] -> [[a]]
chunksof _ [] = []
@ -73,8 +66,8 @@ conv (fp@(PixelRGB8 fr fg fb),PixelRGB8 br bg bb) = printf "\x1b[48;2;%d;%d;%dm\
img2ascii :: ((PixelRGB8,PixelRGB8) -> String) -> (Image PixelRGB8,Image PixelRGB8) -> [[String]]
img2ascii c (fg@(Image w h _),bg@(Image w' h' _)) = (fmap.fmap) (c.(uncurry (pixelAt fg) &&& uncurry (pixelAt bg))) [[(x,y) | x <- [0..w-1]] | y <- [0..h-1]]
pixelize :: Image PixelRGB8 -> Int -> Int -> Maybe (Image PixelRGB8,Image PixelRGB8)
pixelize im@(Image iw ih id) tw th =
pixelize :: Int -> Int -> Image PixelRGB8 -> Maybe (Image PixelRGB8,Image PixelRGB8)
pixelize tw th im@(Image iw ih id) =
if windoww == 0 || windowh == 0 then
Nothing
else Just (snd $ generateFoldImage (folder filterfun windoww windowh) im tw th,