/* ****************************************************************** */
/*               Convert Pictures Batch load & Save                   */
/* ****************************************************************** */



/* Add REXX libraries */


/*     REXX Support Library     */

if ~show('L','rexxsupport.library') then
   do
     if addlib('rexxsupport.library',0,-30,0) then
        say 'Added library 'rexxsupport.library''
     else do
        say 'REXX Support library not present'
        exit
     end
   end


/*     REXX Math Library     */

if ~show('L','rexxmathlib.library') then
   do
     if addlib('rexxmathlib.library',0,-30,0) then
        say 'Added library 'rexxmathlib.library''
     else do
        say 'REXX Math library not present'
        Exit    
 end
   end


OPTIONS RESULTS


Address 'ADPro'
Lformat 'Universal'
Sformat 'IFF'
Address 'REXX'

      /*CALLS*/
call Selfiles

     END     /*END CALLS*/

Selfiles:
Address 'ADPro'
First_Flag = 0

ADPRO_TO_FRONT

   GETDIR 'BATCH-FILE-LOAD-DIRECTORY'
   IF RC ~= 0 then exit
   Dnam = ADPRO_RESULT
        /*Places '/' after Director Name if now ':' present*/

     Dnam = STRIP(dnam)
        IF RIGHT(Dnam  , 1) ~= ':' THEN Dnam  = Dnam  || '/'

Address 'ADPro'
   GETDIR 'BATCH-FILE-SAVE-DIRECTORY'
   IF RC ~= 0 then exit
   SDIR = ADPRO_RESULT
        /*Places '/' after Director Name if now ':' present*/

     Sdir = STRIP(Sdir)
        IF RIGHT(Sdir , 1) ~= ':' THEN Sdir = Sdir || '/'

Address 'REXX'


           /*Gets Files In Directory*/
           contents = Showdir(dnam, 'files')
         do i = 1 to words(contents)
       thefile = word(contents,i)

           /*Calls Operators*/

           Call Loop
        end i

             /*Begin Operator Call*/
Loop:
Address 'ADPro'
LOAD Dnam || thefile
IF RC ~= 0 THEN DO
        OKAY1 'Could Not Load' thefile
        EXIT
    END



            /*Ask's if You want Pallet Locked After First Pic*/

        IF FIRST_FLAG = 0 THEN DO

        /* If this is the first frame, see if the user wants to
               lock the palette for the remaining frames.*/

	PSTATUS UNLOCKED
	PTOTAL 32
	POFFSET 0
	PUSED  32
	PWIDTH ENHANCED
	PLOAD 'env:Iconillusion.prefs'
        FIRST_FLAG = 1

    END

     /*Operator Process*/

/*Screen_type 7*/

	Operator 'Color_To_Gray'

	PSTATUS UNLOCKED
	PTOTAL 32
	POFFSET 0
	PUSED  32
	PWIDTH ENHANCED
	PLOAD 'env:Iconillusion.prefs'
	PTOTAL 16
	PUSED 12
	POFFSET 4
	PSTATUS LOCKED

	Dither 1
	PCT_SCALE 40 40
	RENDER_TYPE CUST
	EXECUTE

    /*Save file*/

Address 'ADPro'
save Sdir || thefile 'Image'
IF RC ~= 0 THEN DO
        OKAY1 'Could Not Save' Sdir || thefile
        EXIT
    END

