module Main
where
-import Data.Maybe (fromJust)
-import Control.Monad (when)
+import Control.Monad ( when )
import qualified Data.Array.Repa as R
-import Data.Maybe (isJust)
-import GHC.Conc (getNumProcessors, setNumCapabilities)
-import System.IO (hPutStrLn, stderr)
-import System.Exit (exitSuccess, exitWith, ExitCode(..))
+import Data.Maybe ( fromJust )
+import GHC.Conc ( getNumProcessors, setNumCapabilities )
+import System.IO ( hPutStrLn, stderr )
+import System.Exit ( exitSuccess, exitWith, ExitCode(..) )
-import CommandLine (Args(..), apply_args)
+import CommandLine ( Args(..), apply_args )
import ExitCodes
-import Grid (zoom)
+import Grid ( zoom )
import Volumetric (
bracket_array,
flip_x,
swap_bytes,
write_values_to_bmp,
write_word16s,
- z_slice
- )
+ z_slice )
validate_args :: Args -> IO ()
num_procs <- getNumProcessors
setNumCapabilities num_procs
- -- Determine whether we're doing 2d or 3d. If we're given a slice,
- -- assume 2d.
let shape = (R.Z R.:. depth R.:. height R.:. width) :: R.DIM3
- if (isJust slice) then
- main2d args shape
- else
- main3d args shape
+ -- Determine whether we're doing 2d or 3d. If we're given a slice,
+ -- assume 2d.
+ let main_function = case slice of
+ Nothing -> main3d
+ Just _ -> main2d
+ main_function args shape
exitSuccess
- where
-
-
main3d :: Args -> R.DIM3 -> IO ()
main3d Args{..} shape = do
let arr_shaped = R.reshape shape arr_swapped
dbl_data <- R.computeUnboxedP $ R.map fromIntegral arr_shaped
raw_output <- zoom dbl_data zoom_factor
- word16_output <- R.computeUnboxedP $ round_array raw_output
- write_word16s output word16_output
+ let word16_output = round_array raw_output
+ -- Switch the bytes order back to what it was. This lets us use the
+ -- same program to view the input/output data.
+ swapped_output <- R.computeUnboxedP $ swap_bytes word16_output
+ write_word16s output swapped_output
main2d :: Args -> R.DIM3 -> IO ()