home *** CD-ROM | disk | FTP | other *** search
RISC OS BBC BASIC V Source | 1992-09-28 | 6.5 KB | 245 lines |
- >ReduceSp
- 9Usage$ = "ReduceSp <In> <Out> [-Verbose <n>] [-Even]"
- Read in a sprite file
- For each sprite
- Delete all unused rows to left, right, top bottom
- If EVEN then ensure lop off same (min) from opposite sides
- "OS_GetEnv"
- getz(p%), "-load")
- * In$ = "<TestSprite$Dir>.CrossA"
- * Out$ = "<TestSprite$Dir>.CrossC"
- Verbose% = 2
- 9 Even% =
- :
- Take SAME off opposite edges
- 8 V$ = "basic,quit/s,/a,In/a,Out/a,Verbose/e,Even/S"
- b% 512
- "XOS_ReadArgs", V$, p%, b%, 512
- 1, "Usage: "+ Usage$
- In$ =
- getz(b%!12)
- Out$ =
- getz(b%!16)
- Verbose% =
- geti(b%!20)
- Even% =
- getb(b%!24)
- _Main
- _Main
- "XHourglass_On"
- "XHourglass_Off":
- "OS_File", 17, In$
- t%,,,,length%
- t%<>1
- 1, "Can't find file "+ In$
- Sprites% length% + 4
- !Sprites% = length% + 4
- "OS_SpriteOp", &10A, Sprites%, In$
- BufLen% = 16
- Buf% BufLen%
- n%= 1
- Sprites%!4
- ,9
- "XHourglass_Percentage", n%/(Sprites%!4+1)*100
- -;
- "OS_SpriteOp", &10D, Sprites%, Buf%, BufLen%, n%
- .:
- "OS_SpriteOp", &118, Sprites%, Buf%, n%
- ,, s%
- /9
- Verbose%>0
- "Processing sprite ";
- getz(Buf%)
- 0+
- _Reduce_Sprite_Edges(Sprites%, s%)
- Verbose%>0
- "Saving..."
- "OS_SpriteOp", &10C, Sprites%, Out$
- Verbose%>0
- "All done"
- "XHourglass_Off"
- _Reduce_Sprite_Edges(area%, sprite%)
- width%, height%, mode%, seigx%, seigy%, slog2bpp%
- r_top%, r_bot%, r_left%, r_right%
- Verbose%>0
- "OS_SpriteOp", &222, area%, sprite%, 512, 0, 8
- "OS_SpriteOp", &228, area%, sprite%
- ,,,width%,height%,,mode%
- "OS_ReadModeVariable", mode%, 4
- ,, seigx%
- "OS_ReadModeVariable", mode%, 5
- ,, seigy%
- "OS_ReadModeVariable", mode%, 9
- ,, slog2bpp%
- Verbose%>2
- _show_sprite(area%, sprite%, width%, height%)
- BF r_top% =
- _Reduce_Sprite_Top(area%, sprite%, width%, height%)
- CI r_bottom% =
- _Reduce_Sprite_Bottom(area%, sprite%, width%, height%)
- DG r_left% =
- _Reduce_Sprite_Left(area%, sprite%, width%, height%)
- EH r_right% =
- _Reduce_Sprite_Right(area%, sprite%, width%, height%)
- Even%
- min(r_top%, r_bottom%)
- min(r_left%, r_right%)
- _Reduce_Sprite_Top(r_top%, area%, sprite%, width%, height%)
- _Reduce_Sprite_Bottom(r_bottom%, area%, sprite%, width%, height%)
- _Reduce_Sprite_Left(r_left%, area%, sprite%, width%, height%)
- _Reduce_Sprite_Right(r_right%, area%, sprite%, width%, height%)
- Verbose%>2
- k =
- Verbose%>2
- _show_sprite(area%, sprite%, width%, height%)
- ---------------------------------------------------------------------
- _Reduce_Sprite_Top(area%, sprite%, width%, height%)
- x%, y%, c%
- y% = 0
- x%= 0
- width% - 1
- YB
- "OS_SpriteOp", &229, area%, sprite%, x%, y%
- ,,,,,c%
-
- x%= width%
- c%=0
- y% += 1
- ^
- y%=height%
- y%=height%
- 1, "Sprite is empty"
- Verbose%>1
- y%>0
- " Can take "; y%; " rows from top"
- _Reduce_Sprite_Top(y%, area%, sprite%, width%,
- height%)
- Verbose%>0
- y%>0
- " Took "; y%; " rows from top"
- y%>0
- height% -= 1
- h1
- "OS_SpriteOp", &220, area%, sprite%, 0
- y% -= 1
- ---------------------------------------------------------------------
- _Reduce_Sprite_Bottom(area%, sprite%, width%, height%)
- x%, y%, c%
- y% = 0
- x%= 0
- width% - 1
- tL
- "OS_SpriteOp", &229, area%, sprite%, x%, height%-y%-1
- ,,,,,c%
-
- x%= width%
- c%=0
- y% += 1
- y
- height%=0
- height%=0
- 1, "Sprite is empty"
- Verbose%>1
- y%>0
- " Can take "; y%; " rows from bottom"
- _Reduce_Sprite_Bottom(y%, area%, sprite%, width%,
- height%)
- Verbose%>0
- y%>0
- " Took "; y%; " rows from bottom"
- y%>0
- height% -= 1
- 7
- "OS_SpriteOp", &220, area%, sprite%, height%
- y% -= 1
- ---------------------------------------------------------------------
- _Reduce_Sprite_Left(area%, sprite%, width%, height%)
- x%, y%, c%
- x% = 0
- y%= 0
- height% - 1
- B
- "OS_SpriteOp", &229, area%, sprite%, x%, y%
- ,,,,,c%
-
- y%= height%
- c%=0
- x% += 1
-
- width%=x%
- x%=width%
- 1, "Sprite is empty"
- Verbose%>1
- x%>0
- " Can take "; x%; " columns from left"
- _Reduce_Sprite_Left(x%, area%, sprite%,
- width%, height%)
- Verbose%>0
- x%>0
- " Took "; x%; " columns from left"
- x%>0
- width% -= 1
- 1
- "OS_SpriteOp", &22E, area%, sprite%, 0
- x% -= 1
- ---------------------------------------------------------------------
- _Reduce_Sprite_Right(area%, sprite%, width%, height%)
- x%, y%, c%
- x% = 0
- y%= 0
- height% - 1
- K
- "OS_SpriteOp", &229, area%, sprite%, width%-x%-1, y%
- ,,,,,c%
-
- y%= height%
- c%=0
- x% += 1
-
- width%=x%
- x%=width%
- 1, "Sprite is empty"
- Verbose%>1
- x%>0
- " Can take "; x%; " columns from right"
- _Reduce_Sprite_Right(x%, area%, sprite%,
- width%, height%)
- Verbose%>0
- x%>0
- " Took "; x%; " columns from right"
- x%>0
- width% -= 1
- 8
- "OS_SpriteOp", &22E, area%, sprite%, width%
- x% -= 1
- ---------------------------------------------------------------------
- Debugging routine
- : Displays each pixel of a sprite as a hex digit
- _show_sprite(area%, sprite%, width%, height%)
- x%, y%, c%
- y%= 0
- height%-1
- x%= 0
- width% - 1
- B
- "OS_SpriteOp", &229, area%, sprite%, x%, y%
- ,,,,,c%
-
- h(c%); ",";
-
- ---------------------------------------------------------------------
- & out: x% = y% = min(x%, y%)
- x%,
- x%<y%
- y% = x%
- x% = y%
- h(a%)
- "0"+
- ~(a%), 1)
- getb(b%)
- getz(b%)
- ?b%:V$+=
- (?b%):b%+=1:
- geti(b%)
- b%=b%!1
-