Resources and Support
 Pixel Joint Forum : The Lounge : Resources and Support
Message Icon Topic: Crushing 9-bit palette down to 256 colors Post Reply Post New Topic
Author Message
rootbeer666
Seaman
Seaman


Joined: 17 February 2019
Online Status: Offline
Posts: 1
Quote rootbeer666 Replybullet Topic: Crushing 9-bit palette down to 256 colors
    Posted: 18 February 2019 at 6:32pm
Hey all,

My first post here. I was going to post yesterday, but forum rules, you know. At least I had time to sleep on it, if you know what I mean.

I've been working on an 8/16-bit hobby computer project for a while, and I've made the design decision to drop the discrete RAMDAC I had originally planned due to chip bloat of the design, as project's objective is to stay relatively simple and efficient.

In my design all of the video modes are 8bbp, which is both generous on color and efficient for address generator of the video circuit, as computer's bus is 8 bits wide. This left me with a decision to make regarding the DAC, and how I'm going to drive it without palette registers. Sure, hand-picked palettes work best for specific instances, but I need to provide a general case that provides a full range of color. Simplest of course is RGB332 DAC which provides only half the steps in the blue channel. I decided against it, as among other things it provides only a 4-color pure grayscale ramp (black, white and 2 grays). Then I came up with a "gray fix" circuit, that drives the 9th bit to pull up the blue channel for a pure gray when values on other channels are equal, still, I wasn't satisfied as the blue primary ramp had only 4 values.

I consider 9-bit color space to be quite adequate for 16-bit type graphics and art, as evident from a number of successful and very colorful systems, such as SEGA Genesis, Atari ST and my favorite of them, the PC Engine.

So what I'm trying to do is cram all of the useful colors out of the 9-bit palette (512 colors) into a 256 color palette I can address with 8 bits. Obviously we are losing some values, but if you take a hard look, you will see that some are too similar to be noticed if they're missing. In other words my objective is to create a perception-optimized representation of the 9-bit color space with 256 entries. To help me visualize the color space I'm working with I wrote a Java program to plot out the colors (and I did several other experiments with other sizes of color cubes).
Note that Chrome browser color managemet may be making a mess of the image (my blues here look purple but normal in GIMP and Firefox).


First three rows are different RGB arrangements of the 9-bit color space, followed by three rows of luminance calculations to better visualize why so many of the colors look too similar.

So, what I need help with is devising a technique or formula to determine which colors are less important and can be dropped without perceived loss in color fidelity, as opposed to doing it all by hand and introducing a personal bias. How would you approach this? That is the first immediate objective.

Second objective would be arranging or sorting the resulting palette in some meaningful fashion. For example, perhaps arranging the first 16 entries as approximations of CGA colors for ease of programming on the hobby computer, but that's just an example.

This resulting palette could potentially have other applications, such as a uniform palette for GIF screenshots of 9-bit games with perceptive accuracy and no dithering or severe color banding. (For example GIMP makes quite a mess when generating indexed images, heavily favoring hue matching to luminance matching.)

What do you guys think?
IP IP Logged
yrizoud
Commander
Commander
Avatar

Joined: 03 May 2021
Location: France
Online Status: Offline
Posts: 343
Quote yrizoud Replybullet Posted: 20 February 2019 at 8:36am
Can you afford a pre-computed (hard-coded) 512 byte lookup table ? If so, that would be the easiest to implement.
Hand-select a palette, and pre-compute the lookup table.

However, I think the 9bit->palette design is awkward and inefficient. Do you actually ever 'compute' a color from RGB ? If not, having 'spots' everywhere in the entire RGB cube is useless (especially with this rather low precision of 8 levels per channel). A good part of it is made of visually redundant and rarely used fluorescent colors.
You would probably get a much more useful/interesting video system with a single hard-coded 256 color palette that gives room to all needs.

The Commodore 64 had better 16 handpicked colors than the 27 colors of the Amstrad CPC that fill a RGB cube (3x3x3)


Note, you may want to take gamma into account. If you apply gamma correction so that RGB 444 out of 888 is an average grey (instead of a dark grey), it's a better use of the low indexes : 000 111 and 222 are both separately useful, instead of almost the same.
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum