The QBasic Forum      Other Subforums, Links and Downloads
  << Previous Topic | Next Topic >>Return to Index  

Utility to create 4/8-bit Windows bitmaps from QBasic

March 11 2003 at 9:31 PM
  (no login)

'****************************************************************
'
'----- BITMAP.BAS -----------------------------------------------
'
'----- Creates Windows bitmaps out of SCREEN 12/13 images -------
'------Windows bitmap file structure courtesy WOTSIT.ORG --------
'----- Freeware by Bob Seguin 2003 -- (TheBOB) ------------------
'
'****************************************************************

DECLARE SUB FourBIT (x1%, y1%, x2%, y2%, FileNAME$)
DECLARE SUB EightBIT (x1%, y1%, x2%, y2%, FileNAME$)

'Demonstrates CALL to sub programs (delete as you wish)
SCREEN 13
LINE (0, 0)-(319, 199), 13, BF
EightBIT 0, 0, 319, 199, "Purple8"

SCREEN 12
LINE (0, 0)-(639, 479), 13, BF
FourBIT 0, 0, 639, 479, "Purple4"

SYSTEM

SUB EightBIT (x1%, y1%, x2%, y2%, FileNAME$)
DIM FileCOLORS%(1 TO 768)
DIM Colors8%(255)

IF INSTR(FileNAME$, ".BMP") = 0 THEN
  FileNAME$ = RTRIM$(LEFT$(FileNAME$, 8)) + ".BMP"
END IF

FOR x = x1% TO x2%
  FOR y = y1% TO y2%
    Colors8%(POINT(x, y)) = 1
  NEXT y
NEXT x
FOR n = 0 TO 255
  IF Colors8%(n) = 1 THEN SigCOLORS& = SigCOLORS& + 1
NEXT n

FileTYPE$ = "BM"
Reserved1% = 0
Reserved2% = 0
OffsetBITS& = 1078
InfoHEADER& = 40
PictureWIDTH& = x2% - x1% + 1
PictureDEPTH& = y2% - y1% + 1
NumPLANES% = 1
BPP% = 8
Compression& = 0
WidthPELS& = 3780
DepthPELS& = 3780
NumCOLORS& = 256

IF PictureWIDTH& MOD 4 <> 0 THEN
ZeroPAD$ = SPACE$(4 - PictureWIDTH& MOD 4)
END IF

ImageSIZE& = (PictureWIDTH& + LEN(ZeroPAD$)) * PictureDEPTH&
FileSIZE& = ImageSIZE& + OffsetBITS&

Colr = 0
FOR n = 1 TO 768 STEP 3
  OUT &H3C7, Colr
  FileCOLORS%(n) = INP(&H3C9)
  FileCOLORS%(n + 1) = INP(&H3C9)
  FileCOLORS%(n + 2) = INP(&H3C9)
  Colr = Colr + 1
NEXT n

OPEN FileNAME$ FOR BINARY AS #1

PUT #1, , FileTYPE$
PUT #1, , FileSIZE&
PUT #1, , Reserved1% 'should be zero
PUT #1, , Reserved2% 'should be zero
PUT #1, , OffsetBITS&
PUT #1, , InfoHEADER&
PUT #1, , PictureWIDTH&
PUT #1, , PictureDEPTH&
PUT #1, , NumPLANES%
PUT #1, , BPP%
PUT #1, , Compression&
PUT #1, , ImageSIZE&
PUT #1, , WidthPELS&
PUT #1, , DepthPELS&
PUT #1, , NumCOLORS&
PUT #1, , SigCOLORS&

u$ = " "
FOR n% = 1 TO 768 STEP 3
  Colr$ = CHR$(FileCOLORS%(n% + 2) * 4)
  PUT #1, , Colr$
  Colr$ = CHR$(FileCOLORS%(n% + 1) * 4)
  PUT #1, , Colr$
  Colr$ = CHR$(FileCOLORS%(n%) * 4)
  PUT #1, , Colr$
  PUT #1, , u$ 'Unused byte
NEXT n%

FOR y = y2% TO y1% STEP -1
  FOR x = x1% TO x2%
    a$ = CHR$(POINT(x, y))
    PUT #1, , a$
  NEXT x
  PUT #1, , ZeroPAD$
NEXT y

CLOSE #1

END SUB

SUB FourBIT (x1%, y1%, x2%, y2%, FileNAME$)
DIM FileCOLORS%(1 TO 48)
DIM Colors4%(15)

IF INSTR(FileNAME$, ".BMP") = 0 THEN
  FileNAME$ = RTRIM$(LEFT$(FileNAME$, 8)) + ".BMP"
END IF

FOR x = x1% TO x2%
  FOR y = y1% TO y2%
    Colors4%(POINT(x, y)) = 1
  NEXT y
NEXT x
FOR n = 0 TO 15
  IF Colors4%(n) = 1 THEN SigCOLORS& = SigCOLORS& + 1
NEXT n

FileTYPE$ = "BM"
Reserved1% = 0
Reserved2% = 0
OffsetBITS& = 118
InfoHEADER& = 40
PictureWIDTH& = x2% - x1% + 1
PictureDEPTH& = y2% - y1% + 1
NumPLANES% = 1
BPP% = 4
Compression& = 0
WidthPELS& = 3780
DepthPELS& = 3780
NumCOLORS& = 16

IF PictureWIDTH& MOD 8 <> 0 THEN
  ZeroPAD$ = SPACE$((8 - PictureWIDTH& MOD 8) \ 2)
END IF

ImageSIZE& = (((ImageWIDTH& + LEN(ZeroPAD$)) * ImageDEPTH&) + .1) / 2
FileSIZE& = ImageSIZE& + OffsetBITS&

Colr = 0
FOR n = 1 TO 48 STEP 3
  OUT &H3C7, Colr
  FileCOLORS%(n) = INP(&H3C9)
  FileCOLORS%(n + 1) = INP(&H3C9)
  FileCOLORS%(n + 2) = INP(&H3C9)
  Colr = Colr + 1
NEXT n

OPEN FileNAME$ FOR BINARY AS #1

PUT #1, , FileTYPE$
PUT #1, , FileSIZE&
PUT #1, , Reserved1% 'should be zero
PUT #1, , Reserved2% 'should be zero
PUT #1, , OffsetBITS&
PUT #1, , InfoHEADER&
PUT #1, , PictureWIDTH&
PUT #1, , PictureDEPTH&
PUT #1, , NumPLANES%
PUT #1, , BPP%
PUT #1, , Compression&
PUT #1, , ImageSIZE&
PUT #1, , WidthPELS&
PUT #1, , DepthPELS&
PUT #1, , NumCOLORS&
PUT #1, , SigCOLORS&

u$ = " "
FOR n% = 1 TO 46 STEP 3
  Colr$ = CHR$(FileCOLORS%(n% + 2) * 4)
  PUT #1, , Colr$
  Colr$ = CHR$(FileCOLORS%(n% + 1) * 4)
  PUT #1, , Colr$
  Colr$ = CHR$(FileCOLORS%(n%) * 4)
  PUT #1, , Colr$
  PUT #1, , u$ 'Unused byte
NEXT n%

FOR y = y2% TO y1% STEP -1
  FOR x = x1% TO x2% STEP 2
    HiX = POINT(x, y)
    LoX = POINT(x + 1, y)
    HiNIBBLE$ = HEX$(HiX)
    LoNIBBLE$ = HEX$(LoX)
    HexVAL$ = "&H" + HiNIBBLE$ + LoNIBBLE$
    a$ = CHR$(VAL(HexVAL$))
    PUT #1, , a$
  NEXT x
  PUT #1, , ZeroPAD$
NEXT y

CLOSE #1

END SUB


    
This message has been edited by iorr5t on Mar 14, 2003 6:31 PM
This message has been edited by iorr5t on Mar 12, 2003 2:43 PM
This message has been edited by iorr5t on Mar 12, 2003 8:35 AM


 
 Respond to this message   
AuthorReply

(Login dpherron)

Thanks for the program.

April 21 2009, 5:19 PM 

Much thanks for compensating for my
own download inadequacies by supplying me
the code for creating 4/8-Bit Windows
Bitmaps. I hope to try it promptly!
Cordially yours,
David Herron
david98alej@aol.com

 
 Respond to this message   

(Login burger2227)

To save up to 8 seconds when using the FourBit SUB.....

April 21 2009, 9:19 PM 

eliminate the following code as Significant colors is not necessary:

FOR x = x1% TO x2%
FOR y = y1% TO y2%
Colors4%(POINT(x, y)) = 1
NEXT y
NEXT x
FOR n = 0 TO 15
IF Colors4%(n) = 1 THEN SigCOLORS& = SigCOLORS& + 1
NEXT n

POINT is slow for fullscreen bitmaps in SCREEN 12. It will just be set as zero like most bitmaps.

Ted

 
 Respond to this message   
Current Topic - Utility to create 4/8-bit Windows bitmaps from QBasic
  << Previous Topic | Next Topic >>Return to Index