Graphics routines

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
johnfin
Coder
Posts: 18
Joined: Tue Apr 01, 2008 8:26 am

Graphics routines

Post by johnfin »

Are there any methods for getting common graphics files(.bmp.gif.jpg) to display in qbasic programs.
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Sure are

Post by burger2227 »

Look for my BSAVER, BMPCOLOR, and BLOADANY zip programs here:

http://www.qbasicstation.com/index.php? ... &filecat=2

You may need a picture or photo editor capable of converting files to bitmap files and convert palette settings to 1, 4, 8, or 24 BPP. 4 for Screen 12 or 13 color and 8 for Screen 13 color only. A scanner program may work well enough.

Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
User avatar
Kiyotewolf
Veteran
Posts: 96
Joined: Tue Apr 01, 2008 11:38 pm

BMP source __ not my own

Post by Kiyotewolf »

This source came from one of the higher up coders, don't remember his name or web site.. tried to google it.. will find it and make amends later..

http://www.freewebs.com/kiyotewolf2/BMP.zip

I uploaded the bare bones file there.

That will let you manipulate the BMP pixel by pixel in BYTE, 8 bit precision of the RGB values.

What I had to code was a color matcher to take these raw 8 bit RGB colors and match them down to the local palette, or a palette derived from every possible combination of the EGA 16 colors, which suprisingly is a wide array of colors.

You use the standard PAL(255) of Hues .. etc.. to use as your palette, and then match the colors down to those. You of course have to have an existing palette, or rip the palette present in MCGA that exists naturally, or generate one from scratch. I have written code to derive a palette out of the EGA colors for VGA use and matching to dither colors on both MCGA and EGA the same, and if you want I'll email you the code.

Post a msg saying you want it emailed and I'll get back to you if so.
Banana phone! We need more lemon pledge. * exploding fist of iced tea! * I see your psycho cat and counter with a duck that has a broken leg, in a cast.
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

Sounds like a waste of time doing all of that. Especially when my routines make you look "smarter than a fourth grader". LOL

Screen 12 (4 BPP) is great for almost anything but photos.

Screen 13(8 BPP) is good for photographs, but reduce height to 83% in a BMP picture editor.

Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
johnfin
Coder
Posts: 18
Joined: Tue Apr 01, 2008 8:26 am

Graphics

Post by johnfin »

Ok, I have read the posts and I am really confused now. I have been playing around with the bsave and loadany and cant get them to work. I can see my file in the bsave , its 8bpp, but I cant load it and I cant get the load routine to run from the bsave zip. Is there an easy way to do this?
johnfin
Coder
Posts: 18
Joined: Tue Apr 01, 2008 8:26 am

easier way

Post by johnfin »

ok, I was thinking, maybe an easier way is for me to make a clean bitmap using paint, monochrome, instead of an existing picture. Would this be better.
TmEE
Veteran
Posts: 97
Joined: Mon Mar 17, 2008 11:14 am
Location: Estonia, Rapla
Contact:

Post by TmEE »

monocrome BMPs are 1bpp... there's quite some headache getting them display nicely. I have some code to load 8 and 4 bit BMPs. I'll see if I can find it.

Here it is, I wrote it before becoming an (ASM) optimization guru, so there's quite a bit of stupidity in the code

Code: Select all

