small cleanup-work
This commit is contained in:
parent
89061f9a15
commit
7671db99b5
27
src/Main.hs
27
src/Main.hs
@ -12,7 +12,7 @@ import qualified Data.ByteString as B
|
|||||||
import System.IO (stdin)
|
import System.IO (stdin)
|
||||||
|
|
||||||
|
|
||||||
data Options = Options
|
data Options = Options
|
||||||
{ srcFile :: String
|
{ srcFile :: String
|
||||||
, width :: Int
|
, width :: Int
|
||||||
, height :: Int
|
, height :: Int
|
||||||
@ -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 _ [] = []
|
||||||
@ -61,7 +54,7 @@ conv :: (PixelRGB8,PixelRGB8) -> String
|
|||||||
conv (fp@(PixelRGB8 fr fg fb),PixelRGB8 br bg bb) = printf "\x1b[48;2;%d;%d;%dm\x1b[38;2;%d;%d;%dm%c" br bg bb fr fg fb (lumi.computeLuma $ fp)
|
conv (fp@(PixelRGB8 fr fg fb),PixelRGB8 br bg bb) = printf "\x1b[48;2;%d;%d;%dm\x1b[38;2;%d;%d;%dm%c" br bg bb fr fg fb (lumi.computeLuma $ fp)
|
||||||
where
|
where
|
||||||
lumi :: Word8 -> Char
|
lumi :: Word8 -> Char
|
||||||
lumi x
|
lumi x
|
||||||
| x > 225 = '@'
|
| x > 225 = '@'
|
||||||
| x > 180 = 'O'
|
| x > 180 = 'O'
|
||||||
| x > 150 = 'X'
|
| x > 150 = 'X'
|
||||||
@ -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