module Main where import Data.Maybe import ImageTypes import ReadImage import ShowImage import System.Environment import System.IO -- -------------------------------------- processImage :: FilePath -> FilePath -> (Image -> Image) -> IO () processImage src dst f = do ih <- openBinaryFile src ReadMode c <- hGetContents ih let res = showImage True . f . readImage $ c oh <- openBinaryFile dst WriteMode hPutStr oh res hClose ih hClose oh -- -------------------------------------- main :: IO() main = getArgs >>= main1 main1 :: [String] -> IO() main1 [opr, inp, outp] = do processImage inp outp (lookupOp opr) where lookupOp op = (fromMaybe id . lookup op) fctTab fctTab :: [(String, Image -> Image)] fctTab = [ ("id" , id ) , ("bitmap" , bitmap ) , ("fliph" , flipH ) , ("flipv" , flipV ) , ("gamma.5" , gamma 0.5 ) , ("gamma2" , gamma 2.0 ) , ("halfsize" , halfSize ) , ("invert" , invert ) , ("reduce3" , reduceColors 3 ) , ("rot90" , rot90 ) , ("rot180" , rot180 ) , ("rot270" , rot270 ) , ("double" , scale 2 3 ) , ("tile4" , tile 2 2 ) , ("tilemir4" , tileMirr 2 2 ) , ("shiftrot" , shiftRot 20 20) , ("mult" , \ i -> merge2 (*) i (flipV i)) ] main1 args = hPutStrLn stderr $ "usage: Uebung7 (got: " ++ show args ++ ")" -- --------------------------------------