(svn r13571) -Codechange: define channels in struct Colour in different order on LE and BE machines

This commit is contained in:
smatz 2008-06-18 21:19:04 +00:00
parent bc12e5453c
commit 7a7ff65ac5
7 changed files with 32 additions and 24 deletions

View File

@ -37,11 +37,10 @@ public:
/**
* Look up the colour in the current palette.
**/
static inline uint32 LookupColourInPalette(uint8 index)
*/
static inline uint32 LookupColourInPalette(uint index)
{
if (index == 0) return 0x00000000; // Full transparent pixel */
return ComposeColour(0xFF, _cur_palette[index].r, _cur_palette[index].g, _cur_palette[index].b);
return _cur_palette[index];
}
/**

View File

@ -19,7 +19,7 @@ enum Endian {
};
/**
* Shortcut to printf("#define TTD_*_ENDIAN 0/1")
* Shortcut to printf("#define TTD_ENDIAN TTD_*_ENDIAN")
* @param endian endian type to define
*/
static inline void printf_endian(Endian endian)

View File

@ -62,7 +62,7 @@ extern int _pal_count_dirty;
extern int _num_resolutions;
extern Dimension _resolutions[32];
extern Dimension _cur_resolution;
extern Colour _cur_palette[256];
extern Colour _cur_palette[256]; ///< Current palette. Entry 0 has to be always fully transparent!
void HandleKeypress(uint32 key);
void HandleCtrlChanged();

View File

@ -5,6 +5,7 @@
#ifndef GFX_TYPE_H
#define GFX_TYPE_H
#include "core/endian_type.hpp"
#include "core/enum_type.hpp"
#include "core/geometry_type.hpp"
#include "zoom_type.h"
@ -142,9 +143,13 @@ struct DrawPixelInfo {
};
struct Colour {
byte r;
byte g;
byte b;
#if TTD_ENDIAN == TTD_BIG_ENDIAN
uint8 a, r, g, b; ///< colour channels in BE order
#else
uint8 b, g, r, a; ///< colour channels in LE order
#endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */
operator uint32 () { return *(uint32 *)this; }
};
enum FontSize {

View File

@ -124,11 +124,13 @@ void DisplaySplashImage()
}
for (i = 0; i < num_palette; i++) {
_cur_palette[i].a = i == 0 ? 0 : 0xff;
_cur_palette[i].r = palette[i].red;
_cur_palette[i].g = palette[i].green;
_cur_palette[i].b = palette[i].blue;
}
_cur_palette[0xff].a = 0xff;
_cur_palette[0xff].r = 0;
_cur_palette[0xff].g = 0;
_cur_palette[0xff].b = 0;

View File

@ -428,20 +428,15 @@ static bool MakePCXImage(const char *name, ScreenshotCallback *callb, void *user
return false;
}
if (sizeof(*palette) == 3) {
success = fwrite(palette, 256 * sizeof(*palette), 1, f) == 1;
} else {
/* If the palette is word-aligned, copy it to a temporary byte array */
byte tmp[256 * 3];
uint i;
/* Palette is word-aligned, copy it to a temporary byte array */
byte tmp[256 * 3];
for (i = 0; i < 256; i++) {
tmp[i * 3 + 0] = palette[i].r;
tmp[i * 3 + 1] = palette[i].g;
tmp[i * 3 + 2] = palette[i].b;
}
success = fwrite(tmp, sizeof(tmp), 1, f) == 1;
for (uint i = 0; i < 256; i++) {
tmp[i * 3 + 0] = palette[i].r;
tmp[i * 3 + 1] = palette[i].g;
tmp[i * 3 + 2] = palette[i].b;
}
success = fwrite(tmp, sizeof(tmp), 1, f) == 1;
fclose(f);

View File

@ -2,11 +2,18 @@
/** @file palettes.h The colour translation of the GRF palettes. */
#define M(r, g, b) { r, g, b }
#include "../core/endian_type.hpp"
#if TTD_ENDIAN == TTD_BIG_ENDIAN
#define M(r, g, b) { 0xff, r, g, b }
#else
#define M(r, g, b) { b, g, r, 0xff }
#endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */
static const Colour _palettes[][256] = {
/* palette 1 (TTD Windows) */
{
M( 0, 0, 0), M(212, 0, 212), M(212, 0, 212), M(212, 0, 212),
{ 0, 0, 0, 0 }, M(212, 0, 212), M(212, 0, 212), M(212, 0, 212),
M(212, 0, 212), M(212, 0, 212), M(212, 0, 212), M(212, 0, 212),
M(212, 0, 212), M(212, 0, 212), M(168, 168, 168), M(184, 184, 184),
M(200, 200, 200), M(216, 216, 216), M(232, 232, 232), M(252, 252, 252),
@ -74,7 +81,7 @@ static const Colour _palettes[][256] = {
/* palette 2 (mixed TTD DOS + TTD Windows palette */
{
M( 0, 0, 0), M( 16, 16, 16), M( 32, 32, 32), M( 48, 48, 48),
{ 0, 0, 0, 0 }, M( 16, 16, 16), M( 32, 32, 32), M( 48, 48, 48),
M( 65, 64, 65), M( 82, 80, 82), M( 98, 101, 98), M(115, 117, 115),
M(131, 133, 131), M(148, 149, 148), M(168, 168, 168), M(184, 184, 184),
M(200, 200, 200), M(216, 216, 216), M(232, 232, 232), M(252, 252, 252),