summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-08-15 01:20:27 +0300
committerAndrei Karas <akaras@inbox.ru>2013-08-18 19:36:33 +0300
commit1d9a6b861ceb672ca62ba0bb5c14df65b7fa7c0b (patch)
tree3f8fa195f394356e5a59b22f9574ef2fe2810f6f
parentf97a167c445790fb380c2f730c377271e80e0d97 (diff)
downloadmv-1d9a6b861ceb672ca62ba0bb5c14df65b7fa7c0b.tar.gz
mv-1d9a6b861ceb672ca62ba0bb5c14df65b7fa7c0b.tar.bz2
mv-1d9a6b861ceb672ca62ba0bb5c14df65b7fa7c0b.tar.xz
mv-1d9a6b861ceb672ca62ba0bb5c14df65b7fa7c0b.zip
fix A and S dye for big endian systems.
-rw-r--r--src/resources/dye.cpp30
-rw-r--r--src/resources/dye_unittest.cc28
2 files changed, 41 insertions, 17 deletions
diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp
index 905f3bcab..c21a20305 100644
--- a/src/resources/dye.cpp
+++ b/src/resources/dye.cpp
@@ -29,6 +29,8 @@
#include <math.h>
#include <sstream>
+#include <SDL/SDL_endian.h>
+
#include "debug.h"
DyePalette::DyePalette(const std::string &description,
@@ -217,10 +219,16 @@ void DyePalette::replaceSColor(uint32_t *pixels, const int bufSize) const
const DyeColor &col = *it;
++ it;
const DyeColor &col2 = *it;
+
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ const unsigned int data = (*pixels) & 0x00ffffff;
+ const unsigned int coldata = (col.value[2] << 16)
+ | (col.value[1] << 8) | (col.value[0]);
+#else
const unsigned int data = (*pixels) & 0xffffff00;
const unsigned int coldata = (col.value[2] << 8)
| (col.value[1] << 16) | (col.value[0] << 24);
-
+#endif
if (data == coldata)
{
p[3] = col2.value[0];
@@ -254,9 +262,15 @@ void DyePalette::replaceAColor(uint32_t *pixels, const int bufSize) const
++ it;
const DyeColor &col2 = *it;
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ const unsigned int data = *pixels;
+ const unsigned int coldata = (col.value[3] << 24)
+ | (col.value[2] << 16) | (col.value[1] << 8) | (col.value[0]);
+#else
const unsigned int data = *pixels;
const unsigned int coldata = (col.value[3]) | (col.value[2] << 8)
| (col.value[1] << 16) | (col.value[0] << 24);
+#endif
if (data == coldata)
{
@@ -294,10 +308,15 @@ void DyePalette::replaceSOGLColor(uint32_t *pixels, const int bufSize) const
++ it;
const DyeColor &col2 = *it;
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ const unsigned int data = (*pixels) & 0xffffff00;
+ const unsigned int coldata = (col.value[0] << 24)
+ | (col.value[1] << 16) | (col.value[2] << 8);
+#else
const unsigned int data = (*pixels) & 0x00ffffff;
const unsigned int coldata = (col.value[0])
| (col.value[1] << 8) | (col.value[2] << 16);
-
+#endif
if (data == coldata)
{
p[0] = col2.value[0];
@@ -331,10 +350,15 @@ void DyePalette::replaceAOGLColor(uint32_t *pixels, const int bufSize) const
++ it;
const DyeColor &col2 = *it;
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ const unsigned int data = *pixels;
+ const unsigned int coldata = (col.value[0] << 24)
+ | (col.value[1] << 16) | (col.value[2] << 8) | col.value[3];
+#else
const unsigned int data = *pixels;
const unsigned int coldata = (col.value[0]) | (col.value[1] << 8)
| (col.value[2] << 16) | (col.value[3] << 24);
-
+#endif
if (data == coldata)
{
p[0] = col2.value[0];
diff --git a/src/resources/dye_unittest.cc b/src/resources/dye_unittest.cc
index dcea7bba6..5898f5665 100644
--- a/src/resources/dye_unittest.cc
+++ b/src/resources/dye_unittest.cc
@@ -41,15 +41,15 @@ TEST(Dye, replaceSOGLColor1)
TEST(Dye, replaceSOGLColor2)
{
- DyePalette palette("#00ff00,000011", 6);
+ DyePalette palette("#01ff02,030411", 6);
uint8_t data[4];
- data[0] = 0x00;
+ data[0] = 0x01;
data[1] = 0xff;
- data[2] = 0x00;
+ data[2] = 0x02;
data[3] = 0x20;
palette.replaceSOGLColor(reinterpret_cast<uint32_t*>(&data[0]), 1);
- EXPECT_EQ(0x00, data[0]);
- EXPECT_EQ(0x00, data[1]);
+ EXPECT_EQ(0x03, data[0]);
+ EXPECT_EQ(0x04, data[1]);
EXPECT_EQ(0x11, data[2]);
EXPECT_EQ(0x20, data[3]);
}
@@ -87,15 +87,15 @@ TEST(Dye, replaceAOGLColor1)
TEST(Dye, replaceAOGLColor2)
{
- DyePalette palette("#00ff0020,000011ff", 8);
+ DyePalette palette("#00ff0120,020311ff", 8);
uint8_t data[4];
data[0] = 0x00;
data[1] = 0xff;
- data[2] = 0x00;
+ data[2] = 0x01;
data[3] = 0x20;
palette.replaceAOGLColor(reinterpret_cast<uint32_t*>(&data[0]), 1);
- EXPECT_EQ(0x00, data[0]);
- EXPECT_EQ(0x00, data[1]);
+ EXPECT_EQ(0x02, data[0]);
+ EXPECT_EQ(0x03, data[1]);
EXPECT_EQ(0x11, data[2]);
EXPECT_EQ(0xff, data[3]);
}
@@ -179,17 +179,17 @@ TEST(Dye, replaceAColor1)
TEST(Dye, replaceAColor2)
{
- DyePalette palette("#00ff0020,000011ff", 8);
+ DyePalette palette("#02ff0120,040311ff", 8);
uint8_t data[4];
data[0] = 0x20;
- data[1] = 0x00;
+ data[1] = 0x01;
data[2] = 0xff;
- data[3] = 0x00;
+ data[3] = 0x02;
palette.replaceAColor(reinterpret_cast<uint32_t*>(&data[0]), 1);
EXPECT_EQ(0xff, data[0]);
EXPECT_EQ(0x11, data[1]);
- EXPECT_EQ(0x00, data[2]);
- EXPECT_EQ(0x00, data[3]);
+ EXPECT_EQ(0x03, data[2]);
+ EXPECT_EQ(0x04, data[3]);
}
TEST(Dye, replaceAColor3)