SUB LOADBMP (BMPFILE$)
'Windows bitmap image loader. Supports 4-BIt and 8-BIT images.
'4-BIT image loading is 2.* times slower
'320x200x256 - 0.5 seconds    320x200x16  - 1.* seconds
OPEN BMPFILE$ FOR BINARY AS #1
BMPID$ = INPUT$(2, #1)                      ' BM
IF BMPID$ <> "BM" THEN
TPRINT "NOT BMP", 0, 24: SLEEP: FILELOADED% = 0: CLOSE #1: EXIT SUB
END IF
BMPS& = CVL(INPUT$(4, #1))                  ' filesize
'IF BMPS& <> LOF(1) THEN
'TPRINT "WIERD BMP1", 0, 24: SLEEP: FILELOADED% = 0: CLOSE #1: EXIT SUB
'END IF
nothing$ = INPUT$(4, #1)
IMGS& = CVL(INPUT$(4, #1))          ' 1078/118 image start
IF IMGS& = 1078 OR IMGS& = 118 THEN
ELSE
TPRINT "WIERD BMP2", 0, 24: SLEEP: FILELOADED% = 0: CLOSE #1: EXIT SUB
END IF
HD& = CVL(INPUT$(4, #1))         ' 40   header size
IF HD& <> 40 THEN
TPRINT "WIERD BMP3", 0, 24: SLEEP: FILELOADED% = 0: CLOSE #1: EXIT SUB
END IF
XLEN& = CVL(INPUT$(4, #1))          ' width
YLEN& = CVL(INPUT$(4, #1))         ' height
ONE% = CVI(INPUT$(2, #1))          ' 1
IF ONE% <> 1 THEN
TPRINT "WIERD BMP4", 0, 24: SLEEP: FILELOADED% = 0: CLOSE #1: EXIT SUB
END IF
COLORS% = CVI(INPUT$(2, #1))          ' 1/4/8/24 bpp
SELECT CASE COLORS%
CASE 1, 24
TPRINT "NOT SUPPORTED COLOR FORMAT", 0, 24: SLEEP: FILELOADED% = 0
CLOSE #1: EXIT SUB
END SELECT
CMRS& = CVL(INPUT$(4, #1))          ' 0 compression
IF CMRS& <> 0 THEN
TPRINT "COMPRESSED BMP", 0, 24: SLEEP: FILELOADED% = 0: CLOSE #1: EXIT SUB
END IF
CIS& = CVL(INPUT$(4, #1))         ' (compressed) image size
'PRINT CIS&, XLEN&, YLEN&
'IF CIS& <XLEN> 319 THEN
TPRINT "TOO WIDE BMP", 0, 24: SLEEP: FILELOADED% = 0: CLOSE #1: EXIT SUB
END IF
IF YLENGHT% > 191 THEN YLENGHT% = 191

'There's that funny thing about BMP format that I didn't know before.
'For example you have image with the width of 87, but in the file where
'image is stored there's 88 bytes and the last byte (88 - 87) has to be
'ignored for not messing up the image that gets loaded into PUT array.
'Amount of data in a single line must be a multiple of 4 !!!!!!
'here i'll find the number of bytes that have to be ignored.
'Unluckily it doesn't work with 4-BIT images
IF COLORS% = 8 THEN
'XLEN2& = XLEN& / 4
'XLEN2& = XLEN2& * 4
'DIF% = XLEN2& - XLEN&
XLEN2& = XLEN& AND &HFFFC
DIF% = (4 - (XLEN& - XLEN2&)) AND 3
END IF

IF COLORS% = 4 THEN
XLEN2& = XLEN& AND &HFFF8
DIF% = (8 - (XLEN& - XLEN2&)) AND 7
'XLEN2& = XLEN& / 16
'XLEN2& = (XLEN2& * 16)
'DIF% = XLEN2& - XLEN&
'IF XLEN& = 8 THEN DIF% = 0
'IF XLEN& = 7 THEN DIF% = 1
'IF XLEN& = 6 THEN DIF% = 2
'IF XLEN& = 5 THEN DIF% = 3
'IF XLEN& = 4 THEN DIF% = 4
'IF XLEN& = 3 THEN DIF% = 5
'IF XLEN& = 2 THEN DIF% = 6
'IF XLEN& = 1 THEN DIF% = 7
END IF

DEF SEG = VARSEG(IMAGE(0))
OFFSET& = VARPTR(IMAGE(0))
XLENGHT2% = XLEN& \ 32
XLENGHT1% = (XLEN& - (XLENGHT2% * 32)) * 8
POKE OFFSET& + 0, XLENGHT1%
POKE OFFSET& + 1, XLENGHT2%
POKE OFFSET& + 2, YLENGHT% + 1

IF COLORS% = 8 THEN
DEF SEG = VARSEG(IMAGE(0))
'OFFSET& = VARPTR(IMAGE(0))
OFFSET& = (XLEN& * YLEN&) + 4
FOR YYY% = 0 TO YLENGHT%
BYTES$ = INPUT$(XLEN& + DIF%, #1)
OFFSET& = OFFSET& - XLEN&
FOR XXX% = 0 TO XLENGHT%
DEF SEG = VARSEG(BYTES$)
OFFSET2& = SADD(BYTES$)
BYTE% = PEEK(OFFSET2& + XXX%)
DEF SEG = VARSEG(IMAGE(0))
POKE OFFSET&, BYTE%
'PSET (XXX% - 1, YYY% - 1), BYTE%
OFFSET& = OFFSET& + 1
NEXT XXX%
OFFSET& = OFFSET& - XLEN&
NEXT YYY%
END IF

IF COLORS% = 4 THEN
DEF SEG = VARSEG(IMAGE(0))
'OFFSET& = VARPTR(IMAGE(0))
OFFSET& = (XLEN& * YLEN&) + 4
FOR YYY% = 0 TO YLENGHT%
BYTES$ = INPUT$((XLEN& + DIF%) / 2, #1)
OFFSET& = OFFSET& - XLEN&
FOR XXX% = 0 TO XLENGHT% STEP 2
DEF SEG = VARSEG(BYTES$)
OFFSET2& = SADD(BYTES$)
BYTE% = PEEK(OFFSET2& + XXX% / 2)

BYTE1% = (BYTE% AND 240) / 16
BYTE2% = BYTE% AND 15

'PSET (XXX% - 1, YYY% - 1), BYTE1%       'everything gets drawn OK
'PSET (XXX% - 0, YYY% - 1), BYTE2%       'but in the array you'll find mess
DEF SEG = VARSEG(IMAGE(0))
POKE OFFSET& + 0, BYTE1%
POKE OFFSET& + 1, BYTE2%
OFFSET& = OFFSET& + 2
NEXT XXX%
OFFSET& = OFFSET& - XLEN&
NEXT YYY%
END IF
CLOSE #1
'PUT (0, 0), IMAGE(0), PSET
'PRINT XLEN&; XLEN2&; DIF%; YLEN&
'SETPALETTE2
'SLEEP
'END
END SUB
I hope its useful....
Mida sa loed ? Nagunii aru ei saa :P
johnfin
Coder
Posts: 18
Joined: Tue Apr 01, 2008 8:26 am

Graphics

Post by johnfin »

Thanks, I will give that code a try.
johnfin
Coder
Posts: 18
Joined: Tue Apr 01, 2008 8:26 am

Errors

Post by johnfin »

Too many syntax errors in that code. Is it Qbasic, ie Tprint? whats that, also 'end if' syntax errors. I am running v4.5 I believe.
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

The bitmap palette needs 4 BPP for Screen 12. That gives you 16 colors.
Photographs are poor, but cartoons or drawings look great.

For photos you need to save as 8 BPP and use Screen 13. Max size is 320 X 200 in 13 or 640 X 480 in 12.

BloadAny will BLOAD the file After it is created in the BSAVER or BMPColor programs. Bsaver saves the file with a BSV extension. BMPColor saves as a BCS file.

Color information is stored at the beginning of the files. Even if just normal settings.

What do you mean that you "think" it is QB45? Qbasic only has 2 files: the EXE and a help file. I think you are in over your head sonny.

Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
johnfin
Coder
Posts: 18
Joined: Tue Apr 01, 2008 8:26 am

versions

Post by johnfin »

There are MANY versions of qbasic, thats what I mean by version 4.5. I was not able to get a TPRINT command to work so I figured is must be in another version. It came up with a SYNTAX error. I was able to get a Bload'ed bsv file to come up but it is crude. Screen 12 and 13 have poor resolution. I would like very small line drawings (thumbnails) to display in my program.
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

What is TPRINT? Not QB

Post by burger2227 »

Then you need a good picture editing program. They can do the following:

1) Change any format of a picture as a bitmap (including ICOns)
2) Size the picture (may distort the image however)
3) Set the color palette referred to as BPP or bits per pixel.

The palette must be 1 (B&W screens 12 or 13), 4 (16 colors, screens 12 or 13), 8 (256 colors, 13 only), 24 (greyscale 12 or 13).

See if you can find some kind of scanner editor, Photoshop, or Paintshop Pro by Jasc.

Not all bitmaps will look great especially in 12, but photos are best in 13.
Screen 12 actually has the best resolution available in QB!

QB 4.5 rules!,

Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
Ralph
Veteran
Posts: 148
Joined: Fri Feb 09, 2007 3:10 pm
Location: Katy, Texas

Post by Ralph »

Ted:
The code posted by TMEE has some TPRINTs in it. The OP, Johnfin, was referring to that code when he commented on too many syntax errors, and what TPRINT was supposed to be.
Ralph, with QuickBASIC 4.5, operating under Windows XP, wiht anHP LaserJet 4L Printer. Bilingual in English/Spanish
TmEE
Veteran
Posts: 97
Joined: Mon Mar 17, 2008 11:14 am
Location: Estonia, Rapla
Contact:

Post by TmEE »

that TPRINT is my own PRINT routine for Screen13. Just replace it with just PRINT and remove the 2 numbers after the string.
Mida sa loed ? Nagunii aru ei saa :P
johnfin
Coder
Posts: 18
Joined: Tue Apr 01, 2008 8:26 am

Graphics

Post by johnfin »

1. That program listed above has numerous errors other then the tprint, ie 'end if' errors, Image(0) array not defined errors.

2. Is there a good shareware program that can take care of my bmp editing. I have been using photoline32, and while its powerful, its not easy to use.

3. Can I draw 1BPP monochrome line drawings in MSpaint that can be saved with bsave.
TmEE
Veteran
Posts: 97
Joined: Mon Mar 17, 2008 11:14 am
Location: Estonia, Rapla
Contact:

Post by TmEE »

I can't make things too easy for you... use your brains (and fingers) !!! I already said what to do with the TPRINTs, if no IMAGE array, CREATE one, just use DIM IMAGE(max_size_of_the_image_youre_gonna_load)...
Mida sa loed ? Nagunii aru ei saa :P
Post Reply