home *** CD-ROM | disk | FTP | other *** search
/ APDL Public Domain 1 / APDL_PD1A.iso / graphics / spritegen / ReduceSp (.txt) < prev   
Encoding:
RISC OS BBC BASIC V Source  |  1992-09-28  |  6.5 KB  |  245 lines

  1.   >ReduceSp
  2. 9Usage$ = "ReduceSp <In> <Out> [-Verbose <n>] [-Even]"
  3.      Read in a sprite file
  4.      For each sprite
  5.      Delete all unused rows to left, right, top bottom
  6.      If EVEN then ensure lop off same (min) from opposite sides
  7.  "OS_GetEnv" 
  8. getz(p%), "-load") 
  9. *  In$      = "<TestSprite$Dir>.CrossA"
  10. *  Out$     = "<TestSprite$Dir>.CrossC"
  11.   Verbose% = 2
  12. 9  Even%    = 
  13.        :
  14.   Take SAME off opposite edges
  15. 8  V$ = "basic,quit/s,/a,In/a,Out/a,Verbose/e,Even/S"
  16.  b% 512
  17.  "XOS_ReadArgs", V$, p%, b%, 512 
  18.  1, "Usage: "+ Usage$
  19.   In$      = 
  20. getz(b%!12)
  21.   Out$     = 
  22. getz(b%!16)
  23.   Verbose% = 
  24. geti(b%!20)
  25.   Even%    = 
  26. getb(b%!24)
  27. _Main
  28. _Main
  29.  "XHourglass_On"
  30.  "XHourglass_Off":
  31.  "OS_File", 17, In$ 
  32.  t%,,,,length%
  33.  t%<>1 
  34.  1, "Can't find file "+ In$
  35.  Sprites% length% + 4
  36.   !Sprites% = length% + 4
  37.  "OS_SpriteOp", &10A, Sprites%, In$
  38.   BufLen% = 16
  39.  Buf% BufLen%
  40.  n%= 1 
  41.  Sprites%!4
  42. ,9    
  43.  "XHourglass_Percentage", n%/(Sprites%!4+1)*100
  44. -;    
  45.  "OS_SpriteOp", &10D, Sprites%, Buf%, BufLen%, n%
  46. .:    
  47.  "OS_SpriteOp", &118, Sprites%, Buf%, n% 
  48.  ,, s%
  49. /9    
  50.  Verbose%>0 
  51. "Processing sprite "; 
  52. getz(Buf%)
  53. 0+    
  54. _Reduce_Sprite_Edges(Sprites%, s%)
  55.  Verbose%>0 
  56. "Saving..."
  57.  "OS_SpriteOp", &10C, Sprites%, Out$
  58.  Verbose%>0 
  59. "All done"
  60.  "XHourglass_Off"
  61. _Reduce_Sprite_Edges(area%, sprite%)
  62.  width%, height%, mode%, seigx%, seigy%, slog2bpp%
  63.  r_top%, r_bot%, r_left%, r_right%
  64.  Verbose%>0 
  65.  "OS_SpriteOp", &222, area%, sprite%, 512, 0, 8
  66.  "OS_SpriteOp", &228, area%, sprite% 
  67.  ,,,width%,height%,,mode%
  68.  "OS_ReadModeVariable", mode%, 4 
  69.  ,, seigx%
  70.  "OS_ReadModeVariable", mode%, 5 
  71.  ,, seigy%
  72.  "OS_ReadModeVariable", mode%, 9 
  73.  ,, slog2bpp%
  74.  Verbose%>2 
  75. _show_sprite(area%, sprite%, width%, height%)
  76. BF  r_top%    = 
  77. _Reduce_Sprite_Top(area%, sprite%, width%, height%)
  78. CI  r_bottom% = 
  79. _Reduce_Sprite_Bottom(area%, sprite%, width%, height%)
  80. DG  r_left%   = 
  81. _Reduce_Sprite_Left(area%, sprite%, width%, height%)
  82. EH  r_right%  = 
  83. _Reduce_Sprite_Right(area%, sprite%, width%, height%)
  84.  Even% 
  85. min(r_top%, r_bottom%)
  86. min(r_left%, r_right%)
  87. _Reduce_Sprite_Top(r_top%, area%, sprite%, width%, height%)
  88. _Reduce_Sprite_Bottom(r_bottom%, area%, sprite%, width%, height%)
  89. _Reduce_Sprite_Left(r_left%, area%, sprite%, width%, height%)
  90. _Reduce_Sprite_Right(r_right%, area%, sprite%, width%, height%)
  91.  Verbose%>2 
  92.  k = 
  93.  Verbose%>2 
  94. _show_sprite(area%, sprite%, width%, height%)
  95.  ---------------------------------------------------------------------
  96. _Reduce_Sprite_Top(area%, sprite%, width%, height%)
  97.  x%, y%, c%
  98.   y% = 0
  99.  x%= 0 
  100.  width% - 1
  101. YB      
  102.  "OS_SpriteOp", &229, area%, sprite%, x%, y% 
  103.  ,,,,,c%
  104.       
  105.  x%= width%
  106.  c%=0 
  107.       y% += 1
  108. ^        
  109.  y%=height% 
  110.  y%=height% 
  111.  1, "Sprite is empty"
  112.  Verbose%>1 
  113.  y%>0 
  114. "  Can take "; y%; " rows from top"
  115. _Reduce_Sprite_Top(y%, area%, sprite%, width%, 
  116.  height%)
  117.  Verbose%>0 
  118.  y%>0 
  119. "  Took "; y%; " rows from top"
  120.  y%>0
  121.     height% -= 1
  122. h1    
  123.  "OS_SpriteOp", &220, area%, sprite%, 0
  124.     y% -= 1
  125.  ---------------------------------------------------------------------
  126. _Reduce_Sprite_Bottom(area%, sprite%, width%, height%)
  127.  x%, y%, c%
  128.   y% = 0
  129.  x%= 0 
  130.  width% - 1
  131. tL      
  132.  "OS_SpriteOp", &229, area%, sprite%, x%, height%-y%-1 
  133.  ,,,,,c%
  134.       
  135.  x%= width%
  136.  c%=0 
  137.       y% += 1
  138. y        
  139.  height%=0 
  140.  height%=0 
  141.  1, "Sprite is empty"
  142.  Verbose%>1 
  143.  y%>0 
  144. "  Can take "; y%; " rows from bottom"
  145. _Reduce_Sprite_Bottom(y%, area%, sprite%, width%, 
  146.  height%)
  147.  Verbose%>0 
  148.  y%>0 
  149. "  Took "; y%; " rows from bottom"
  150.  y%>0
  151.     height% -= 1
  152. 7    
  153.  "OS_SpriteOp", &220, area%, sprite%, height%
  154.     y% -= 1
  155.  ---------------------------------------------------------------------
  156. _Reduce_Sprite_Left(area%, sprite%, width%, height%)
  157.  x%, y%, c%
  158.   x% = 0
  159.  y%= 0 
  160.  height% - 1
  161. B      
  162.  "OS_SpriteOp", &229, area%, sprite%, x%, y% 
  163.  ,,,,,c%
  164.       
  165.  y%= height%
  166.  c%=0 
  167.       x% += 1
  168.         
  169.  width%=x% 
  170.  x%=width% 
  171.  1, "Sprite is empty"
  172.  Verbose%>1 
  173.  x%>0 
  174. "  Can take "; x%; " columns from left"
  175. _Reduce_Sprite_Left(x%, area%, sprite%, 
  176.  width%, height%)
  177.  Verbose%>0 
  178.  x%>0 
  179. "  Took "; x%; " columns from left"
  180.  x%>0
  181.     width% -= 1
  182. 1    
  183.  "OS_SpriteOp", &22E, area%, sprite%, 0
  184.     x% -= 1
  185.  ---------------------------------------------------------------------
  186. _Reduce_Sprite_Right(area%, sprite%, width%, height%)
  187.  x%, y%, c%
  188.   x% = 0
  189.  y%= 0 
  190.  height% - 1
  191. K      
  192.  "OS_SpriteOp", &229, area%, sprite%, width%-x%-1, y% 
  193.  ,,,,,c%
  194.       
  195.  y%= height%
  196.  c%=0 
  197.       x% += 1
  198.         
  199.  width%=x% 
  200.  x%=width% 
  201.  1, "Sprite is empty"
  202.  Verbose%>1 
  203.  x%>0 
  204. "  Can take "; x%; " columns from right"
  205. _Reduce_Sprite_Right(x%, area%, sprite%, 
  206.  width%, height%)
  207.  Verbose%>0 
  208.  x%>0 
  209. "  Took "; x%; " columns from right"
  210.  x%>0
  211.       width% -= 1
  212. 8      
  213.  "OS_SpriteOp", &22E, area%, sprite%, width%
  214.       x% -= 1
  215.  ---------------------------------------------------------------------
  216.         Debugging routine
  217. :        Displays each pixel of a sprite as a hex digit
  218. _show_sprite(area%, sprite%, width%, height%)
  219.  x%, y%, c%
  220.  y%= 0 
  221.  height%-1
  222.  x%= 0 
  223.  width% - 1
  224. B      
  225.  "OS_SpriteOp", &229, area%, sprite%, x%, y% 
  226.  ,,,,,c%
  227.       
  228. h(c%); ",";
  229.         
  230.  ---------------------------------------------------------------------
  231. &        out: x% = y% = min(x%, y%)
  232.  x%, 
  233.  x%<y% 
  234.     y% = x%
  235.     x% = y%
  236. h(a%)
  237. "0"+ 
  238. ~(a%), 1)
  239. getb(b%)
  240. getz(b%)
  241. ?b%:V$+=
  242. (?b%):b%+=1:
  243. geti(b%)
  244.  b%=b%!1
  245.