WIN BMP TO BVLOAD CONVERTER

All aspects of programming on the Commander X16.
User avatar
ahenry3068
Posts: 1084
Joined: Tue Apr 04, 2023 9:57 pm

WIN BMP TO BVLOAD CONVERTER

Post by ahenry3068 »

THIS IS SOME QUICK AND DIRTY CODE.. BUT I THINK ITS USEFUL.


This is some useful files to use the CODE ON
BMPS.zip
(89.18 KiB) Downloaded 150 times
added some more that work too.
MOREBMPS.zip
(903.81 KiB) Downloaded 131 times
Last edited by ahenry3068 on Sat Sep 09, 2023 10:35 pm, edited 5 times in total.
User avatar
ahenry3068
Posts: 1084
Joined: Tue Apr 04, 2023 9:57 pm

BMP TO BVLOAD CONVERTOR ...DONE

Post by ahenry3068 »

Ok........... Seems to be working now in all Valid cases. Takes about 2 minutes to do the file conversion

But....... Do your Image in any current Paint Program. Save as Windows/OS2 BMP, 8 bit (or 256 colors). RGB encoded.
Don't use RLE encoding. This program is not super robust and currently does no Error Checking.
Must be 320x240 resolution


RENAME Your file to IN.BMP. Put it in the Directory where you will be running this code.

It takes about 2 mins to complete, but when completed you will have a VPAL.BIN and IMG.BIN that can be BVLOADED with BASIC or just copied to VRAM with C or ASM

I'm inclined to make this a bit more ROBUST and Scale or Pad other Resolutions as Necessary. But right now it doesn't do that. I'm thinking this opens up a lot of design tools to make screens for X16 programs.


I'm using Paint Shop Pro 3.11 which is kind of an old program. But one I have some Nostalgia for. I'm running it under Win XP


The current code ASSUMES 320x240x8 BMP file RGB Encoded and does no error checking. The Output files should be BVLOADED under Screen 128 ($80)

EDIT: I was using Paint Shop Pro on my XP system to do the saves. Some of the more modern paint programs no longer give you the option to save 8 bit BMP's :(

I haven't used ImageMagick so much, but I have used it here and there.

THIS command in Linux will create a BMP that can be converted

convert INPUTFILE.EXT -compress none -resize 320x240! -flip -depth 8 -type palette BMP3:IN.BMP

NEW EDIT.
When using Paint Shop Pro to resize aspect ration is not preserved. The Image is full screen always. When using ImageMagick the aspect ratio is preserved. The files work but you end up with a border at the bottom.......... Either way works. I'm putting some of both results into my Slideshow.

ANOTHER EDIT 9 SEP

Discovered another caveat to ImageMagick preserving the aspect ratio. It will make the image narrower than 320... :( :( These images DO NOT process properly with my Current code. I'm trying to figure out how to make ImageMagick ignore Aspect Ratio so this doesn't happen. I'm sure theres a command line switch somewhere. But ImageMagick is a very complicated program. It amazes me how thorough it actually is. If anyone has a tip for me here I would welcome it.

NEW EDIT
Dug a little deeper in the ImageMagick docs. Putting the ! after the resize forces the aspect ration to be ignored. -resize 320x240! will resize to 320x240 in all cases. This may or may not cause significant distortion depending on original aspect ratio.


( I could also actually pay attention to the DIB header in my code and make it more robust )





It should work on any Input file that ImageMagick supports. Of course don't expect miracles. If you bring
in a 3096 x 1560 jpg. The output will work but it will lose some quality


BVLOAD "IMG.BIN",8,0,0
BVLOAD "VPAL.BIN",8,1,$FA00

Enjoy.

THE CODE

Code: Select all

05 T1=TI
06 CLS:PRINT:PRINT
10 OPEN 5,8,2,"@:VPAL.BIN,S,W"
20 OPEN 6,8,4,"IN.BMP,S,R"
30 SCREEN 1:CLS


100 FOR X = 1 TO 54
110     GET #6,X$
120 NEXT X
125 LOCATE 2,2:PRINT "GENERATING PALLETTE"
130 FOR X = 1 TO 256
135     LOCATE 3,3:PRINT "ENTRY ";X-1;
136     LOCATE 4,3:PRINT "STAT: ";ST
140     GET#6,B$
150     GET#6,G$
160     GET#6,R$
170     GET#6,X$
180     R%=ASC(R$)/16
190     G%=ASC(G$)/16
200     B%=ASC(B$)/16
210     GB%=(G%*16)+B%
220     PRINT#5,CHR$(GB%);
230     PRINT#5,CHR$(R%);
240 NEXT X

250 CLOSE 5:LOCATE 2,2:PRINT "PALLETTE COMPLETE      ";

260 OPEN 5,8,3,"@:IMG.BIN,S,W"


270 FOR Y=1 TO 240
275     LOCATE 3,2:PRINT "WORKING ROW:";Y
276     PRINT "STATUS: ";ST
280     FOR X=1 TO 320
300        GET#6,X$
310        PRINT#5,CHR$(ASC(X$));
320     NEXT X
330 NEXT Y

340 CLOSE 5
341 CLOSE 6
345 T2=TI
346 PRINT:PRINT:PRINT "START : ";T1
347 PRINT "END   : ";T2

348 GOSUB 500

350 SCREEN $80
360 BVLOAD "IMG.BIN",8,0,0
370 BVLOAD "VPAL.BIN",8,1,$FA00
375 GOSUB 500

395 GOSUB 45000
396 GOSUB 500
400 SCREEN 0
410 END



500 GET X$:IF X$<>"" THEN 500
510 GET X$:IF X$="" THEN 510
520 RETURN


REM SET OF GOSUBS FOR DIRECT VERA PALLETTE MANIPULATION
REM USES VPOKE & VPEEK
REM FOR THE OTHER ROUTINES TO WORK RELIABLY SHOULD GOSUB 45000
REM FIRST.    ALSO GOSUB 45000 IS USED AT ANY TIME TO RESET
REM THE VERA PALLETTE TO DEFAULT VALUES.
REM ..
REM ...
REM WHEN THE VERA IS INITIALLY SET TO GRAPHICS MODE IT USES THE
REM DEFAULT PALLETTE BUT IF YOU USE VPEEK TO READ IT RETURNS
REM RANDOM GARBAGE...    AFTER YOU VPOKE THEM IT ALL WORKS
REM AS EXPECTED.
REM .
REM ..
REM ...
REM THIS CODE DOES ABSOLUTELY NO ERROR CHECKING !!!!!!
REM IF USING R%,G% OR B% VALUES SHOULD ALWAYS BE BETWEEN
REM 0-15
REM .
REM ..
REM ...
REM WHEN USING P1 AND P2 TO POINT AT PALLETTE ENTRYS THEY SHOULD
REM ALWAYS BE BETWEEN 0 AND 255
REM I HAD ERROR CHECKING CODE WHEN WRITING THESE ROUTINES
REM BUT ERROR CHECKING TAKES CPU CYCLES....   JUST KEEP THE VALUES
REM CORRECT BEFORE CALLING.
REM .
REM ..
REM ...
REM ..
REM GOSUB 45000..   POKES IN THE DEFAULT PALLETTE VALUES
REM                 SHOULD BE CALLED AT INIT.   AND THEN ANY TIME
REM                 TO RESET THE VERA TO DEFAULT VALUES
REM ..
REM GOSUB 40000..   SETS PALLETTE ENTRY P1 TO R%,G%,B%
REM ..
REM GOSUB 40100..   READS VALUES AT P1 RETURNS IN R%,G%,B%
REM ..
REM GOSUB 40200..   CHANGES THE PALLETTE COLOR P2 TO P1. BUT DIFFERENT THAN 41000
REM                 41000 CHANGES IT FAST.   40200 IMPLEMENTS A FADE WITH SPEED
REM                 CONTROLLED BY THE VALUE OF J (BIGGER VALUE=SLOWER)
REM                 ACTUALLY MOST OF THE WORK DONE BY GOSUB TO 40300
REM ..
REM GOSUB 40300     FADES PALLETTE COLOR AT P1 TO R%,G%,B%
REM                 SPEED CONTROLLED BY THE VALUE OF J.    1 TO 10
REM                 IS SO FAR BEST FOR ME BUT I DIDN'T RESTRICT VALUES
REM                 THE BIGGER J IS.. THE SLOWER THE FADE.
REM ..
REM GOSUB 40500..   SWAPS THE PALLETTE VALUES BETWEEN P1 AND P2
REM                 IF AND ITS A BIG IF...  I MAKE FURTHER CHANGES
REM                 THE NEXT ROUTINE I MAKE WILL BE TO DO THIS AS A
REM                 ..FADE.. USING A SIMILIAR ALGORITHM I USED IN GOSUB 40300
REM ..
REM GOSUB 41000..   COPYS PALLETTE ENTRY P1 TO P2.   P1 IS UNCHANGED
REM ..
REM .
REM ..
REM ...



39995 REM SET PALLETTE ENTRY P1 TO R%,G%,B%
40000 VPOKE 1,$FA00+(P1*2),(G%*16) + B%
40010 VPOKE 1,$FA00+((P1*2)+1),R%
40020 RETURN

40100 REM READ PALLETTE ENTRY AT P1
40100 REM RETURNED IN %R,%G,%B
40100 A1 = $FA00+(P1*2)
40105 R% = VPEEK(1,A1+1)
40110 GB%= VPEEK(1,A1)
40115 G% = GB%/16
40120 B% = GB% AND $0F
40125 RETURN

40199 FADE P2 FROM CURRENT COLOR TO P1 COLOR, J IS JIFFY DELAY
40200 GOSUB 40100
40205 P3=P1
40210 P1=P2
40215 GOSUB 40300
40220 P1=P3
40225 RETURN


40299 REM FADE P1 TO R%,G%,B%, J IS JIFFY DELAY
40300 DR%=R%:DG%=G%:DB%=B%
40305 GOSUB 40100
40310 RI=1:IF DR%<R% THEN RI=-1
40315 GI=1:IF DG%<G% THEN GI=-1
40320 BI=1:IF DB%<B% THEN BI=-1
40325 IF DR%<>R% THEN R%=R%+RI
40330 IF DG%<>G% THEN G%=G%+GI
40335 IF DB%<>B% THEN B%=B%+BI
40340 GOSUB 40000
40345 SLEEP J
40350 IF DR%=R% AND DG%=G% AND DB%=B% THEN 40360
40355 GOTO 40325
40360 RETURN


40499 REM SWAP PALLETTE COLORS AT P1 & P2
40500 A1 = $FA00+(P1*2)
40505 A2 = $FA00+(P2*2)
40510 B1 = VPEEK (1,A1)
40515 B2 = VPEEK (1,A1+1)
40520 B3 = VPEEK (1,A2)
40525 B4 = VPEEK (1,A2+1)
40530 VPOKE 1, A1, B3
40535 VPOKE 1, A1+1, B4
40540 VPOKE 1, A2, B1
40550 VPOKE 1, A2+1, B2
40560 RETURN

40999 REM COPY P1 PALLETTE ENTRY TO P2.. P1 IS LEFT UNCHANGED.
41000 VPOKE 1,$FA00+(P2*2), VPEEK(1, $FA00+(P1*2))
41010 VPOKE 1,$FA00+(P2*2)+1, VPEEK(1, $FA00+(P1*2)+1)
41020 RETURN

45000 RESTORE 50000
45010 REM LOOP THROUGH THE PALLETTE ADDRESS SPACE
45015 REM AND POKE THE VERA DEFAULT PALLETTE
45020 FOR PE = $FA00 TO $FBFE STEP 2
45025     READ R:READ GB
45030     VPOKE 1,PE,GB
45035     VPOKE 1,PE+1, R
45040 NEXT PE
45050 RETURN

49999 REM DEFAULT VERA PALLETTE AS DATA. FROM 0 TO 255 (2 BYTES EACH ENTRY)RGB
50000 DATA $00,$00,$0F,$FF,$08,$00,$0A,$FE,$0C,$4C,$00,$C5,$00,$0A,$0E,$E7,$0D
50005 DATA $85,$06,$40,$0F,$77,$03,$33,$07,$77,$0A,$F6,$00,$8F,$0B,$BB,$00,$00
50010 DATA $01,$11,$02,$22,$03,$33,$04,$44,$05,$55,$06,$66,$07,$77,$08,$88,$09
50015 DATA $99,$0A,$AA,$0B,$BB,$0C,$CC,$0D,$DD,$0E,$EE,$0F,$FF,$02,$11,$04,$33
50020 DATA $06,$44,$08,$66,$0A,$88,$0C,$99,$0F,$BB,$02,$11,$04,$22,$06,$33,$08
50025 DATA $44,$0A,$55,$0C,$66,$0F,$77,$02,$00,$04,$11,$06,$11,$08,$22,$0A,$22
50030 DATA $0C,$33,$0F,$33,$02,$00,$04,$00,$06,$00,$08,$00,$0A,$00,$0C,$00,$0F
50035 DATA $00,$02,$21,$04,$43,$06,$64,$08,$86,$0A,$A8,$0C,$C9,$0F,$EB,$02,$11
50040 DATA $04,$32,$06,$53,$08,$74,$0A,$95,$0C,$B6,$0F,$D7,$02,$10,$04,$31,$06
50045 DATA $51,$08,$62,$0A,$82,$0C,$A3,$0F,$C3,$02,$10,$04,$30,$06,$40,$08,$60
50050 DATA $0A,$80,$0C,$90,$0F,$B0,$01,$21,$03,$43,$05,$64,$07,$86,$09,$A8,$0B
50055 DATA $C9,$0D,$FB,$01,$21,$03,$42,$04,$63,$06,$84,$08,$A5,$09,$C6,$0B,$F7
50060 DATA $01,$20,$02,$41,$04,$61,$05,$82,$06,$A2,$08,$C3,$09,$F3,$01,$20,$02
50065 DATA $40,$03,$60,$04,$80,$05,$A0,$06,$C0,$07,$F0,$01,$21,$03,$43,$04,$65
50070 DATA $06,$86,$08,$A8,$09,$CA,$0B,$FC,$01,$21,$02,$42,$03,$64,$04,$85,$05
50075 DATA $A6,$06,$C8,$07,$F9,$00,$20,$01,$41,$01,$62,$02,$83,$02,$A4,$03,$C5
50080 DATA $03,$F6,$00,$20,$00,$41,$00,$61,$00,$82,$00,$A2,$00,$C3,$00,$F3,$01
50085 DATA $22,$03,$44,$04,$66,$06,$88,$08,$AA,$09,$CC,$0B,$FF,$01,$22,$02,$44
50090 DATA $03,$66,$04,$88,$05,$AA,$06,$CC,$07,$FF,$00,$22,$01,$44,$01,$66,$02
50095 DATA $88,$02,$AA,$03,$CC,$03,$FF,$00,$22,$00,$44,$00,$66,$00,$88,$00,$AA
50100 DATA $00,$CC,$00,$FF,$01,$12,$03,$34,$04,$56,$06,$68,$08,$8A,$09,$AC,$0B
50105 DATA $CF,$01,$12,$02,$24,$03,$46,$04,$58,$05,$6A,$06,$8C,$07,$9F,$00,$02
50110 DATA $01,$14,$01,$26,$02,$38,$02,$4A,$03,$5C,$03,$6F,$00,$02,$00,$14,$00
50115 DATA $16,$00,$28,$00,$2A,$00,$3C,$00,$3F,$01,$12,$03,$34,$05,$46,$07,$68
50120 DATA $09,$8A,$0B,$9C,$0D,$BF,$01,$12,$03,$24,$04,$36,$06,$48,$08,$5A,$09
50125 DATA $6C,$0B,$7F,$01,$02,$02,$14,$04,$16,$05,$28,$06,$2A,$08,$3C,$09,$3F
50130 DATA $01,$02,$02,$04,$03,$06,$04,$08,$05,$0A,$06,$0C,$07,$0F,$02,$12,$04
50135 DATA $34,$06,$46,$08,$68,$0A,$8A,$0C,$9C,$0F,$BE,$02,$11,$04,$23,$06,$35
50140 DATA $08,$47,$0A,$59,$0C,$6B,$0F,$7D,$02,$01,$04,$13,$06,$15,$08,$26,$0A
50145 DATA $28,$0C,$3A,$0F,$3C,$02,$01,$04,$03,$06,$04,$08,$06,$0A,$08,$0C,$09
50150 DATA $0F,$0B

Last edited by ahenry3068 on Mon Sep 11, 2023 9:54 pm, edited 6 times in total.
Ed Minchau
Posts: 497
Joined: Sat Jul 11, 2020 3:30 pm

Re: SOME CRUDE BMP CONVERSION CODE.

Post by Ed Minchau »

Your palette is distorted because BMP files store colors as Blue Green Red Alpha. BMP files also list the pixels as rows from left to right, but from the bottom row of the screen working up.

If the BMP is saved as 256 colors, then the palette is listed right after the 54 bute header. If your BMP file is saved as 24 bit encoding, then each pixel is listed as four bytes (BGRA) rather than as a palette index, starting immediately after the header.

To match that to the current palette on the X16, make a 24 bit equivalent of the X16 palette by multiplying each 4 bit value by 17, then use that 24 bit equivalent palette to compare with the BRG values in the BMP.
Last edited by Ed Minchau on Thu Sep 07, 2023 8:49 pm, edited 1 time in total.
User avatar
ahenry3068
Posts: 1084
Joined: Tue Apr 04, 2023 9:57 pm

Re: SOME CRUDE BMP CONVERSION CODE.

Post by ahenry3068 »

Figured that out................. TY though. Was back and forth with MarkTheStrange on DISCORD for about a couple hours earlier :)
User avatar
ahenry3068
Posts: 1084
Joined: Tue Apr 04, 2023 9:57 pm

Re: SOME CRUDE BMP CONVERSION CODE.

Post by ahenry3068 »

I ended up flipping the source files vertically in Paint Shop Pro to deal with the other issue
User avatar
ahenry3068
Posts: 1084
Joined: Tue Apr 04, 2023 9:57 pm

Re: SOME CRUDE BMP CONVERSION CODE.

Post by ahenry3068 »

Screenshot from 2023-09-07 14-24-32.png
Screenshot from 2023-09-07 14-24-32.png (88.77 KiB) Viewed 2564 times
I was elated when I got this Output........ I didn't imagine the X16 could look so good.
User avatar
ahenry3068
Posts: 1084
Joined: Tue Apr 04, 2023 9:57 pm

WINDOWS BMP TO BVLOAD CONVERTOR

Post by ahenry3068 »

I know I'm getting f....ing old. I know I went through a phase about 96,97 where I wrote a few Image Decoders
in Turbo Pascal. I know I did PCX & GIF. I know I took a stab at JPG and gave it up as to complicated. I'm almost
certain that I did a Windows BMP decoder in there somewhere, But I do not for the life of me remember the image being
stored Upside Down. !!!!!!
User avatar
ahenry3068
Posts: 1084
Joined: Tue Apr 04, 2023 9:57 pm

BMP TO BVLOAD CONVERTOR ...DONE

Post by ahenry3068 »

Another impressive image.
Screenshot from 2023-09-07 18-21-54.png
Screenshot from 2023-09-07 18-21-54.png (65.15 KiB) Viewed 2519 times
User avatar
ahenry3068
Posts: 1084
Joined: Tue Apr 04, 2023 9:57 pm

BMP TO BVLOAD ....UPDATE

Post by ahenry3068 »

Ed Minchau wrote: Thu Sep 07, 2023 8:40 pm Your palette is distorted because BMP files store colors as Blue Green Red Alpha. BMP files also list the pixels as rows from left to right, but from the bottom row of the screen working up.

If the BMP is saved as 256 colors, then the palette is listed right after the 54 bute header. If your BMP file is saved as 24 bit encoding, then each pixel is listed as four bytes (BGRA) rather than as a palette index, starting immediately after the header.

To match that to the current palette on the X16, make a 24 bit equivalent of the X16 palette by multiplying each 4 bit value by 17, then use that 24 bit equivalent palette to compare with the BRG values in the BMP.
I was initially assuming R,G,B,A order. The docs I read were a little unclear. It messed with my Brain for a couple hours until I got it figured out (with help)
User avatar
ahenry3068
Posts: 1084
Joined: Tue Apr 04, 2023 9:57 pm

Re: WIN BMP TO BVLOAD CONVERTER

Post by ahenry3068 »

If you feed it the right file the CX16 is absolutely spectacular for 8 bit.
Screenshot from 2023-09-09 20-34-25.png
Screenshot from 2023-09-09 20-34-25.png (265.92 KiB) Viewed 2411 times
Post Reply