Allegro.cc - Online Community

Allegro.cc 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!
boulifb
Member #7,909
October 2006

ok,

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.

Fred

Evert
Member #794
November 2000
avatar

Nevermind, try the following program:

1#include <allegro.h>
2 
3/* Change this for testing */
4static int rgb_colour_15 = 0x7FFF;
5 
6#define gba_getb(v) (v&31)
7#define gba_getg(v) ((v >> 5)&31)
8#define gba_getr(v) (v >> 10)
9 
10int main(void)
11{
12 int r, g, b;
13 
14 allegro_init();
15 install_keyboard();
16
17 set_color_depth(32);
18 set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
19
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.;
23
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));
27 
28 rectfill(screen, SCREEN_W/6, SCREEN_H/3, 5*SCREEN_W/6, 4*SCREEN_H/6, makecol(r, g, b));
29 
30 readkey();
31 
32}
33END_OF_MAIN()

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

boulifb
Member #7,909
October 2006

Hi,

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

I have seen this:
https://connect.apple.com/cgi-bin/WebObjects/MemberSite.woa/105/wo/m11Ev3fANuyw2NsPxNy1jFYVzsr/0.0.17.2.1.1.3.1.1.2.1.1.0

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 :(

Evert
Member #794
November 2000
avatar

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.

boulifb
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.

Evert
Member #794
November 2000
avatar

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.

Quote:

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?

Quote:

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).

boulifb
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: