Find the best 8 bit palette for an RGB image

General FreeBASIC programming questions.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Find the best 8 bit palette for an RGB image

Post by MrSwiss »

Well, you've your ideas, fine ...

I'd go a different route:
leaving the images at 32 bit but, converting from .BMP to .PNG (saving plenty disk-space, in the process),
since .PNG is a compressed format ...

There even is a Library, to do such things in FB (called: FBImage, by D.J.Peters). (search: Forum/Libraries)
fatman2021
Posts: 215
Joined: Dec 14, 2013 0:43

Re: Find the best 8 bit palette for an RGB image

Post by fatman2021 »

MrSwiss wrote:Well, you've your ideas, fine ...

I'd go a different route:
leaving the images at 32 bit but, converting from .BMP to .PNG (saving plenty disk-space, in the process),
since .PNG is a compressed format ...

There even is a Library, to do such things in FB (called: FBImage, by D.J.Peters). (search: Forum/Libraries)
It looks like FBimage is Window/Linux only:

viewtopic.php?f=14&t=24105&p=223951&hil ... ge#p223951
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Find the best 8 bit palette for an RGB image

Post by MrSwiss »

fatman2021 wrote:It looks like FBimage is Window/Linux only:
I don't ever use DOS any longer but, the lib for WIN32 should also work on DOS (since both are 32 bit),
I just don't exactly know, where to copy them to ... (it's static too, DOS can't natively load DLL's).

My tip: just try it ... (can't more than fail but, then you know *for sure*.)
fatman2021
Posts: 215
Joined: Dec 14, 2013 0:43

Re: Find the best 8 bit palette for an RGB image

Post by fatman2021 »

MrSwiss wrote:
fatman2021 wrote:It looks like FBimage is Window/Linux only:
I don't ever use DOS any longer but, the lib for WIN32 should also work on DOS (since both are 32 bit),
I just don't exactly know, where to copy them to ... (it's static too, DOS can't natively load DLL's).

