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 src' <- if src == "-" then B.getContents else B.readFile src
case decodeImage src' of case decodeImage src' of
Left err -> putStrLn err Left err -> putStrLn err
Right img -> do Right img ->
src <- return $ extractDynImage img case extractDynImage img >>= pixelize w h of
case src of Nothing -> return ()
(Just s) -> do Just (f,b) ->
pix <- return $ pixelize s w h let str = img2ascii conv (f,b)
case pix of in mapM_ (\x -> putStr x >> putStrLn "\x1b[0m") (concat <$> str)
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 ()
chunksof :: Int -> [a] -> [[a]] chunksof :: Int -> [a] -> [[a]]
chunksof _ [] = [] 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 :: ((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]] 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 :: Int -> Int -> Image PixelRGB8 -> Maybe (Image PixelRGB8,Image PixelRGB8)
pixelize im@(Image iw ih id) tw th = pixelize tw th im@(Image iw ih id) =
if windoww == 0 || windowh == 0 then if windoww == 0 || windowh == 0 then
Nothing Nothing
else Just (snd $ generateFoldImage (folder filterfun windoww windowh) im tw th, else Just (snd $ generateFoldImage (folder filterfun windoww windowh) im tw th,