(svn r13571) -Codechange: define channels in struct Colour in different order on LE and BE machines
authorsmatz
Wed, 18 Jun 2008 21:19:04 +0000
changeset 11015 cf4b53f23fde
parent 11013 71b7f7c475db
child 11016 88f9744fefcc
(svn r13571) -Codechange: define channels in struct Colour in different order on LE and BE machines
src/blitter/32bpp_base.hpp
src/endian_check.cpp
src/gfx_func.h
src/gfx_type.h
src/os/macosx/splash.cpp
src/screenshot.cpp
src/table/palettes.h
--- a/src/blitter/32bpp_base.hpp	Wed Jun 18 20:20:12 2008 +0000
+++ b/src/blitter/32bpp_base.hpp	Wed Jun 18 21:19:04 2008 +0000
@@ -37,11 +37,10 @@
 
 	/**
 	 * 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];
 	}
 
 	/**
--- a/src/endian_check.cpp	Wed Jun 18 20:20:12 2008 +0000
+++ b/src/endian_check.cpp	Wed Jun 18 21:19:04 2008 +0000
@@ -19,7 +19,7 @@
 };
 
 /**
- * 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)
--- a/src/gfx_func.h	Wed Jun 18 20:20:12 2008 +0000
+++ b/src/gfx_func.h	Wed Jun 18 21:19:04 2008 +0000
@@ -62,7 +62,7 @@
 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();
--- a/src/gfx_type.h	Wed Jun 18 20:20:12 2008 +0000
+++ b/src/gfx_type.h	Wed Jun 18 21:19:04 2008 +0000
@@ -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 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 {
--- a/src/os/macosx/splash.cpp	Wed Jun 18 20:20:12 2008 +0000
+++ b/src/os/macosx/splash.cpp	Wed Jun 18 21:19:04 2008 +0000
@@ -124,11 +124,13 @@
 				}
 
 				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;
--- a/src/screenshot.cpp	Wed Jun 18 20:20:12 2008 +0000
+++ b/src/screenshot.cpp	Wed Jun 18 21:19:04 2008 +0000
@@ -428,20 +428,15 @@
 		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);
 
--- a/src/table/palettes.h	Wed Jun 18 20:20:12 2008 +0000
+++ b/src/table/palettes.h	Wed Jun 18 21:19:04 2008 +0000
@@ -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 @@
 
 	/* 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),