pathfindImage :: FilePath -> FilePath -> Coord -> Coord -> IO ()
pathfindImage pathIn pathOut startc finishc = do
  
  io <- load Autodetect pathIn

  case io of
    Left err -> do
      putStrLn ("Unable to load image at path: " ++ pathIn)
      print err

    Right (rgb :: Image.RGB) -> do
      
      let
        grid   = imageToGrid rgb
        dim    = dims grid
        start  = c2i dim startc
        finish = c2i dim finishc
        
      {-
      defaultMain [
        bench "searchAstar" $ whnf (\x -> Astar.findPathNormal x start finish) grid
        ]
      -}
      (path, visited) <- return (Astar.findPathNormal grid start finish)

      {-
      defaultMain [
        bench "searchJPS" $ whnf (\x -> JPS.findPathJPS x start finish) grid
        ]
      
      (path, visited) <- return (JPS.findPathJPS grid start finish)
      -}
      
      grid' <- return
        $ (markStartFinish start finish)
        $ (markPath path)
        $ (markVisited visited)
        $ grid
      
      case path of
        [] -> do
          putStrLn("No path found!")
        otherwise -> do
          putStrLn("Found a path!")
          
      image <- return (gridToImage grid')
    
      outExists <- doesFileExist pathOut
      when outExists (removeFile pathOut)
      
      mErr <- save Autodetect pathOut image
      case mErr of
        Nothing -> return ()
        Just err -> do
          putStrLn $ "ERROR - could not save image to path: " ++ pathOut
          print err
  
-- Convert coordinates to / from the Shape format used by Vision (we only need 2d coordinates :) )
pathfindImage :: FilePath -> FilePath -> Coord -> Coord -> IO ()
pathfindImage pathIn pathOut startc finishc = do
  
  io <- load Autodetect pathIn

  case io of
    Left err -> do
      putStrLn ("Unable to load image at path: " ++ pathIn)
      print err

    Right (rgb :: Image.RGB) -> do
      
      let
        grid   = imageToGrid rgb
        dim    = dims grid
        start  = c2i dim startc
        finish = c2i dim finishc
        
      {-
      defaultMain [
        bench "searchAstar" $ whnf (\x -> Astar.findPathNormal x start finish) grid
        ]
      -}
      (path, visited) <- return (Astar.findPathNormal grid start finish)

      {-
      defaultMain [
        bench "searchJPS" $ whnf (\x -> JPS.findPathJPS x start finish) grid
        ]
      
      (path, visited) <- return (JPS.findPathJPS grid start finish)
      -}
      
      grid' <- return
        $ (markStartFinish start finish)
        $ (markPath path)
        $ (markVisited visited)
        $ grid
      
      case path of
        [] -> do
          putStrLn("No path found!")
        otherwise -> do
          putStrLn("Found a path!")
          
      image <- return (gridToImage grid')
    
      outExists <- doesFileExist pathOut
      when outExists (removeFile pathOut)
      
      mErr <- save Autodetect pathOut image
      case mErr of
        Nothing -> return ()
        Just err -> do
          putStrLn $ "ERROR - could not save image to path: " ++ pathOut
          print err
  
-- Convert coordinates to / from the Shape format used by Vision (we only need 2d coordinates :) )
pathfindImage pathIn pathOut startc finishc = do
  
  io <- load Autodetect pathIn

  case io of
    Left err -> do
      putStrLn ("Unable to load image at path: " ++ pathIn)
      print err

    Right (rgb :: Image.RGB) -> do
      
      let
        grid   = imageToGrid rgb
        dim    = dims grid
        start  = c2i dim startc
        finish = c2i dim finishc
        
      {-
      defaultMain [
        bench "searchAstar" $ whnf (\x -> Astar.findPathNormal x start finish) grid
        ]
      -}
      (path, visited) <- return (Astar.findPathNormal grid start finish)

      {-
      defaultMain [
        bench "searchJPS" $ whnf (\x -> JPS.findPathJPS x start finish) grid
        ]
      
      (path, visited) <- return (JPS.findPathJPS grid start finish)
      -}
      
      grid' <- return
        $ (markStartFinish start finish)
        $ (markPath path)
        $ (markVisited visited)
        $ grid
      
      case path of
        [] -> do
          putStrLn("No path found!")
        otherwise -> do
          putStrLn("Found a path!")
          
      image <- return (gridToImage grid')
    
      outExists <- doesFileExist pathOut
      when outExists (removeFile pathOut)
      
      mErr <- save Autodetect pathOut image
      case mErr of
        Nothing -> return ()
        Just err -> do
          putStrLn $ "ERROR - could not save image to path: " ++ pathOut
          print err
  
-- Convert coordinates to / from the Shape format used by Vision (we only need 2d coordinates :) )