#
# Sinclair QL (lowres 256x256 bitmap) exporter
# A Multipaint internal script
#
# Fail if less than 32000 or more than 32800
#

LOAD

# Error checking

A = LENGTH

IF A<32000
	ALERT 1
	STOP
ENDIF
IF A>32800
	ALERT 1
	STOP
ENDIF

# bitmap (flash ignored)

#  F E D C B A 9 8  7 6 5 4 3 2 1 0
# G3F3G2F2G1F1G0F0 R3B3R2B2R1B1R0B0

FOR Y=0 TO 255
	FOR X=0 TO 63
		READ H
		READ L		
		R=L&2
		R=R/2
		G=H&2
		G=G/2
		B=L&1
		P=B+(R*2)+(G*4)
		PUTPOINT X*4+3,Y,P
		R=L&8
		R=R/8
		G=H&8
		G=G/8
		B=L&4
		B=B/4
		P=B+(R*2)+(G*4)
		PUTPOINT X*4+2,Y,P
		R=L&32
		R=R/32
		G=H&32
		G=G/32
		B=L&16
		B=B/16
		P=B+(R*2)+(G*4)
		PUTPOINT X*4+1,Y,P
		R=L&128
		R=R/128
		G=H&128
		G=G/128
		B=L&64
		B=B/64
		P=B+(R*2)+(G*4)
		PUTPOINT X*4+0,Y,P			
	NEXT X
NEXT Y
