[comp.sys.acorn] 8-bit: Mono Sun Raster File viewer

ian@ob1.uws.EDU.AU (Ian Walsh) (02/07/91)

	Here is a little BBC BASIC 2 program that will display
monochrome Sun Raster files on your Beeb.
	Give your Sun Raster files a prefix of 'R.'. When asked
to enter the filename leave out the 'R.' prefix. Choose which
graphics mode you wish to display the file in, and wait!
	If you want to save the image in BBC format uncomment line
130. The picture will be saved with an 'S.' prefix (you could
replace 'SAVE' with 'SVPIC' if you've got it).

NOTE: I haven't fully tested the program! I've only tried 'encoded'
      Sun Raster files not 'standard' Raster files. And, I've only
      ever used files with widths exactly divisible by 8 (the docs
      say that the width is always rounded up to 16 bits - but
      every file I've tried is padded up to the next byte (8 bits)).
      If you have any problems PLEASE email me.

 10 REM Sun Raster File Viewer for BBC, by Andrew Leahy 1/2/91
 20 REM email: a.leahy@nepean.uws.edu.au
 30 ONERRORVDU4:CLOSE#0:REPORT:PRINT" at ";ERL:END
 40 INPUT"Enter Sun Raster File to view : R."C$
 50 C%=OPENIN("R."+C$):IF C%=0 PROCerr("No Such File!")
 60 PROCgetinfo
 70 REPEATINPUT'"Which mode (01245) : "md%:UNTILmd%<6
 80 MODEmd%:md%=md%MOD3+1:M%=2^md%:VDU19,0,7;0;19,7,0;0;5:REM Setup screen
 90 X%=0:Y%=0:XS%=640-W%*M%/2:YS%=512+H%*2:VDU29,XS%;YS%;:REM Centre image
100 W%=(W%DIV8*8+8)*M%:BW%=8*M%:REM determine 'real' width
110 IF type=2 PROCencoded ELSE PROCstandard
120 VDU4:CLOSE#0
130 REMOSCLI("SAVE S."+C$+" 3000 8000")
140 END
150 DEFPROCstandard:REPEATB%=BGET#C%:PROCa:UNTILY%=H%:ENDPROC
160 DEFPROCencoded:REPEATB%=BGET#C%
170 IFB%<>&80 PROCa ELSEN%=BGET#C%:IFN% B%=BGET#C%:FORI%=0TON%:PROCa:NEXT ELSEB%=&80:PROCa
180 UNTILY%=H%:ENDPROC
190 DEFPROCa:IFB% MOVEX%,0:VDU23,128,B%;0;0;0;128
200 X%=X%+BW%:IFX%>W% X%=0:Y%=Y%+1:VDU29,XS%;YS%-Y%*4;
210 ENDPROC
220 DEFPROCgetinfo
230 magic=&59A66A95:IF FNgetlong<>magic PROCerr("Not a Sun Raster File!")
240 W%=FNgetlong:H%=FNgetlong
250 depth=FNgetlong:IF depth<>1 PROCerr("Not a B&W image!")
260 length=FNgetlong:REM not used
270 type=FNgetlong:IF type>2 PROCerr("Don't know this image type!")
280 maptype=FNgetlong:maplength=FNgetlong:REM not used
290 PRINT'"File info: ";W%"x"H%;", Mono, ";
300 IF type=2 PRINT"Byte encoded." ELSE PRINT"Standard."
310 ENDPROC
320 DEFFNgetlong:=BGET#C%*16777216+BGET#C%*65536+BGET#C%*256+BGET#C%
330 DEFPROCerr(A$):PRINT'A$:CLOSE#0:END

	For a source of Sun Raster files, look for sites which hold
the Jef Poskanzer bitmap collection. Only trouble is that most of these
files have a resolution greater than 640x256! If you have PBMPLUS you
can create your own Sun Rasters from GIF/IFF/PCX/MAC/... files.
 
				Andrew Leahy
			email: a.leahy@nepean.uws.edu.au