home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Graphics / PPT / rexx / ConvertFileFormat.prx < prev    next >
Text File  |  1998-11-07  |  5KB  |  184 lines

  1. /*
  2.     This script loads a file and converts it to any format PPT supports.
  3.  
  4.     Known bugs:
  5.     - Works only on AGA or CyberGfx.
  6.  
  7.     $Id: ConvertFileFormat.prx,v 1.1 1998/11/08 00:22:28 nobody Exp nobody $
  8. */
  9.  
  10. OPTIONS RESULTS
  11. SIGNAL ON ERROR
  12. IF ADDRESS() = REXX THEN DO
  13.     startedfromcli = 1
  14.     ADDRESS PPT
  15. END
  16. ELSE DO
  17.     startedfromcli = 0
  18.     ADDRESS PPT
  19. END
  20. RESULT = 'no result'
  21.  
  22. /*---------------------------------------------------------------------*/
  23.  
  24. PPT_TO_FRONT
  25.  
  26. /*
  27.  *  Open file
  28.  */
  29.  
  30. ASKFILE '"Open file to convert"' POS "Open"
  31. loadfile = RESULT
  32.  
  33. LOADFRAME loadfile
  34. myframe = RESULT
  35.  
  36. /*
  37.  *  Gather a list of I/O modules and ask the user
  38.  *  which format he wishes to use for output.
  39.  */
  40.  
  41. LISTIOMODULES STEM iomodlist ONLYSAVERS
  42.  
  43. iocyc.type=CYCLE
  44. iocyc.popup=1
  45. iocyc.labels=""
  46. DO i = 1 to iomodlist.0
  47.     IF i = 1 THEN
  48.         iocyc.labels=iomodlist.i
  49.     ELSE
  50.         iocyc.labels=iocyc.labels || "|" || iomodlist.i
  51. END
  52.  
  53. ASKREQ '"Please choose the output format"' iocyc
  54.  
  55. IF RESULT = 0 THEN
  56. DO
  57.     iomodnum = iocyc.value + 1
  58.  
  59.     IOMODULEINFO iomodlist.iomodnum STEM modinfo
  60.  
  61.     ASKFILE '"Save file"' POS "Save!" ID "T:" SAVE
  62.     savefile = RESULT
  63.  
  64.     /*
  65.      *  Do generic checks on how to convert the file before
  66.      *  saving.  This does a couple of assumptions, such as
  67.      *  the RGB model is always supported if ARGB is, etc.
  68.      *
  69.      *  This script always tries to keep the colorspace
  70.      *  the same, then it will lose first the transparency
  71.      *  information.  It will try to keep color available
  72.      *  as long as possible.
  73.      */
  74.  
  75.     FRAMEINFO myframe STEM imginfo
  76.     render = 0
  77.  
  78.     IF imginfo.colorspace = "RGB" THEN
  79.     DO
  80.         IF POS("RGB",modinfo.saveformats) = 0 THEN
  81.         DO
  82.             IF POS("Colormapped",modinfo.saveformats) = 0 THEN
  83.             DO
  84.                 IF POS("Greyscale",modinfo.saveformats) = 0 THEN
  85.                 DO
  86.                     SHOWERROR '"Cannot convert to this format"'
  87.                     EXIT 10
  88.                 END
  89.                 ELSE DO
  90.                     PROCESS myframe "Greyscale"
  91.                 END
  92.             END
  93.             ELSE DO
  94.                 render = 1
  95.             END
  96.         END
  97.         ELSE SAY 'Using RGB'
  98.     END
  99.     ELSE IF imginfo.colorspace = "ARGB" THEN
  100.     DO
  101.         IF POS("ARGB",modinfo.saveformats) = 0 THEN
  102.         DO
  103.             IF POS("RGB",modinfo.saveformats) = 0 THEN
  104.             DO
  105.                 IF POS("Colormapped",modinfo.saveformats) = 0 THEN
  106.                 DO
  107.                     IF POS("Greyscale",modinfo.saveformats) = 0 THEN
  108.                     DO
  109.                         SHOWERROR '"Cannot convert to this format"'
  110.                         EXIT 10
  111.                     END
  112.                     ELSE DO
  113.                         PROCESS myframe "Greyscale"
  114.                     END
  115.                 END
  116.                 ELSE DO
  117.                     render = 1
  118.                 END
  119.             END
  120.             ELSE DO
  121.                 PROCESS myframe "TrueColor"
  122.             END
  123.         END
  124.         ELSE SAY 'Using ARGB: ' modinfo.saveformats
  125.     END
  126.     ELSE IF imginfo.colorspace = "Greyscale" THEN
  127.     DO
  128.         IF POS("Greyscale",modinfo.saveformats) = 0 THEN
  129.         DO
  130.             IF POS("RGB",modinfo.saveformats) = 0 THEN
  131.             DO
  132.                 IF POS("Colormapped",modinfo.saveformats) = 0 THEN
  133.                 DO
  134.                     SHOWERROR '"Cannot convert to this format"'
  135.                     EXIT 10
  136.                 END
  137.                 ELSE DO
  138.                    render = 1
  139.                 END
  140.             END
  141.             ELSE DO
  142.                 PROCESS myframe "Truecolor"
  143.             END
  144.         END
  145.         ELSE SAY 'using Grey'
  146.     END
  147.  
  148.     /*
  149.      *  If we need to save a colormapped image, we do it here.
  150.      *  BUG: I probably should offer the user a possibility to
  151.      *  determine the number of colors and the dither mode.
  152.      */
  153.  
  154.     IF render = 1 THEN
  155.     DO
  156.         SETRENDERPREFS myframe NCOLORS 256 MODE Color DITHER "Floyd-Steinberg"
  157.         'RENDER' myframe
  158.         SAVEFRAMEAS myframe savefile FORMAT iomodlist.iomodnum COLORMAPPED
  159.         CLOSERENDER myframe
  160.     END
  161.     ELSE DO
  162.         SAVEFRAMEAS myframe savefile FORMAT iomodlist.iomodnum
  163.     END
  164.  
  165.     DELETEFRAME myframe FORCE
  166. END
  167.  
  168. EXIT 0
  169.  
  170. /*-------------------------------------------------------------------*/
  171. /* Again, keep this part intact. This is the error handler. */
  172. ERROR :
  173. returncode = RC
  174. IF startedfromcli = 1 THEN DO
  175.     SAY 'ERROR ' returncode ' on line ' SIGL ': ' RC2
  176.     PPT_TO_BACK
  177. END
  178. ELSE
  179.     SHOWERROR '"'RC2'"' SIGL
  180. EXIT returncode
  181.  
  182.  
  183.  
  184.