home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / GFX / Converter / IMAFX26.lha / imagefx2 / rexx / Snapshot.ifx < prev    next >
Encoding:
Text File  |  1994-08-22  |  10.7 KB  |  383 lines

  1. /*
  2.  * $VER: Snapshot 2.0.0 (19.8.94)
  3.  *
  4.  * Arexx program for the ImageFX image processing system.
  5.  * Written by Thomas Krehbiel (from an idea by Bob Fisher)
  6.  *
  7.  * Take a directory of images, and reduce them to small thumbnail
  8.  * snapshot images, and place them on one or more images which are
  9.  * then saved out somewhere.  This script also renders the snapshot
  10.  * pages down to 16 color images for easy viewing.  We can also
  11.  * optionally stamp the name of the file at the bottom of each
  12.  * thumbnail.
  13.  *
  14.  * By default we make 640x400 24-bit renderings with a 5x5 grid
  15.  * of thumbnails.
  16.  *
  17.  */
  18.  
  19. OPTIONS RESULTS
  20.  
  21. SIGNAL ON BREAK_C
  22.  
  23. GetMain
  24. IF rc = 0 THEN DO
  25.    RequestResponse 'The current buffer will be destroyed.'
  26.    IF rc ~= 0 THEN EXIT
  27.    END
  28.  
  29. KillBuffer Force
  30.  
  31. /* retreive defaults from any previous useage of this macro */
  32. defsdir  = GETCLIP('IFX_Snapshot_DefSource')
  33. defspat  = GETCLIP('IFX_Snapshot_DefSrcPat')
  34. defdest  = GETCLIP('IFX_Snapshot_DefDest')
  35. numcols  = GETCLIP('IFX_Snapshot_Colors')
  36. gridsize = GETCLIP('IFX_Snapshot_Grid')
  37. width    = GETCLIP('IFX_Snapshot_Width')
  38. height   = GETCLIP('IFX_Snapshot_Height')
  39. labelit  = GETCLIP('IFX_Snapshot_Labels')
  40. grey     = GETCLIP('IFX_Snapshot_Grey')
  41. keepext  = GETCLIP('IFX_Snapshot_KeepExt')
  42. saveform = GETCLIP('IFX_Snapshot_SaveForm')
  43. saveopt  = GETCLIP('IFX_Snapshot_SaveOpts')
  44. spacing  = GETCLIP('IFX_Snapshot_Spacing')
  45. enhance  = GETCLIP('IFX_Snapshot_Enhance')
  46. doback   = GETCLIP('IFX_Snapshot_DoBack')
  47. backdrop = GETCLIP('IFX_Snapshot_Backdrop')
  48. doshadow = GETCLIP('IFX_Snapshot_DoShadow')
  49. red      = GETCLIP('IFX_Snapshot_Red')
  50. green    = GETCLIP('IFX_Snapshot_Green')
  51. blue     = GETCLIP('IFX_Snapshot_Blue')
  52.  
  53. /* some defaults - change as desired */
  54.  
  55. IF defsdir  = '' THEN defsdir  = ""          /* default source dir */
  56. IF defspat  = '' THEN defspat  = "#?"        /* default source pattern */
  57. IF defdest  = '' THEN defdest  = "RAM:.Snap" /* default dest files */
  58. IF numcols  = '' THEN numcols  = 8           /* colors in renderings */
  59. IF gridsize = '' THEN gridsize = 5           /* thumbnail rows/cols */
  60. IF width    = '' THEN width    = 640         /* dest width */
  61. IF height   = '' THEN height   = 400         /* dest height */
  62. IF labelit  = '' THEN labelit  = 1           /* label each thumbnail? */
  63. IF grey     = '' THEN grey     = 0           /* convert to greyscale? */
  64. IF keepext  = '' THEN keepext  = 1           /* keep file extensions? */
  65. IF saveform = '' THEN saveform = 'ILBM'      /* save format */
  66. IF spacing  = '' THEN spacing  = 10          /* spacing between nails */
  67. IF enhance  = '' THEN enhance  = 1           /* enhance nails? */
  68. IF doback   = '' THEN doback   = 0           /* do backdrop texture? */
  69. IF backdrop = '' THEN backdrop = 'Textures/Leather'   /* backdrop texture */
  70. IF doshadow = '' THEN doshadow = 1           /* do shadowed nails? */
  71. IF red      = '' THEN red      = 128
  72. IF green    = '' THEN green    = 100
  73. IF blue     = '' THEN blue     = 140
  74.  
  75. RequestFile '"Source Directory:"' '"'defsdir'"' '" "' '"'defspat'"'
  76. IF rc ~= 0 THEN EXIT    /* cancelled */
  77. sourcedir = filereq.path
  78. sourcepat = filereq.pat
  79.  
  80. /* get a directory and pattern and grid size */
  81.  
  82. Gadget.1  = 'I/190/19/Rows & Columns:/'gridsize
  83. Gadget.2  = 'I/190/34/Spacing:/'spacing
  84.  
  85. Gadget.3  = 'I/190/50/Width (Pixels):/'width
  86. Gadget.4  = 'I/190/65/Height (Pixels):/'height
  87. Gadget.5  = 'T/190/80/60/0/Save Format:/'saveform
  88. Gadget.6  = 'T/190/95/60/0/Save Options:/'saveopt
  89. Gadget.7  = 'D/162/110/100/Colors:/9/2/4/8/16/32/64/128/254/24-Bit/'numcols
  90. Gadget.8  = 'T/110/125/140/1/Basename:/'defdest
  91.  
  92. Gadget.9  = 'X/300/20/Convert To Greyscale?/'grey
  93. Gadget.10 = 'X/300/34/Label Thumbnails?/'labelit
  94. Gadget.11 = 'X/300/46/Keep Extensions?/'keepext
  95. Gadget.12 = 'X/300/60/Enhance Thumbnails?/'enhance
  96. Gadget.13 = 'X/300/72/Create Shadows?/'doshadow
  97. Gadget.14 = 'X/300/86/Create Backdrop?/'doback
  98.  
  99. Gadget.15 = 'T/300/98/180/0/ /'backdrop
  100.  
  101. Gadget.16 = 'J/300/125/35/R:/'red
  102. Gadget.17 = 'J/370/125/35/G:/'green
  103. Gadget.18 = 'J/440/125/35/B:/'blue
  104.  
  105. ComplexRequest '"Snapshot V2.0 Options:"' 18 Gadget 520 165
  106. IF rc ~= 0 THEN EXIT
  107.  
  108. gridsize = result.1
  109. spacing  = result.2
  110. width    = result.3
  111. height   = result.4
  112. saveform = result.5
  113. saveopt  = result.6
  114. numcols  = result.7
  115. destbase = result.8
  116. grey     = result.9
  117. labelit  = result.10
  118. keepext  = result.11
  119. enhance  = result.12
  120. doshadow = result.13
  121. doback   = result.14
  122. backdrop = result.15
  123. red      = result.16
  124. green    = result.17
  125. blue     = result.18
  126.  
  127. CALL SETCLIP('IFX_Snapshot_DefSource', sourcedir)
  128. CALL SETCLIP('IFX_Snapshot_DefSrcPat', sourcepat)
  129. CALL SETCLIP('IFX_Snapshot_DefDest', destbase)
  130. CALL SETCLIP('IFX_Snapshot_Colors', numcols)
  131. CALL SETCLIP('IFX_Snapshot_Grid', gridsize)
  132. CALL SETCLIP('IFX_Snapshot_Width', width)
  133. CALL SETCLIP('IFX_Snapshot_Height', height)
  134. CALL SETCLIP('IFX_Snapshot_Labels', labelit)
  135. CALL SETCLIP('IFX_Snapshot_Grey', grey)
  136. CALL SETCLIP('IFX_Snapshot_KeepExt', keepext)
  137. CALL SETCLIP('IFX_Snapshot_SaveForm', saveform)
  138. CALL SETCLIP('IFX_Snapshot_SaveOpts', saveopt)
  139. CALL SETCLIP('IFX_Snapshot_Spacing', spacing)
  140. CALL SETCLIP('IFX_Snapshot_Enhance', enhance)
  141. CALL SETCLIP('IFX_Snapshot_DoBack', doback)
  142. CALL SETCLIP('IFX_Snapshot_Backdrop', backdrop)
  143. CALL SETCLIP('IFX_Snapshot_DoShadow', doshadow)
  144. CALL SETCLIP('IFX_Snapshot_Red', red)
  145. CALL SETCLIP('IFX_Snapshot_Green', green)
  146. CALL SETCLIP('IFX_Snapshot_Blue', blue)
  147.  
  148.  
  149. SELECT
  150.    WHEN numcols = 0 THEN numcols = 2
  151.    WHEN numcols = 1 THEN numcols = 4
  152.    WHEN numcols = 2 THEN numcols = 8
  153.    WHEN numcols = 3 THEN numcols = 16
  154.    WHEN numcols = 4 THEN numcols = 32
  155.    WHEN numcols = 5 THEN numcols = 64
  156.    WHEN numcols = 6 THEN numcols = 128
  157.    WHEN numcols = 7 THEN numcols = 256
  158.    WHEN numcols = 8 THEN numcols = 'DEEP'
  159.    OTHERWISE EXIT 0
  160.    END
  161.  
  162.  
  163. thumbxspace = (width / gridsize)
  164. thumbyspace = ((height-20) / gridsize)
  165.  
  166. thumbwidth = thumbxspace - spacing
  167. thumbheight = thumbyspace - spacing
  168.  
  169. picnum = 1
  170.  
  171.  
  172. DO FOREVER
  173.  
  174.    /* build list of files to process */
  175.  
  176.    ECHO 'List >RAM:__Snap_TEMP__ NOHEAD LFORMAT='sourcedir'/%s' sourcedir 'PAT' sourcepat
  177.    ADDRESS COMMAND 'List >RAM:__Snap_TEMP__ NOHEAD LFORMAT='sourcedir'/%s' sourcedir 'PAT' sourcepat
  178.    IF rc ~= 0 THEN DO
  179.       RequestNotify 'Problem scanning the source directory.'
  180.       EXIT
  181.       END
  182.  
  183.    /* sort alphabetically */
  184.    ADDRESS COMMAND 'Sort RAM:__Snap_TEMP__ TO RAM:__Snap_LIST__'
  185.    ADDRESS COMMAND 'Delete RAM:__Snap_TEMP__ QUIET'
  186.  
  187.    /* okay, process the files */
  188.  
  189.    IF ~OPEN(infile, 'RAM:__Snap_LIST__', 'Read') THEN DO
  190.       RequestNotify 'Problem reading sorted file list - no files found?'
  191.       EXIT
  192.       END
  193.  
  194.    IF numcols ~= 'DEEP' THEN DO
  195.       SetRender 'Amiga'
  196.       Render Mode HIRES LACE
  197.       Render Colors numcols
  198.       Render Dither 1 2 0     /* floyd zigzag none */
  199.       END
  200.  
  201.    Requesters Off    /* disable error requesters */
  202.    Redraw Off
  203.    Undo Off
  204.  
  205.    Blend 100
  206.    EdgeMode Normal
  207.    Transparency Include 0 Exclude 0
  208.  
  209.    /* force new buffer the first time: */
  210.    x = 999
  211.    y = 999
  212.    pagenum = 0
  213.  
  214.    DO WHILE ~EOF(infile)
  215.  
  216.       x = x + 1
  217.       IF x >= gridsize THEN DO
  218.          x = 0
  219.          y = y + 1
  220.          IF y >= gridsize THEN DO
  221.  
  222.             GetMain
  223.             IF rc = 0 THEN DO
  224.                IF numcols ~= 'DEEP' THEN DO
  225.                   Render Go
  226.                   SaveRenderedAs saveform destbase||RIGHT('000'||picnum,3) saveopt
  227.                   Render Close
  228.                   END
  229.                ELSE DO
  230.                   SaveBufferAs saveform destbase||RIGHT('000'||picnum,3) saveopt
  231.                   END
  232.                END
  233.  
  234.             pagenum = pagenum + 1
  235.             picnum = picnum + 1
  236.  
  237.             IF grey THEN CreateBuffer width height 'GREY' red green blue FORCE
  238.             ELSE         CreateBuffer width height red green blue FORCE
  239.  
  240.             IF doback THEN DO
  241.                Hook ApplyTexture backdrop 0 80 Shiny
  242.                END
  243.  
  244.             title = sourcedir||' ('||pagenum||')'
  245.  
  246.             ActiveColor 0     /* usually black */
  247.             Text 'topaz.font' 11 100 BOLD title
  248.             Blend 50
  249.             Point width%2+2 9
  250.             Blend 100
  251.             KillBrush
  252.  
  253.             ActiveColor 1     /* usually white */
  254.             Text 'topaz.font' 11 100 BOLD title
  255.             Point width%2 7
  256.             KillBrush
  257.  
  258.             Redraw
  259.             y = 0
  260.  
  261.             END
  262.          END
  263.  
  264.       nextfile = READLN(infile)
  265.       IF nextfile = "" THEN ITERATE
  266.       Message nextfile
  267.  
  268.       xp = x*thumbxspace
  269.       yp = y*thumbyspace+20
  270.  
  271.       LoadBrush nextfile 1       /* 1 in case we find an anim */
  272.  
  273.       IF rc = 0 THEN DO
  274.  
  275.          GetBrush
  276.          PARSE VAR result name w h d ax ay .
  277.  
  278.          IF grey THEN DO
  279.             IF (d > 1) THEN Color2Grey Luma
  280.             END
  281.  
  282.          IF (ax > 0) THEN h = h * ay % ax
  283.  
  284.          IF (w > h) THEN DO
  285.             nw = thumbwidth
  286.             nh = h * nw % w
  287.             IF (nh > thumbheight) THEN nh = thumbheight
  288.             END
  289.          ELSE DO
  290.             nh = thumbheight
  291.             nw = w * nh % h
  292.             IF (nw > thumbwidth) THEN nw = thumbwidth
  293.             END
  294.  
  295.          IF (w < thumbwidth) & (h < thumbheight) THEN
  296.             Scale nw nh FAST
  297.          ELSE
  298.             Scale nw nh
  299.  
  300.          /* a little enhancement - makes 'em stand out more */
  301.          IF enhance THEN DO
  302.             Contrast 10
  303.             UnsharpMask 8
  304.             END
  305.  
  306.          IF doshadow THEN DO
  307.             DrawMode Darken
  308.             EdgeMode FeatherIn 4
  309.             Point xp+thumbxspace%2+4 yp+thumbyspace%2+4
  310.             DrawMode Normal
  311.             EdgeMode Normal
  312.             END
  313.  
  314.          Point xp+thumbxspace%2 yp+thumbyspace%2
  315.          KillBrush
  316.  
  317.          END
  318.  
  319.       IF labelit THEN DO
  320.  
  321.          /* strip path and optionally the trailing extension */
  322.          n = LASTPOS('/', nextfile) + 1
  323.          label = SUBSTR(nextfile,n)
  324.          IF ~keepext THEN DO
  325.             n = 1
  326.             DO WHILE n > 0
  327.                n = LASTPOS('.', label)
  328.                IF (n > 0) THEN label = LEFT(label,n-1)
  329.                END
  330.             END
  331.  
  332.          ActiveColor 0     /* usually black */
  333.          Text 'topaz.font' 8 100 label
  334.          Blend 50
  335.          Point xp+thumbxspace%2+1 yp+thumbheight-6
  336.          Blend 100
  337.          KillBrush
  338.  
  339.          ActiveColor 1     /* usually white */
  340.          Text 'topaz.font' 8 100 label
  341.          Point xp+thumbxspace%2 yp+thumbheight-7
  342.          KillBrush
  343.  
  344.          END
  345.  
  346.       Redraw xp yp thumbxspace thumbyspace
  347.  
  348.       END
  349.  
  350.    IF (x > 0) | (y > 0) THEN DO
  351.       IF numcols ~= 'DEEP' THEN DO
  352.          Render Go
  353.          SaveRenderedAs saveform destbase||RIGHT('000'||picnum,3) saveopt
  354.          Render Close
  355.          END
  356.       ELSE DO
  357.          SaveBufferAs saveform destbase||RIGHT('000'||picnum,3) saveopt
  358.          END
  359.       END
  360.  
  361.    RequestResponse 'Please insert next volume.'
  362.    IF rc ~= 0 THEN LEAVE
  363.  
  364.    CALL CLOSE(infile)
  365.  
  366.    KillBuffer Force
  367.  
  368.    END
  369.  
  370. BREAK_C:
  371.  
  372. CALL CLOSE(infile)
  373.  
  374. ADDRESS COMMAND 'Delete RAM:__Snap_LIST__ QUIET'
  375.  
  376. KillBrush
  377. Undo On
  378. Redraw On
  379. Requesters On
  380.  
  381. EXIT
  382.  
  383.