Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Rui 'Trovatore' Pires on Fri 20/05/2005 19:15:26

Title: Question: AGS's color system
Post by: Rui 'Trovatore' Pires on Fri 20/05/2005 19:15:26
I'd just like to ask, and I thought this might as well go here in case it becomes a suggestion of change (not yet) -

What's the logic behind AGS' color system (high-colour modes), which uses a range of 0-31 RGB instead of a 0-255 RGB? Is there any difference, or is it just backward compatibility?

How do I found out which color in this system is the equal of, say, 123,132,312 (just made that up) in regular 255 RGB?

And vice versa?
Title: Re: Question: AGS's color system
Post by: strazer on Fri 20/05/2005 20:09:28
QuoteHow do I found out which color in this system is the equal of, say, 123,132,312 (just made that up) in regular 255 RGB?

rawcolor = (2048*R) + (64*G) + B
Title: Re: Question: AGS's color system
Post by: Pumaman on Fri 20/05/2005 20:11:10
Hi-colour is 16-bit colour, in which Red, Green and Blue are represented by 5 bits each.
Therefore the accuracy of the hi-color video mode is down to 32 shades of each component.

AGS then keeps this method of selecting colours for 32-bit to make porting your game between 16-bit and 32-bit as painless as possible.
Title: Re: Question: AGS's color system
Post by: Kweepa on Fri 20/05/2005 20:22:32
Quote from: strazer on Fri 20/05/2005 20:09:28
QuoteHow do I found out which color in this system is the equal of, say, 123,132,312 (just made that up) in regular 255 RGB?

rawcolor = (2048*R) + (64*G) + B

Well, he asked for a conversion that would go from "255 RGB" to rawcolour.

This should work better.

// first convert from 0-255 to 0-31
int r32 = R/8;
int g32 = G/8;
int b32 = B/8;
// then
rawcolour = (2048*r32) + (64*g32) + b32
Title: Re: Question: AGS's color system
Post by: Rui 'Trovatore' Pires on Fri 20/05/2005 22:34:48
Thank you, but for the use I'll give it all I needed to know was that I can divide each number by 8 and use the resulting settings - that IS right, isn't it?

Nevertheless, I'll keep the rest in mind. But BTW,
Quoterawcolour = (2048*r32) + (64*g32) + b32

this is the internal calculation AGS does, right? I mean, in order to come up with the final number, this is what AGS does from the RGB values I set?
Title: Re: Question: AGS's color system
Post by: Clarvalon on Sat 03/10/2009 12:30:14
Forgive me for being thick - my GCSE maths is failing me.

How would you go about finding the reverse, i.e. the RGB 0-31 values from the 16bit rawcolour?  I'm guessing it will require some sort of Bitwise shifting?
Title: Re: Question: AGS's color system
Post by: Pumaman on Sat 03/10/2009 12:38:10
red = (raw >> 11) % 32
green = ((raw >> 5) % 64) / 2
blue = raw % 32
Title: Re: Question: AGS's color system
Post by: Clarvalon on Sat 03/10/2009 13:05:30
Superb, works a treat.  Thanks Chris.