/* $VER: ArtConvert.rexx 1.6 (4.5.2000) (C) by Martin Steigerwald $Id: ArtConvert.rexx 1.6 2000/05/04 13:34:55 helios Exp $ - an ARexx script to automatically convert images with ArtEffect */ OPTIONS RESULTS OPTIONS FAILAT 30 PARSE ARG args.dest args.src args.dest=STRIP(args.dest) args.src=STRIP(args.src) SIGNAL ON SYNTAX SIGNAL ON HALT SIGNAL ON BREAK_C IF ~SHOW("L", "rexxsupport.library") THEN DO IF ~ADDLIB("rexxsupport.library", 0, -30, 0) THEN DO SAY "FATAL ERROR: Could not open rexxsupport.library" END END handle=0 IF ~Initialize() THEN DO Cleanup() EXIT END CALL LoadConfig() IF args.dest~=="" THEN config.dest=args.dest IF args.src~=="" THEN config.src=args.src convertflag=ConfigDialog() IF convertflag=1 THEN DO CALL ConvertFiles() END CALL Cleanup() EXIT break_c: halt: Cleanup() EXIT syntax: SAY 'Error:' rc',' ERRORTEXT(rc) 'in line' sigl'.' Cleanup() EXIT Cleanup: IF SHOW("P", "ArtEffect") THEN DO ADDRESS "ArtEffect" UNLOCKGUI ADDRESS END RETURN 0 EXIT ConvertFiles: PROCEDURE EXPOSE app. config. count=0 src=STRIP(config.src) IF src~=="" THEN DO DO UNTIL src=="" src=STRIP(src) count=count+1 IF LEFT(src,1)=='"' THEN DO PARSE VAR src '"' src.count '"' src END ELSE DO PARSE VAR src src.count ' ' src END /* IF */ src.count=STRIP(src.count) END END IF src.1~=="" THEN DO /* Start ArtEffect if needed */ IF ~SHOW("P", "ArtEffect") THEN DO oldstack=PRAGMA('STACK', 30000) ADDRESS COMMAND 'run >NIL: T:ArtConvert.list LFORMAT "%S%S" FILES' IF RC>0 THEN DO CALL request(getstr(101,"Cancel"), getstr(6, "Scanning directory failed!")) CALL Cleanup() EXIT END IF OPEN(srclist, "T:ArtConvert.list") THEN DO DO UNTIL EOF(srclist) line=READLN(srclist) IF RIGHT(UPPER(line),5) ~== ".INFO" THEN DO IF line~=="" THEN DO CALL Convert(line) END END END CALL CLOSE(srclist) END RETURN 0 convert: PROCEDURE EXPOSE app. config. PARSE ARG srcfile /*format.0="GIF"*/ format.0="IFF-ILBM" format.1="JFIF-JPEG" ; format.2="PNG" IF POS(':', srcfile)=0 THEN DO srcfile=PRAGMA('D')'/'srcfile END destfile=destfilename(srcfile) IF EXISTS(srcfile) THEN DO LOADPIC 'NAME "' || srcfile || '"' IF RC=0 THEN DO /* Picture loaded? */ IF config.scale=1 THEN SCALEPIC config.width config.height f=config.format SAVEPIC 'NAME "'destfile'" NOFLATTEN EXCLUDEALPHA PLUGIN 'format.f IF RC>0 THEN DO CALL request(getstr(101, "Cancel"), getstr(9,"Could not save file »%s«!",destfile)) END CLOSEPIC FORCE ADDRESS END ELSE DO CALL request(getstr(101, "Cancel"), getstr(8,"Could not load file »%s«!",srcfile)) END /* Picture loaded? */ END ELSE DO /* should not happen as already checked in convert files */ request(getstr(101, 'Cancel'), getstr(10,'File »%s« not found',srcfile)) END /* IF EXISTS */ RETURN 0 SaveConfig: PROCEDURE EXPOSE app. config. IF OPEN('fh', app.configfile, 'W') THEN DO WRITELN("fh", "ArtConvertConfig1") WRITELN("fh", "Src =" config.src) WRITELN("fh", "Dest =" config.dest) WRITELN("fh", "Format =" config.format) WRITELN("fh", "Scale =" config.scale) WRITELN("fh", "Width =" config.width) WRITELN("fh", "Height =" config.height) WRITELN("fh", "Keepaspect = " config.keepaspect) WRITELN("fh", "Adjustcolors =" config.adjustcolors) WRITELN("fh", "Depth =" config.depth) CLOSE('fh') END ELSE DO request(getstr(100, 'OK'),getstr(2, 'Could not save config file »%s«!', app.configfile)) END RETURN 0 LoadConfig: PROCEDURE EXPOSE app. config. config.src='""' /* source file, directory or pattern */ config.dest='"RAM:"' /* destination directory */ config.format=0 /* format to convert to */ config.scale=0 /* scale the image? */ config.width=640 /* scaling width */ config.height=480 /* scaling height */ config.keepaspect=1 /* keep aspect ratio? */ config.adjustcolors=0 /* do color adjustment? */ config.depth=24 /* wished depth */ IF OPEN('fh', app.configfile, 'R') THEN DO IF READLN('fh')=='ArtConvertConfig1' THEN DO DO UNTIL EOF("fh") line=STRIP(READLN('fh')) PARSE VAR line option "=" setting option=UPPER(STRIP(option)) setting=STRIP(setting) config.option=setting END END CLOSE('fh') END /* DISABLE */ config.adjustcolors=0 config.keepaspect=0 RETURN ConfigDialog: PROCEDURE EXPOSE config. app. convertflag=0 resolution.count=8 resolution.0.width=80 ; resolution.0.height=60 resolution.1.width=160 ; resolution.1.height=120 resolution.2.width=320 ; resolution.2.height=240 resolution.3.width=640 ; resolution.3.height=480 resolution.4.width=800 ; resolution.4.height=600 resolution.5.width=1024 ; resolution.5.height=768 resolution.6.width=1280 ; resolution.6.height=1024 resolution.7.width=1600 ; resolution.7.height=1200 pipe=ConfigOpenGUI() IF pipe~=="nogui" THEN DO DO WHILE ~EOF(pipe) CALL topipe(pipe, "continue") line=READLN(pipe) PARSE VAR line arg1 arg2 arg3 arg4 IF arg1=="gadget" THEN DO IF arg2=gad.src THEN config.src=STRIP(arg4) IF arg2=gad.dest THEN config.dest=STRIP(arg4) IF arg2=gad.format THEN config.format=arg3 IF arg2=gad.scale THEN DO config.scale=arg3 CALL topipe(pipe, 'id 'gad.width' dis '1-config.scale' ref') CALL topipe(pipe, 'id 'gad.height' dis '1-config.scale' ref') CALL topipe(pipe, 'id 'gad.resolution' dis '1-config.scale' ref') /* DISABLE CALL topipe(pipe, 'id 'gad.keepaspect' dis '1-config.scale' ref') */ END IF arg2=gad.width THEN DO config.width=arg3 res=checkresolution(config.width,config.height) CALL topipe(pipe, 'id 'gad.resolution' s 'res' ref') END IF arg2=gad.height THEN DO config.height=arg3 res=checkresolution(config.width,config.height) CALL topipe(pipe, 'id 'gad.resolution' s 'res' ref') END IF arg2=gad.resolution THEN DO IF arg3~=0 THEN DO arg3=arg3-1 config.width=resolution.arg3.width config.height=resolution.arg3.height END IF arg3=0 THEN DO res=checkresolution(config.width,config.height) IF res~=0 THEN CALL topipe(pipe, 'id 'gad.resolution' s 'res' ref') END CALL topipe(pipe, 'id 'gad.width' defn 'config.width' ref') CALL topipe(pipe, 'id 'gad.height' defn 'config.height' ref') END IF arg2=gad.keepaspect THEN config.keepaspect=arg3 IF arg2=gad.adjustcolors THEN DO config.adjustcolors=arg3 CALL topipe(pipe, 'id 'gad.depth' dis '1-config.adjustcolors' ref') END IF arg2=gad.depth THEN DO config.depth=arg3+1 IF arg3=8 THEN config.depth=24 END IF arg2=gad.convert THEN DO convertflag=1 CALL SaveConfig() LEAVE END IF arg2=gad.cancel THEN LEAVE END IF arg1=="close" THEN LEAVE END CALL CLOSE(pipe) END IF pipe="nogui" THEN DO CALL request(getstr(100,"OK"), getstr(4,"Could not open user interface!")) END RETURN convertflag ConfigOpenGUI: PROCEDURE EXPOSE config. app. gad. resolution. IF OPEN(pipe, "AWNPIPE:ArtConvertGUI/xc") THEN DO CALL topipe(pipe, '"'app.name'" v cg dg db si a m') CALL topipe(pipe, "layout b 0 v") /* multi selection "multi" does not work */ CALL topipe(pipe, 'label gt "'getstr(200,"Source:")'" ua') gad.src=topipe(pipe, 'getfile chl minwidth 200 filename 'config.src) CALL topipe(pipe, 'label gt "'getstr(201,"Destination:")'" ua') gad.dest=topipe(pipe, 'getfile chl drawers minwidth 200 filename 'config.dest) CALL topipe(pipe, 'label gt "'getstr(202,"Format")'" ua') gad.format=topipe(pipe, 'chooser chl pu cl "ILBM|JPEG|PNG" s='config.format) CALL topipe(pipe, 'label gt "'getstr(210,"Scale?")'" ua') gad.scale=topipe(pipe, "checkbox chl s "config.scale) CALL topipe(pipe, 'label gt "'getstr(211,"Width:")'" ua') gad.width=topipe(pipe, "integer chl minn 2 maxn 2000 arrows dis "1-config.scale" defn "config.width) CALL topipe(pipe, 'label gt "'getstr(212,"Height:")'" ua') gad.height=topipe(pipe, "integer chl minn 2 maxn 2000 arrows dis "1-config.scale" defn "config.height) CALL topipe(pipe, 'label gt "'getstr(213,"Resolution:")'" ua') res=checkresolution(config.width, config.height) gad.resolution=topipe(pipe, 'chooser chl pu cl "'getstr(214,"custom|80x60|160x120|320x240|640x480|800x600|1024x768|1280x1024|1600x1200")'" dis '1-config.scale' s 'res) /* DISABLE CALL topipe(pipe, 'label gt "'getstr(215, "Keep aspect?")'" ua') gad.keepaspect=topipe(pipe, "checkbox chl dis "1-config.scale" s "config.keepaspect) CALL topipe(pipe, 'label gt "'getstr(230, "Adjust colors?")'" ua') gad.adjustcolors=topipe(pipe, "checkbox chl s "config.adjustcolors) CALL topipe(pipe, 'label gt "'getstr(231, "Colors: ")'" ua') colors=config.depth-1 IF colors=24 THEN colors=8 gad.depth=topipe(pipe, 'chooser chl pu cl "'getstr(232,"2|4|8|16|32|64|128|256|True color")'" dis '1-config.adjustcolors' s 'colors) */ CALL topipe(pipe, "le") CALL topipe(pipe, "layout si so") gad.convert=topipe(pipe, 'button gt "'getstr(250, "Convert")'" c') gad.cancel=topipe(pipe, 'button gt "'getstr(101, "Cancel")'" c') CALL topipe(pipe, "le") CALL topipe(pipe, "open") END ELSE DO pipe="nogui" END RETURN pipe Initialize: PROCEDURE EXPOSE app. success=1 app.name='ArtConvert' app.configfile="ArtEffect:Settings/ArtConvert.cfg" lf='0a'x app.catalog=0 app.locale=0 IF SHOW('L', 'locale.library') THEN DO app.locale=1 END ELSE DO IF ADDLIB('locale.library',0,-30,0) THEN DO app.locale=1 END END /* IF */ IF app.locale=1 THEN DO app.catalog = OpenCatalog(app.name".catalog",'english',12) END RETURN success /* Support functions */ topipe: PROCEDURE /* this routine does error checking on lines written to pipe.*/ /*get line to output*/ PARSE ARG pipe,out /* write to the pipe*/ CALL WRITELN(pipe,out) /*get responce and parse it.*/ res=READLN(pipe) PARSE VAR res res1 res2 . /* if all is ok return the second part of the responce (usualy the GID)*/ IF res1='ok' THEN RETURN(res2) /* something went wrong, we notify the user then exit */ /*show problem line and responce (reponce may be just a blank line)*/ request(getstr(101, 'Cancel'), getstr(3, "GUI error »%s« / »%s«! Please report to author.", out, res)) CALL CLOSE(pipe.file) Cleanup() EXIT getstr: PROCEDURE EXPOSE app.catalog PARSE ARG msgno, msgstring IF app.catalog ~= 0 THEN msgstring = GetCatalogStr(app.catalog,msgno,msgstring) DO i = 3 TO ARG() PARSE VAR msgstring fore '%s' aft msgstring = fore||ARG(i)||aft END RETURN msgstring request: PROCEDURE EXPOSE app. PARSE ARG buttontexts,reqtext res=0 IF OPEN(req, "AWNPIPE:ArtConvertRequest/xc") THEN DO CALL topipe(req, '"'app.name' request" v cg dg db si a') CALL topipe(req, "layout b 0 v") CALL topipe(req, 'textfield readonly minwidth 300 minheight 60 1 gt "'reqtext'"') CALL topipe(req, "le") CALL topipe(req, "layout si so") first=0 buttons=0 DO WHILE buttontexts~="" PARSE VAR buttontexts buttontext "|" buttontexts IF first=0 THEN DO first=topipe(req, 'button gt "'buttontext'" c') END ELSE DO CALL topipe(req, 'button gt "'buttontext'" c') END buttons=buttons+1 END CALL topipe(req, "le") CALL topipe(req, "open") DO WHILE ~EOF(req) line=READLN(req) PARSE VAR line arg1 arg2 arg3 arg4 IF arg1=="gadget" THEN DO res=arg2-first+1 IF res=buttons THEN res=0 END END CLOSE(req) END RETURN res destfilename: PROCEDURE EXPOSE config. PARSE ARG file /*extension.0="gif"*/ ; extension.0="ilbm" extension.1="jpg" ; extension.2="png" p=LASTPOS("/",file) IF p>0 THEN file=SUBSTR(file,p+1) p=LASTPOS(":",file) IF p>0 THEN file=SUBSTR(file,p+1) /* only strip "" when they are there */ IF LEFT(config.dest,1)=='"' THEN DO PARSE VAR config.dest '"'destdir'"' END ELSE DO destdir=config.dest END destdir=STRIP(destdir) IF RIGHT(destdir,1)~==":" & RIGHT(destdir,1)~=="/" THEN DO destdir=destdir"/" END p=LASTPOS('.',file) IF p>0 THEN file=LEFT(file,p-1) format=config.format destfile = destdir || file || '.' || extension.format RETURN destfile checkresolution: PROCEDURE EXPOSE resolution. PARSE ARG checkwidth,checkheight res=0 DO i=0 TO resolution.count-1 IF (checkwidth=resolution.i.width) & (checkheight=resolution.i.height) THEN DO res=i+1 LEAVE END END RETURN res