home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Grafik / Misc / ImageEnginer / ARexx / Batch / Circle_alpha_pattern.ieb < prev    next >
Encoding:
Text File  |  1997-02-02  |  6.5 KB  |  237 lines

  1. /*
  2. ** $VER: Circle_alpha_pattern.ieb 1.11, IE Arexx script
  3. ** Image Engineer Batch Processing script
  4. ** Copyright © by Patrik M Nydensten
  5. ** 25/1 1997 Stockholm/Sweden
  6. **
  7. ** Place PRIMARY images in a circular pattern on SECONDARY image with
  8. ** ALPHA channel as transparency level.
  9. */
  10.  
  11. options results
  12. signal on error
  13.  
  14. parse arg input command
  15. input = upper(strip(input))
  16. address 'IMAGEENGINEER'
  17.  
  18. select  /* Required batch script commands */
  19.   when input = 'INFO' then    return get_info()
  20.   when input = 'CONFIG' then  return get_config(command)
  21.   when input = 'PROCESS' then return process_image(command)
  22.   otherwise do
  23.     'REQUEST' '"Failure in call to batch script!"' '" Quit "'
  24.     return '<ERROR>'
  25.   end
  26. end
  27.  
  28. exit 0
  29.  
  30. /* Required "Get_info" procedure  ------------------------------------ */
  31. /* S = SECONDARY, A = ALPHA, 1 = Single file, 2 = Multiple files       */
  32. /* F = Current image number                                            */
  33.  
  34. get_info:
  35.   back = 'OK S2 A2 F'
  36. return back
  37.  
  38. /* Required "Get_config" procedure  ---------------------------------- */
  39.  
  40. get_config:
  41.   parse arg '"'command'"'
  42.  
  43.   Xoff=128 ; Yoff=128 ; Angle=0 ; Radius=64
  44.  
  45.   if command ~= '' then parse var command Xoff Yoff '#'Objects Angle Radius '#'Rotate
  46.  
  47.   'IE_TO_FRONT'
  48.  
  49.   form = 'FORM "Circle Alpha Pattern" " OK | Cancel "',
  50.   ' INTEGER,"X offset",0,4096,'Xoff',SLIDER',
  51.   ' INTEGER,"Y offset",0,4096,'Yoff',SLIDER',
  52.   ' INTEGER,"Rotation angle",-3600,3600,'Angle',SLIDER',
  53.   ' INTEGER,"Pattern radius",0,4096,'Radius',SLIDER'
  54.  
  55.   if command = '' then do
  56.     form = form||' INTEGER,"Number of objects",1,360,5,SLIDER',
  57.     ' CHECKBOX,"Rotate objects within circle?",1'
  58.  
  59.     form
  60.     parse var result ok Xoff Yoff Angle Radius Objects Rotate
  61.     if ok = 0 then return '<ERROR>'
  62.   end
  63.   else do
  64.     form
  65.     parse var result ok Xoff Yoff Angle Radius
  66.     if ok = 0 then return '<ERROR>'
  67.  
  68.     Objects = 'none'
  69.     Rotate = 'none'
  70.   end
  71.  
  72.   back = Xoff Yoff '#'Objects Angle Radius '#'strip(Rotate)
  73. return back
  74.  
  75. /* Required "Process_image" procedure  ------------------------------- */
  76.  
  77. process_image:
  78.   parse arg '"'src_image'"' '"'dst_image'"' '"'options'"' '"'sec_image'"' '"'alp_image'"' '"'frame':'num_frames'"'
  79.   parse var options Xoff Yoff '#'Objects Angle Radius '#'Rotate .
  80.  
  81.   if add_mathlib() = '<ERROR>' then return '<ERROR>'
  82.  
  83.   'OPEN' '"'src_image'"' '24'
  84.   if (RC ~= 0) then do
  85.     'IE_TO_FRONT'
  86.     'REQUEST' '"Failed to load image:' d2c(10)||src_image'"' '" OK "'
  87.     return '<ERROR>'
  88.   end
  89.   else LoadImage = result
  90.  
  91.   'OPEN' '"'sec_image'"' '24'
  92.   if (RC ~= 0) then do
  93.     'IE_TO_FRONT'
  94.     'REQUEST' '"Failed to load SECONDARY image:' d2c(10)||sec_image'"' '" OK "'
  95.     return '<ERROR>'
  96.   end
  97.   else SecImage = result
  98.  
  99.   'OPEN' '"'alp_image'"' '8'
  100.   if (RC ~= 0) then do
  101.     'IE_TO_FRONT'
  102.     'REQUEST' '"Failed to load ALPHA image:' d2c(10)||alp_image'"' '" OK "'
  103.     return '<ERROR>'
  104.   end
  105.   else AlphaImage = result
  106.  
  107.   do until ((Angle < 360)&(Angle >= 0))
  108.     if Angle > 359 then Angle = Angle - 360
  109.     if Angle < 0 then Angle = Angle + 360
  110.   end
  111.  
  112.   'PROJECT_INFO' LoadImage 'WIDTH'  /* PRI image width */
  113.   PIW = RESULT
  114.   'PROJECT_INFO' LoadImage 'HEIGHT' /* PRI image height */
  115.   PIH = RESULT
  116.  
  117.   'PROJECT_INFO' AlphaImage 'WIDTH'   /* ALP image width */
  118.   AIW = RESULT
  119.   'PROJECT_INFO' AlphaImage 'HEIGHT'  /* ALP image height */
  120.   AIH = RESULT
  121.  
  122.   /* Check if ALP and PRI has same size */
  123.  
  124.   if (AIW ~= PIW)|(AIH ~= PIH) then do
  125.     'SCALE' AlphaImage PIW PIH 'BEST'
  126.     ScaledAlphaImage = Result
  127.     'CLOSE' AlphaImage
  128.     AlphaImage = ScaledAlphaImage
  129.   end
  130.  
  131.   'PROJECT_INFO' SecImage 'WIDTH'   /* SEC image width */
  132.   SIW = RESULT
  133.   'PROJECT_INFO' SecImage 'HEIGHT'  /* SEC image height */
  134.   SIH = RESULT
  135.  
  136.   do i = 1 to Objects
  137.  
  138.     ObjAngle = Angle+((i-1)*360/Objects)
  139.  
  140.     NewXoff = Xoff + trunc( cos(((ObjAngle)/360*6.2831853)+1.57079633)*Radius )
  141.     NewYoff = Yoff + trunc( sin(((ObjAngle)/360*6.2831853)+1.57079633)*Radius )
  142.  
  143.     ObjAngle = trunc( ObjAngle )
  144.  
  145.     if (Rotate = 1)&(ObjAngle ~= 0) then do
  146.       'ROTATE' LoadImage ObjAngle 'BEST'  /* Rotate image */
  147.       NewLoadImage = result
  148.       'ROTATE' AlphaImage ObjAngle 'BEST'  /* Rotate alpha */
  149.       NewAlphaImage = result
  150.     end /* do rotate within */
  151.     else do
  152.       NewLoadImage = LoadImage
  153.       NewAlphaImage = AlphaImage
  154.     end
  155.  
  156.     'PROJECT_INFO' NewLoadImage 'WIDTH'  /* NewPRI image width */
  157.     NewPIW = Result
  158.     'PROJECT_INFO' NewLoadImage 'HEIGHT' /* NewPRI image height */
  159.     NewPIH = Result
  160.  
  161.     NewXoff = NewXoff - trunc( NewPIW/2 )
  162.     NewYoff = NewYoff - trunc( NewPIH/2 )
  163.  
  164.     if NewXoff < -NewPIW then NewXoff = -NewPIW
  165.     if NewXoff > SIW then NewXoff = SIW
  166.     if NewYoff < -NewPIH then NewYoff = -NewPIH
  167.     if NewYoff > SIH then NewYoff = SIH
  168.  
  169.     'MARK' NewLoadImage 'PRIMARY'
  170.     'MARK' SecImage 'SECONDARY'
  171.     'MARK' NewAlphaImage 'ALPHA'
  172.  
  173.     'COMPOSITE' NewXoff NewYoff 'ALPHA'
  174.     NewSecImage = Result
  175.     'CLOSE' SecImage
  176.     SecImage = NewSecImage
  177.  
  178.     if (Rotate = 1)&(ObjAngle ~= 0) then do
  179.       'CLOSE' NewLoadImage
  180.       'CLOSE' NewAlphaImage
  181.     end
  182.  
  183.   end /* Objects loop */
  184.  
  185.   'CLOSE' AlphaImage
  186.   'CLOSE' LoadImage
  187.  
  188.   OutputImage = SecImage
  189.  
  190.   if getclip('cfg_save_frmt')='' then setclip('cfg_save_frmt','ILBM CmpByteRun1')
  191.   'SAVE_DATA' OutputImage '"'dst_image'"' '"'getclip('cfg_save_frmt')'"'
  192.   if (RC ~= 0) then do
  193.     'IE_TO_FRONT'
  194.     'REQUEST' '"Failed to save image:' d2c(10)||dst_image'"' '" OK "'
  195.     return '<ERROR>'
  196.   end
  197.   'CLOSE' OutputImage
  198.  
  199.   back = 'OK'
  200. return back
  201.  
  202. /* Internal procedures  ---------------------------------------------- */
  203.  
  204. add_mathlib:
  205.   if ~show(L,'rexxmathlib.library') then do
  206.     if exists('LIBS:rexxmathlib.library') then do
  207.       if ~addlib('rexxmathlib.library',0,-30,0) then do
  208.         'REQUEST' '"Failed to load libs:rexxmathlib.library!"' '" OK "'
  209.         return '<ERROR>'
  210.       end
  211.     end /* lib found on disk */
  212.     else do
  213.       'REQUEST' '"Failed to find libs:rexxmathlib.library!"' '" OK "'
  214.       return '<ERROR>'
  215.     end
  216.   end /* lib exists in mem */
  217. return 'OK'
  218.  
  219. /*******************************************************************/
  220. /* This is where control goes when an error code is returned by IE */
  221. /* It puts up a message saying what happened and on which line     */
  222. /*******************************************************************/
  223.  
  224. error:
  225. if RC=5 then do
  226.     IE_TO_FRONT
  227.     LAST_ERROR
  228.     'REQUEST "'||RESULT||'"'
  229. end
  230. else do
  231.     IE_TO_FRONT
  232.     LAST_ERROR
  233.     'REQUEST "Error detected!!!'||D2C(10)||'Image Engineer error message is as follows'||D2C(10)||result||D2C(10)||'Script failed on line '||SIGL||'"' 'Doh!'
  234. end
  235.  
  236. return '<ERROR>'
  237.