Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# LANGUAGE OverloadedStrings #-}
- -- import Data.Char
- import System.IO
- import System.Environment
- -- import qualified Data.Text as T
- -- import qualified Data.Text.IO as TI
- import System.Random
- import qualified Data.ByteString as B
- import qualified Data.ByteString.Char8 as BC
- intToChar :: Int -> Char
- intToChar int = toEnum safeInt
- where safeInt = int `mod` 255
- intToBC :: Int -> BC.ByteString
- intToBC int = BC.pack [intToChar int]
- replaceByte :: Int -> Int -> BC.ByteString -> BC.ByteString
- replaceByte loc charVal bytes = mconcat [before,newChar,after]
- where (before,rest) = BC.splitAt loc bytes
- after = BC.drop 1 rest
- newChar = intToBC charVal
- randomReplaceByte :: BC.ByteString -> IO BC.ByteString
- randomReplaceByte bytes = do
- let bytesLength = BC.length bytes
- location <- randomRIO (1,bytesLength)
- charVal <- randomRIO (0,255)
- return (replaceByte location charVal bytes)
- main :: IO ()
- main = do
- args <- getArgs
- let filename = args !! 0
- imageFile <- BC.readFile filename
- glitched <- randomReplaceByte imageFile
- let glitchedFileName = mconcat ["glitched_",filename]
- BC.writeFile glitchedFileName glitched
- putStrLn "done"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement