Page 1 of 1

Image Conversion to BVLOAD format.

Posted: Sun Oct 15, 2023 9:47 pm
by ahenry3068
This program won't have any more updates. It works Ok but has a couple bugs. It's functionality is now included in my img2bmx convertor viewtopic.php?p=30702#p30702


I started this over in programming. That thread is spread out and the stuff I came up with deserves to consolidated in one easy repository so .This Post. Its going to be a bit long winded because I want to give some background into the project and a little exposition on the pieces of software here. (ALSO there is at least 2 additional programs to go here sometime in the future).

So almost 4 mos ago I started a pretty elaborate HANGMAN game(still not done) and also picked my next major project for X16 that "Will Not" be written in Basic. That is to be a Autodesk Animator decoder/display program for X16. (FLI/FLC files). I knew that to successfully accomplish that project I would have to be intimately familiar with the Graphics Hardware on the X16 and I've set about learning that. Along the way I've posted a set of VERA Palette GOSUB's for BASIC, and I've learned to play a few tricks for some interesting affects. This has led to the code on this post. So here we go. A lot of this code was initially meant as personal tools, thus there is minimal if any error checking on file formats. Feeding it the wrong file will cause unpredictable results but probably not what you want. :) Also I hard coded things like filenames when for a "release" program I would make that a variable.

All these programs require a BMP revision 3 file as initial input. This file format was chosen because it took the least processing on my part. In a 320x240, uncompressed, 256 color rev 3 BMP the Image data is in almost exactly the format I already need and I only really have to process the Palette Data. (BMP is a pretty non-standard standard, My code works specifically on REV 3, uncompressed 8 bit files.)

(Heres a sanity check. Its not a 100% guaranteed but probably 99%. If the source IN.BMP is exactly 77.9 kb's in size it's probably properly formatted).

UNLESS OTHERWISE NOTED .BAS FILES ARE TEXT BASIC SOURCE. .PRG is TOKENIZED.

CONVERT.BAS & CONVERT.PRG This is CBM / Commander X16 BASIC program for converting a properly formatted BMP Rev 3 file to BVLOAD format. This program started me off on this image conversion path. Filenames are Hardcoded. Input file must be named "IN.BMP" and output files are always named IMG.BIN and VPAL.BIN. The output files will be overwritten on each subsequent run, so if you need them for something then rename them or move them. It works well and I used it to convert the first 500 files for my slide show program. It was really a good feeling to me to be able to accomplish this task with code that ran natively on X16. It is a bit slow, about 1 minute per file in warp on the emulator. A bit over 2 mins if not using warp. The file is displayed in SCREEN $80 after the conversion is complete, so its also kind of a BMP viewer for the X16.
CONVERT.BAS
(7.43 KiB) Downloaded 226 times
CONVERT.PRG
(4.25 KiB) Downloaded 213 times

Since the convertor was slow I wanted some faster more automated tools. So since I've been working in BASIC, I turned to the QB64 compiler that can create Native Linux & Windows executables. Both utilities to be uploaded here. Zip files also include the QB64 source code if you want to play with it. The developers of QB64 went out of thier way to make QB64 both compatible with old GW-BASIC, QBasic and QuickBasic 4.5 code. They did a real good job. This is probably the only compiler you can take code written for DOS VGA Graphics mode and compile them natively for Windows or Linux with NO source code changes !!! (Gorillas anyone!) I was impressed by that. At the same time they made it extensible to support modern OS features as well. My one little bugaboo (very little) is that a lot of modern features are support not with BASIC extensions, but with a kind of Meta language that can be interspersed throughout the code _FILEEXIST for example. Anyway that's resulted in what I kind of consider a bug in my Linux version, (probably the Windows version as well but not tested). I've got to study the Meta language a bit more and I can weed out that bug. The bug is the programs current working directory is always where the executable is stored, instead of the current working directory of the user at the command line. The easiest workaround right now is to just have a copy of the program in the directory your working files on. Use that with ./img2Bvload. I'll clean that up at the next release then you can just keep one copy of the program in your path.

REQUIRES IMAGEMAGICK TO BE INSTALLED. MUST BE AN 8 BITS PER COLOR CHANNEL VERSION

I recommend Linux users to use whatever there repository version is, at least unless it isn't working. My current is the very latest version of Linux Mint (as of this post). The version I have installed just once in awhile messes up when the source file is a PNG. Doesn't err out, just produces a BMP incompatible with my code. I just convert PNG's to another format in GIMP first. Its a workaround. The Windows version doesn't seem to have this problem.. It is an ImageMagick problem. not my code.)
(!!! Hallelujah, the PNG bug with ImageMagick goes away in linux if I downscale the PNG to 8 bit first)

Heres a link to the Windows version that works with my program
download/file.php?id=2469



This code is still working on the REV 3 BMP file when converting to BVLOAD. But it makes a call to ImageMagick itself to initially create the proper BMP, so it can handle. .JPG, .PCX, .WEBP, .PNG .TIFF. Probably other formats as well. ImageMagick is a wondrous piece of software and it deserves its name.


img2Bvload Imgfile.EXT will work on any Image that ImageMagick supports and produce an IMG.BIN and VPAL.BIN to be BVLOADED. The output file names are currently hard coded. It is much faster than the CBM convert program.
img2bvload_LINUX.zip
(414.04 KiB) Downloaded 211 times
img2bvload_WINDOWS_X64.zip
(658.3 KiB) Downloaded 218 times

Finally, (for now) since the img2Bvload is running on the big boy computer, heres a short Test Image program to load and see them on the X16. Copy the IMG.BIN and VPAL.BIN to the working directory for this program before typing RUN.
TESTIMG.PRG
(82 Bytes) Downloaded 215 times

10/30/2023 Added companion program ANALYZE.PRG that counts colors used in IMG.BIN and shows free color indexes if any. Then it shows a visual representation of VPAL.BIN and then the Image. This is to allow the Developer to know what color indexs to use in his code to best work with the Image. I guess there is a 5 attachment image per post. Next Post then.

COMPANION TO Img2Bvload. ANALYZE.

Posted: Mon Oct 30, 2023 4:37 pm
by ahenry3068
Code to give a developer important info about IMG.BIN & VPAL.BIN produced by my conversion programs.

Heres the program. Source is in BASLOAD format now.
ANALYZE.BAS
(8.3 KiB) Downloaded 185 times
ANALYZE.PRG
(4.23 KiB) Downloaded 196 times

The below 64 bit version does not actually show the Palette graphically, just gives you the numbers. So here's SHOWPAL for X16
SHOWPAL.PRG
(3.46 KiB) Downloaded 208 times

NOW A 64 BIT VERSION, QB64 SOURCE AND LINUX EXECUTABLE INCLUDED (WINDOWS EXE TO FOLLOW) 64 BIT VERSION IS SEVERAL HUNDRED TIMES FASTER THAN CBM
ANALYZEQ.zip
(418.02 KiB) Downloaded 197 times

Added QB64 Analyze version

Posted: Wed Nov 01, 2023 10:14 pm
by ahenry3068
Added 64 bit analyze... Post above.