Skip to content

Commit

Permalink
Add --backend flag to select used image manipulation backend
Browse files Browse the repository at this point in the history
  • Loading branch information
ad-si committed Feb 1, 2025
1 parent 346f51d commit a3b7d24
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
26 changes: 24 additions & 2 deletions app/Main.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{-# LANGUAGE OverloadedRecordDot #-}
{-# LANGUAGE QuasiQuotes #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}

{-# HLINT ignore "Replace case with maybe" #-}

module Main where

Expand All @@ -22,7 +25,8 @@ import Protolude (
)
import Protolude qualified as P

import Data.Text as T (isInfixOf, pack, unpack)
import Data.Text (pack, unpack)
import Data.Text qualified as T
import Data.Yaml (decodeFileEither, prettyPrintParseException)
import System.Console.Docopt as Docopt (
Arguments,
Expand All @@ -48,12 +52,15 @@ import System.Directory (
)
import System.FilePath ((</>))

import Control.Arrow ((>>>))
import Lib (loadAndStart)
import Rename (getRenamingBatches)
import Types (
Config,
RenameMode (Even, Odd, Sequential),
SortOrder (Ascending, Descending),
TransformBackend (HipBackend, ImageMagickBackend, SimpleCVBackend),
transformBackendFlag,
)


Expand All @@ -66,9 +73,24 @@ getArgOrExit = getArgOrExitWith patterns


execWithArgs :: Config -> [[Char]] -> IO ()
execWithArgs config cliArgs = do
execWithArgs confFromFile cliArgs = do
args <- parseArgsOrExit patterns cliArgs

let config = case args `getArg` longOption "backend" of
Nothing -> confFromFile
Just backend ->
confFromFile
{ transformBackendFlag =
backend
& ( T.pack
>>> T.toLower
>>> \case
"hip" -> HipBackend
"imagemagick" -> ImageMagickBackend
_ -> SimpleCVBackend
)
}

when (args `isPresent` command "gui") $ do
loadAndStart config Nothing

Expand Down
8 changes: 6 additions & 2 deletions usage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ Correct the perspective of photos
and rename them to match their page numbers.

Usage:
perspec gui
perspec fix <file>...
perspec gui [--backend=<str>]
perspec fix [--backend=<str>] <file>...
perspec rename [options] <directory>

Options:
--backend=<str> Image manipulation backend to use
(SimpleCV, Hip, ImageMagick)

Rename Options:
--start-with=<int> First page number
--even The directory contains only even page numbers
--odd The directory contains only odd page numbers
Expand Down

0 comments on commit a3b7d24

Please sign in to comment.