@REM apply_hald.bat

VER>NUL
call :Assign_SCRIPT_DIR %0
if ERRORLEVEL 1 (
  echo -E- Apply_Hald failed detecting script source directory
  goto :abort
)
echo Apply_Hald runs from the source in directory %SCRIPT_DIR%
set IMC="%SCRIPT_DIR%\..\bin\convert.bat"
@REM set IMC="c:\Program Files\ImageMagick_711_3\magick.exe"

set HALD_DIR="%SCRIPT_DIR%\..\SAMPLE_HALDS"
@REM set HALD_DIR=".\INP\HALD"

echo Apply_Hald assumes ImageMagick convert/magick utility %IMC%
echo Apply_Hald assumes sample HALDs directory %HALD_DIR%

echo Apply_Hald uses percents as in -crop 50%%x100%% and so on

set INP_SBS=%1%
set INP_SBS_NOEXT=%%~dpn1
set INP_SBS_DIR=%%~dp1
set INP_SBS_PURENAME=%%~n1

set COMMON_STEREO_PARAMS=-crop 50%%%%x100%%%% -swap 0,1 -define compose:args=20 -compose stereo -composite
set COMMON_OUTFILE_PARAMS=-depth 8 -quality 92

@REM set OUTDIR="%INP_SBS_DIR%\ANA"
@REM set OUTDIR=%INP_SBS_DIR%\ANA
@REM set OUTDIR=%%~dp1\ANA
set OUTDIR=%~dp1%\ANA
echo OUTDIR == "%OUTDIR%"
md %OUTDIR%

@REM ============== BEGIN: the ultimate commands ===============================
call %IMC%  "%1"  -gamma 1.0  %HALD_DIR%\hald__ahg_oleg_cp__16.TIF -hald-clut   %COMMON_STEREO_PARAMS%  -set comment "Processed with _cp HALD, gamma=1.0"  %COMMON_OUTFILE_PARAMS%  %OUTDIR%\%INP_SBS_PURENAME%__CP.JPG

call %IMC%  "%1"  -gamma 1.0  %HALD_DIR%\ADD\hald__ahg_oleg_mc__16.TIF -hald-clut   %COMMON_STEREO_PARAMS%  -set comment "Processed with _mc HALD, gamma=1.0"  %COMMON_OUTFILE_PARAMS%  %OUTDIR%\%INP_SBS_PURENAME%__MC.JPG
@REM ============== END:   the ultimate commands ===============================

pause
@REM goto :finish


@REM  "$IMC"  "$1"  -gamma $_gm  $_haldParam  -crop 50%x100% -swap 0,1 -define compose:args=20 -compose stereo -composite  -set comment "$_comment"  -depth 8 $OUT_PROP  "$2"

:finish
@echo on
@exit /B 0
:abort
@echo on
@exit /B 1
@REM ============== Subroutines =======================


@REM Subroutine that assigns SCRIPT_DIR to full dir path of the script source code
@REM Invocation:  call :assign_SCRIPT_DIR %0
:Assign_SCRIPT_DIR
  if (%1)==() (
   echo -E- :assign_SCRIPT_DIR requires script full path as the 1-st parameter
   exit /B 1
  )
  set SCRIPT_PATH=%1
  for %%f in (%SCRIPT_PATH%) do set SCRIPT_FULL_PATH=%%~ff
  for %%f in (%SCRIPT_FULL_PATH%) do set SCRIPT_DIR=%%~dpf
  set SCRIPT_PATH=
  set SCRIPT_FULL_PATH=
  echo -L- Script source code located in "%SCRIPT_DIR%"
exit /B 0
