small cleanup-work
This commit is contained in:
parent
89061f9a15
commit
7671db99b5
21
src/Main.hs
21
src/Main.hs
@ -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
|
|
||||||
(Just s) -> do
|
|
||||||
pix <- return $ pixelize s w h
|
|
||||||
case pix of
|
|
||||||
Nothing -> return ()
|
Nothing -> return ()
|
||||||
Just (f,b) -> do
|
Just (f,b) ->
|
||||||
--savePngImage "test.png" (ImageRGB8 b)
|
let str = img2ascii conv (f,b)
|
||||||
str <- return $ img2ascii conv (f,b)
|
in mapM_ (\x -> putStr x >> putStrLn "\x1b[0m") (concat <$> str)
|
||||||
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,
|
||||||
|
Loading…
Reference in New Issue
Block a user