gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > How to get a 12-bit RGB mode on an 8-bit paletted display

#28971 - ayqazi - Tue Nov 09, 2004 1:37 pm

Hi,

I was browsing the Allegro (cross-platform graphics library) and I saw this example (comment taken from it:)

/*
* Example program for the Allegro library, by Richard Mitton.
*
* or "How to get a 12-bit mode on an 8-bit card"
*
* This program sets up a 12-bit mode on any 8-bit card, by setting up
* a 256-colour palette that will fool the eye into grouping two 8-bit
* pixels into one 12-bit pixel.
*
* It's quite simple (sort of). You make your 256-colour palette with
* all the combinations of blue and green, assuming green ranges from
* 0-15 and blue from 0-14. This takes up 16x15=240 colours. This leaves
* 16 colours to use as red (red ranges from 0-15).
*
* Then you put your green/blue in one pixel, and your red in the pixel
* next to it. The eye gets fooled into thinking it's all one pixel.
*
* It's all very simple really. Honest.
*
* To start with, you set a normal 256 color VESA mode, and construct a
* special palette for it. But then comes the trick: you need to write
* to a set of two adjacent pixels to form a single 12 bit dot. Two eight
* bit pixels is the same as one 16 bit pixel, so after setting the video
* mode you need to hack the screen bitmap about, halving the width and
* changing it to use the 16 bit drawing code. Then, once you have packed
* a color into the correct format (using the makecol12() function below),
* any of the normal Allegro drawing functions can be used with this 12
* bit display!
*
* Things to note:
*
* The horizontal width is halved, so you get resolutions like 320x480,
* 400x600, and 512x768.
*
* Because each dot is spread over two actual pixels, the display will
* be darker than in a normal video mode.
*
* Any bitmap data will obviously need converting to the correct 12
* bit format: regular 15 or 16 bit images won't display correctly...
*
* Although this works like a truecolor mode, it is actually using a
* 256 color palette, so palette fades are still possible!
*
* Note: This code only works in linear screen modes (don't try Mode-X).
*/

I was just wondering if we could put it to some kind of funky use? Yes, the GBA's already got 16-bit mode, but its only single buffered. I was thinking of doing this trick with the 8-bit double-buffered mode and thus providing a 12-bit real colour double-buffered mode.

I don't however think its a useful hack. However, what does everybody else think? Could it be useful in any situations?

Thanks,
Asfand Yar
_________________
--
http://www.it-is-truth.org/

#28972 - keldon - Tue Nov 09, 2004 2:06 pm

It's fine for a PC, but to do that to the gameboy would not be a good idea because you are halving the resolution.

#28975 - poslundc - Tue Nov 09, 2004 3:14 pm

You may run into problems on the GBA because the LCD screen already sort of uses this optical "trick" to achieve the effect of colour in the first place. Because of the BGR configuration you'd want to reverse the order, and you'd be leaving a sizeable gap between meta-pixels that might look awfully shabby.

Dan.

#28998 - Abscissa - Tue Nov 09, 2004 9:41 pm

That's pretty cool.

#29001 - sgeos - Tue Nov 09, 2004 11:29 pm

The GBA screen is already dark. I think this trick would darken the screen too much. (Assuming the trick works at all.)

-Brendan

#29008 - tepples - Wed Nov 10, 2004 2:49 am

If you were seriously considering using this trick, just use mode 3, or if you want tiles and sprites, use dithered 8-bit images in a 332 palette (if you have Allegro source code you should know what a 332 palette is).
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#29017 - sgeos - Wed Nov 10, 2004 7:04 am

I'm assuming 3 red bits 3 green bits and 2 blue bits for a total of 256 palette entries? My main problem with these palettes is that many of the dark or desaturated colors more or less look the same.

-Brendan

#29020 - sajiimori - Wed Nov 10, 2004 7:44 am

So weight it towards bright and saturated colors.

#29023 - ayqazi - Wed Nov 10, 2004 8:59 am

As I said, I don't think it'd be useful. Just wondering if anybody could think of any uses for it that I couldn't.
_________________
--
http://www.it-is-truth.org/

#29035 - ampz - Wed Nov 10, 2004 12:35 pm

dithering will most likely provide better results than this "trick" under all circumstances.

#29041 - an - Wed Nov 10, 2004 6:14 pm

if you need lots of colors in 8 bit mode, try this trick ;)

create 16 bit offscreen buffer and fill your screen with gradient from left to right, so that the first pixels have index 0 and the last pixels on right have 239.

then, on your hsync-interrupt, for every single scanline, copy the correct pixels from your buffer to the palettememory.

this way you can have 15 bit colors on 8 bit screen and you can even have it doublebuffered. wohoo! ok, it's slow but it works otherwise fine.

#29048 - sajiimori - Wed Nov 10, 2004 7:15 pm

I'm not seeing the point of that trick. You're copying in the same amount of data as you would in mode 3, and a VRAM backbuffer is useless since your pixel data is always the same.

Now, it might be useful in a tile mode if you fill all the BGs with the gradient pattern and punch holes in some of the top ones, because then you could sort sprites into a 15-bit scene.

#29076 - tepples - Thu Nov 11, 2004 12:57 am

But if you're going to go to all that work, then why not just dither your BG data down to 8-bit? Does it have something to do with inability to perform 8-bit VRAM writes on dynamically generated BG data?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#29081 - sajiimori - Thu Nov 11, 2004 2:40 am

Are you asking why somebody would want 15 bit color instead of dithering? I would think the answer is obvious.

#29734 - Kayamon - Wed Nov 24, 2004 3:36 pm

Wahey! My code is finally famous ;-)

But, on GBA, as someone said, the resolution loss would be a killer. Possibly a better way might be to show all the RED/BLUE pixels one frame, then GREEN the next? The LCD funkyness might blend it all together a bit.

But anyway, probably not worth the bother I suspect.... just stick with 16-bit colour, I reckon.

#29746 - Abscissa - Wed Nov 24, 2004 6:20 pm

Kayamon wrote:
The LCD funkyness might blend it all together a bit.


Either that or nausiate the player ;) But still a cool idea. If it's fast enough it could be like DLP and work well.