My tip: just try it ... (can't more than fail but, then you know *for sure*.)
It uses OpenGL.
SOIL

Jonathan Dummer
2007-07-26-10.36

Simple OpenGL Image Library

A tiny c library for uploading images as
textures into OpenGL. Also saving and
loading of images is supported.

I'm using Sean's Tool Box image loader as a base:
http://www.nothings.org/

I'm upgrading it to load TGA and DDS files, and a direct
path for loading DDS files straight into OpenGL textures,
when applicable.

Image Formats:
- BMP load & save
- TGA load & save
- DDS load & save
- PNG load
- JPG load

OpenGL Texture Features:
- resample to power-of-two sizes
- MIPmap generation
- compressed texture S3TC formats (if supported)
- can pre-multiply alpha for you, for better compositing
- can flip image about the y-axis (except pre-compressed DDS files)

Thanks to:
* Sean Barret - for the awesome stb_image
* Dan Venkitachalam - for finding some non-compliant DDS files, and patching some explicit casts
* everybody at gamedev.net
St_W
Posts: 1618
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: Find the best 8 bit palette for an RGB image

Post by St_W »

MrSwiss wrote:[...] the lib for WIN32 should also work on DOS (since both are 32 bit)
A binary built for Win32 never works on DOS in general. And btw there is 32-bit Linux too, and binaries built for it don't work on DOS either. The main reason is that they are using OS-specific APIs and a OS-specific binary format.
dafhi
Posts: 1640
Joined: Jun 04, 2005 9:51

Re: Find the best 8 bit palette for an RGB image

Post by dafhi »

[update]

floyd steinberg udt
Last edited by dafhi on Oct 03, 2017 2:18, edited 1 time in total.
xlucas
Posts: 334
Joined: May 09, 2014 21:19
Location: Argentina

Re: Find the best 8 bit palette for an RGB image

Post by xlucas »

fatman2021:
Why do you want to do what you want to do? Depending on the reason, I would recommend you to stick to 32 bit mode too. For instance, if you want speed, there are fewer bytes in 8 bits, but changing the palette for every frame will be slow in DOS because palettes are updated internally by outputting to a port each of the registers. FreeBasic can compile DOS programs in 32 bit colour depth and they run fine (unless you want to run them in DOSBox, in which case 32 bit colour depth does not work for 1024x768 or higher).

If you want smaller files, you should use RLE compression. PNG format is great but you will depend on 3rd-party libraries and I doubt you will find one that will work in DOS. I posted a FB-native library that writes Targa images with RLE compression about a month or two ago. If you're interested, I can link you to it here or post a newer version.

You may want to use an 8 bit mode if you expect another program to actually read and display the files and that program will only work with 8 bit images. If you are using and old DOS program to display the images, maybe the program will support FLI format (used by Autodesk Animator). That one is an 8 bit flic format with a reasonable compression for low resolutions. I could recommend you to study that format. Otherwise, you'll probably get a better result if you create your own program to display the frames in FreeBasic and again, in that case, I too think 32 bit mode is better.
fatman2021
Posts: 215
Joined: Dec 14, 2013 0:43

Re: Find the best 8 bit palette for an RGB image

Post by fatman2021 »

What I am doing is making 3D Dos demo(with photo realistic graphics) which will eventually include background music. When I have enough content I will start work on a 3D game(DOS, Windows, MacOS, and Linux will be supported). The 3D Demos and the DOS version of the game will be tested in VirtualBox (FreeDOS) and in DOSBOX. The graphics in the game will be rendered using a combination compositing and 3D planes with animated textures. The artwork is being created in Blender, Graphicsmagick, and GIMP. Most of the heavy lifting (rendering and baking) will be done in Blender.
Last edited by fatman2021 on Oct 03, 2017 2:29, edited 1 time in total.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Find the best 8 bit palette for an RGB image

Post by D.J.Peters »

@dafhi looks really not bad.

Joshy

RGB 24:
Image
My retro computer 16 color palette:
Image
Last edited by D.J.Peters on Oct 04, 2017 19:51, edited 1 time in total.
dafhi
Posts: 1640
Joined: Jun 04, 2005 9:51

Re: Find the best 8 bit palette for an RGB image

Post by dafhi »

:D

parrot.bmp is great too!
fatman2021
Posts: 215
Joined: Dec 14, 2013 0:43

Re: Find the best 8 bit palette for an RGB image

Post by fatman2021 »

Not bad, but needs to be faster...


32-BIT RGBA
Image

4-bit color
Image
TeeEmCee
Posts: 375
Joined: Jul 22, 2006 0:54
Location: Auckland

Re: Find the best 8 bit palette for an RGB image

Post by TeeEmCee »

xlucas wrote:If you want smaller files, you should use RLE compression. PNG format is great but you will depend on 3rd-party libraries and I doubt you will find one that will work in DOS.
These days you can find dependency-free libraries to read or write any common file format... as long as you're at least targetting 32-bit DOS rather than 16-bit (the horror!)
Take a look at LodePNG. It's small, has no dependencies, and someone actually ported it to QuickBasic, in case you have some kind of incorrigible hatred of C!

I'm using one of these simple single-file libraries for recording .gifs in realtime of my game engine running, but I found that its quantising of 24-bit colour inputs produces rather bad results. It uses a no-frills algorithm to compute a balanced k-d tree of the image pixels using partitioning by median. I'm going to try to improve it. Anyone have any suggestions for improving this while keeping the runtime below 5ms?
fatman2021
Posts: 215
Joined: Dec 14, 2013 0:43

Re: Find the best 8 bit palette for an RGB image

Post by fatman2021 »

I am not a big C/C++/Java fan. besides I do not have a cross-compiler that supports a 32-bit DOS target.

Most of my programming experience has been with BASIC, PASCAL, and Assembly(m68K,MOS-6502, Intel) with a little bit of Python, FORTRAN, COBOL, LISP, FORTH, and R(I use R as a bash replacement.)
xlucas
Posts: 334
Joined: May 09, 2014 21:19
Location: Argentina

Re: Find the best 8 bit palette for an RGB image

Post by xlucas »

Yeah, I have no problem with C in GNU/Linux, but in DOS, I also do not have a compiler I can use so that I can link 3rd party libraries. I like C, but I prefer FreeBasic because you always have the choice of not using any external libraries and your program can have everything, whereas that only is true in C if you're writing a console program.

I didn't know about LodePNG and it does indeed sound interesting. If it's been ported to QB and I can include it in my code then it'll be great for my projects. I have to check on the license. But if I have to link it as a shared object, then it would be a dependency itself :S I use Targa so much because it allows me to have 100% my own code and fully licensed to myself.
fatman2021
Posts: 215
Joined: Dec 14, 2013 0:43

Re: Find the best 8 bit palette for an RGB image

Post by fatman2021 »

D.J.Peters wrote:@dafhi looks really not bad.

Joshy

RGB 24:
Image
My retro computer 16 color palette:
Image
How do you convert the images back to 32-bit RGBA?
Post Reply