Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: KamikazeHighland on Sat 28/05/2011 06:09:51

Title: RGB blue is... grey?
Post by: KamikazeHighland on Sat 28/05/2011 06:09:51
Game.GetColorFromRGB(255, 0, 0); is Red, Game.GetColorFromRGB(0, 255, 0); is Green.  Game.GetColorFromRGB(0, 0, 255); is... light grey...?

Game.GetColorFromRGB(0, 0, 100); is some sort of red.
Title: Re: -delete-
Post by: monkey0506 on Sat 28/05/2011 22:19:34
Well see, we can't really help you with that until you tell us what the actual problem is.  :=
Title: Re: -delete-
Post by: Wyz on Sat 28/05/2011 22:28:45
I guess it has something to do with subtractions.  :=
Title: Re: RGB blue is... grey?
Post by: Gilbert on Sun 29/05/2011 13:56:26
The problem is that:
1. AGS uses 16-bit colour depth for its colour space;
2. The first 32 colours are actually coming from standard EGA palette and shades of grays for some reason (which should be BLUE for true 16-bit colour space).

So, it's IMPOSSIBLE to set the drawing colour to RGB(0, 0, B) where B is 1 to 31(*8 ) atm, and GetColorFromRGB(R,g,b) just simply returns (R>>4)<<11) + ((g>>4)<<5) + (b>>3)), so this function is technically broken, if you want to get pure blue.

To get blue you need to make a compromise by using colours like (8, 8, 255).

Alternatively, fix this function by using this:
function FixedColourFromRGB(int R, int g, int b){
 int col = Game.GetColorFromRGB(R, g, b);
 if (col<32) col += ((1<<5)+(1<<11));
 return col;
}
Title: Re: RGB blue is... grey?
Post by: Kweepa on Sun 29/05/2011 15:16:53
This should really be fixed in AGS 4.
Title: Re: RGB blue is... grey?
Post by: Calin Leafshade on Sun 29/05/2011 15:32:17
Color Class plz, not an integer.

Color c = Color.FromARGB(R, G, B, A);
Title: Re: RGB blue is... grey?
Post by: KamikazeHighland on Sun 29/05/2011 19:21:44
Quote from: Calin Leafshade on Sun 29/05/2011 15:32:17
Color Classplease, not an integer.

Color c = Color.FromARGB(R, G, B, A);


Is that an actual thing?  That'd be cool, although I can define alpha in DrawImage.


Anyway, so will using GetColorFromRGB only ever return one of the 65535 colors that can be read with GetPixel?  I ask because while I'm not sure how to make use of Iceboty's code, if the color returned is an integer can that int ever be outside the 32x64x32 color range (i.e. Color_Transparent = -1, white = 65535)?  I'd be wasting my time with GetColorFromRGB if the color could only ever be one of the color codes anyway.

I'm glad you spelled out how GetColorFromRGB works because I've been trying to figure out why it returns different values for green and red whenever I set them to be the same.

I can't get enough of the double bitwise shifts, lol.  8)
Title: Re: RGB blue is... grey?
Post by: Calin Leafshade on Sun 29/05/2011 19:23:05
I'm afraid thats not a thing no. Just saying thats how it should be done.
Title: Re: RGB blue is... grey?
Post by: monkey0506 on Sun 29/05/2011 23:42:13
Well AGS is actually already defining the type:

struct ColorType {
 char rr,g,b; // should be single "are" :P silly SMF
 char filler;  // $AUTOCOMPLETEIGNORE$
 };


Which is only used for the palette (presently):

import ColorType palette[256];

Without actually perusing the source code, I don't know what the "filler" is used for, and obviously this isn't exactly the same as what Calin was talking about, but I just wanted to point out that this type already exists for use with palette-based games.

I think that the palette isn't really based off of "real" RGB either, but..
Title: Re: RGB blue is... grey?
Post by: Gilbert on Mon 30/05/2011 02:15:00
The filler is used for padding, so the palette data of each entry starts at a multiple of 4 bytes.