- Online Community Forums » Programming Questions » No red, only green and blue!

This thread is locked; no one can reply to it. rss feed Print
 1   2 
No red, only green and blue!
Member #7,909
October 2006


I'll do a sample project that will run on both Mac OS X (via XCode) and Windows (via VS2005) tomorrow morning and post it as soon as possible.

Of course, to reflect the error, poeple will need a mac intel.

Maybe there is a problem in Allegro in detecting little endian and big endian on Mac OS X. It happens only on this system.

Best regards.


Member #794
November 2000

Nevermind, try the following program:

1#include <allegro.h>
3/* Change this for testing */
4static int rgb_colour_15 = 0x7FFF;
6#define gba_getb(v) (v&31)
7#define gba_getg(v) ((v >> 5)&31)
8#define gba_getr(v) (v >> 10)
10int main(void)
12 int r, g, b;
14 allegro_init();
15 install_keyboard();
17 set_color_depth(32);
18 set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
20 r = gba_getr(rgb_colour_15) * 255./31.;
21 g = gba_getg(rgb_colour_15) * 255./31.;
22 b = gba_getb(rgb_colour_15) * 255./31.;
24 rectfill(screen, 0, 0, SCREEN_W/3, SCREEN_H-1, makecol(r, 0, 0));
25 rectfill(screen, SCREEN_W/3, 0, 2*SCREEN_W/3, SCREEN_H-1, makecol(0, g, 0));
26 rectfill(screen, 2*SCREEN_W/3, 0, SCREEN_W-1, SCREEN_H-1, makecol(0, 0, b));
28 rectfill(screen, SCREEN_W/6, SCREEN_H/3, 5*SCREEN_W/6, 4*SCREEN_H/6, makecol(r, g, b));
30 readkey();

If that gives you the proper output on both systems (you'll need to change the number at the top) the problem is elsewhere.

Member #7,909
October 2006


I have the correct values:
Red Green Blue verticals rectangles and a white horizontal rectangle.

I have seen this:

where it says that values must be encoded in big endian when running on Mac OS no matter it is intel or ppc processors.

My project maybe gives a perfect illustration of the big endian/little endian.
While windows is little endian, Mac OS is big endian. That's maybe why compisites are reverted.

But... But... but...
Your sample code show me the exact opposit way: composites are correctly sorted!!! Thus even if I select a UB compilation.
I'm stucked :(

Member #794
November 2000

Bit operations on integers do not depend on endianess, so the same code should work on each platform.
If the above code works and yours does not, you need to check what you do differently.

Member #7,909
October 2006

After deeper tests, I have tested with the 15 bits color 0x7249 which is an aquarel blue.

I have used the RGB coding and I get an aquarel orange.
When I reverse to BGR, I get the aquarel blue.

It's maybe due to the Big Endian encoding of Mac OS X.
While I have taken the 15bits values from Windows which is little endian encoded, when I use them on Mac OS X, it reverses the composites. That's the only explanation I have.

Member #794
November 2000

I don't understand what you mean.
If your numbers store the colour values as BGR instead of RGB, you will need to swap the gba_getb and gba_getr macro's, but that isn't and endianesse issue.
If you have the hex number 0xfeef, the high (as in most significant) byte holds the value 0xfe, the low (as in least significant) byte holds 0xef. This is true independent of endianesse. Which of these is stored first in memory (at the lowest memory adress) is, but you don't need to care about that in this case.


While I have taken the 15bits values from Windows which is little endian encoded, when I use them on Mac OS X, it reverses the composites.

I don't understand. What do you mean?


That's the only explanation I have.

You lost me. Are you seeing a problem with my example program, or yours? How are you reading in the colour components? Are they hard-coded, or do you read them from disk?

EDIT: for the record, the code I posted produces identical results on my PC (running Linux) and my laptop (a G4 iBook).

Member #7,909
October 2006

I see a problem with your sample too: use the color I told you (0x7249)
if you run your sample under windows, you'll get a blue color.
if you run your sample under mac os x, you'll get a orange color.

I have read the color values on a game boy emulator that runs under windows.

 1   2 

Go to: