#CompoScript

#detox parameters
#let bminpc = "20.0"
#let bmaxpc = "50.0"

input  "2.0" to bminpc "input blue minPC (0,255)"
input  "40.0" to bmaxpc "input blue maxPC (0,255)"
input  "0.3"  to rcoef  "input red coefficient (0,1)"
input  "0.1"  to gcoef  "input green coefficient (0,1)"
input  "0.6"  to bcoef  "input blue coefficient (0,1)"

# By far the most ambitious to date. :-)

# Ask the user to drag a directory to us.
repeat
 dragload directory "Drag an input directory of images to process." to indir$
until indir$ <> ""

# Ask them to choose an output directory.
repeat
 dragsave directory "Output" "Drag the output directory to create." to outdir$
until outdir$ <> ""

# check if it exists, and if not, create it.
fileinfo outdir$
if .fileinfo.there = 0 then
 proc create_output_directory
endif

# check it really is a directory
fileinfo outdir$
if .fileinfo.there <> 2 then
 report "Output already exists (and is not a directory). Giving up."
 stop
endif

# process everything in the input directory

repeat
 scandirectory indir$ to found$
 if found$ <> "" then
  proc process_image
 endif
until found$ = ""
end

defproc process_image

# check if we've a canvas...
if .objects < 0 then
 proc make_canvas
endif

# delete anything on it.
select all
delete

# load our image and centre it on the canvas
loadimage found$
select first
moveto centre centre
#star "set DeTox$filename <indir$>.<.directoryscan.leafname> "
star "WimpTask <.composcript$dir>.DeToxPageAccGreyScaled <.selected.imagebase> <bminpc> <bmaxpc> <rcoef> <gcoef> <bcoef>  <indir$>.<.directoryscan.leafname> "

redraw
scaleto  540  1000 AspectLock

PROC save_in_output_directory

endproc


defproc save_in_output_directory

# save as a jpeg in the output directory

export jpeg
{
 
 filename:"<outdir$>.<.directoryscan.leafname>"
 quality:75
}

endproc

defproc create_output_directory
star "cdir <outdir$>"
endproc

defproc make_canvas
makecanvas 1000 2000 0
endproc
