summaryrefslogtreecommitdiff
path: root/src/resources/dye
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-09-23 22:01:44 +0300
committerAndrei Karas <akaras@inbox.ru>2016-09-23 22:01:44 +0300
commit3c404128c4669a1f4f190e20a89553677717fc50 (patch)
tree2db4e5031089c800c4e00fd6244e578f44a7c910 /src/resources/dye
parent89b267d6d73bbc59f7c313b8a22b97fbb27f99a8 (diff)
downloadmanaverse-3c404128c4669a1f4f190e20a89553677717fc50.tar.gz
manaverse-3c404128c4669a1f4f190e20a89553677717fc50.tar.bz2
manaverse-3c404128c4669a1f4f190e20a89553677717fc50.tar.xz
manaverse-3c404128c4669a1f4f190e20a89553677717fc50.zip
Add missing comments into defines.
Diffstat (limited to 'src/resources/dye')
-rw-r--r--src/resources/dye/dye.cpp67
-rw-r--r--src/resources/dye/dye_unittest.cc11
-rw-r--r--src/resources/dye/dyepalette.cpp75
-rw-r--r--src/resources/dye/dyepalette.h2
-rw-r--r--src/resources/dye/dyepalette_unittest.cc5
5 files changed, 99 insertions, 61 deletions
diff --git a/src/resources/dye/dye.cpp b/src/resources/dye/dye.cpp
index 3aa42d7e7..e37b2e943 100644
--- a/src/resources/dye/dye.cpp
+++ b/src/resources/dye/dye.cpp
@@ -36,7 +36,7 @@
#ifndef SDL_BYTEORDER
#error missing SDL_endian.h
-#endif
+#endif // SDL_BYTEORDER
Dye::Dye(const std::string &restrict description)
{
@@ -164,9 +164,11 @@ void Dye::normalDye(uint32_t *restrict pixels,
const uint32_t p = pixels[ptr];
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
const int alpha = p & 0xff000000;
-#else
+#else // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
const int alpha = p & 0xff;
-#endif
+#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
if (alpha)
{
unsigned int color[3];
@@ -174,11 +176,13 @@ void Dye::normalDye(uint32_t *restrict pixels,
color[0] = (p) & 255U;
color[1] = (p >> 8U) & 255U;
color[2] = (p >> 16U) & 255U;
-#else
+#else // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
color[0] = (p >> 24U) & 255U;
color[1] = (p >> 16U) & 255U;
color[2] = (p >> 8U) & 255U;
-#endif
+#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
const unsigned int cmax = std::max(
color[0], std::max(color[1], color[2]));
if (cmax == 0)
@@ -205,10 +209,11 @@ void Dye::normalDye(uint32_t *restrict pixels,
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
pixels[ptr] = (color[0]) | (color[1] << 8)
| (color[2] << 16) | alpha;
-#else
+#else // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
pixels[ptr] = (color[0] << 24) | (color[1] << 16)
| (color[2] << 8) | alpha;
-#endif
+#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN
}
endlabel:{}
}
@@ -222,9 +227,11 @@ endlabel:{}
const uint32_t p = *pixels;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
const int alpha = p & 0xff000000;
-#else
+#else // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
const int alpha = p & 0xff;
-#endif
+#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
if (!alpha)
continue;
unsigned int color[3];
@@ -232,11 +239,12 @@ endlabel:{}
color[0] = (p) & 255U;
color[1] = (p >> 8U) & 255U;
color[2] = (p >> 16U) & 255U;
-#else
+#else // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
color[0] = (p >> 24U) & 255U;
color[1] = (p >> 16U) & 255U;
color[2] = (p >> 8U) & 255U;
-#endif
+#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN
const unsigned int cmax = std::max(
color[0], std::max(color[1], color[2]));
@@ -263,10 +271,11 @@ endlabel:{}
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
*pixels = (color[0]) | (color[1] << 8)
| (color[2] << 16) | alpha;
-#else
+#else // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
*pixels = (color[0] << 24) | (color[1] << 16)
| (color[2] << 8) | alpha;
-#endif
+#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN
}
#endif // ENABLE_CILKPLUS
}
@@ -283,9 +292,11 @@ void Dye::normalOGLDye(uint32_t *restrict pixels,
const uint32_t p = pixels[ptr];
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
const int alpha = p & 255;
-#else
+#else // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
const int alpha = p & 0xff000000;
-#endif
+#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
if (alpha)
{
unsigned int color[3];
@@ -293,11 +304,12 @@ void Dye::normalOGLDye(uint32_t *restrict pixels,
color[0] = (p >> 24U) & 255U;
color[1] = (p >> 16U) & 255U;
color[2] = (p >> 8U) & 255U;
-#else
+#else // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
color[0] = (p) & 255U;
color[1] = (p >> 8U) & 255U;
color[2] = (p >> 16U) & 255U;
-#endif
+#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN
const unsigned int cmax = std::max(
color[0], std::max(color[1], color[2]));
@@ -324,10 +336,11 @@ void Dye::normalOGLDye(uint32_t *restrict pixels,
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
pixels[ptr] = (color[0] << 24) | (color[1] << 16)
| (color[2] << 8) | alpha;
-#else
+#else // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
pixels[ptr] = (color[0]) | (color[1] << 8)
| (color[2] << 16) | alpha;
-#endif
+#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN
}
endlabel:{}
}
@@ -341,9 +354,11 @@ endlabel:{}
const uint32_t p = *pixels;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
const int alpha = p & 255;
-#else
+#else // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
const int alpha = p & 0xff000000;
-#endif
+#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
if (!alpha)
continue;
unsigned int color[3];
@@ -351,11 +366,12 @@ endlabel:{}
color[0] = (p >> 24U) & 255U;
color[1] = (p >> 16U) & 255U;
color[2] = (p >> 8U) & 255U;
-#else
+#else // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
color[0] = (p) & 255U;
color[1] = (p >> 8U) & 255U;
color[2] = (p >> 16U) & 255U;
-#endif
+#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN
const unsigned int cmax = std::max(
color[0], std::max(color[1], color[2]));
@@ -382,10 +398,11 @@ endlabel:{}
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
*pixels = (color[0] << 24) | (color[1] << 16)
| (color[2] << 8) | alpha;
-#else
+#else // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
*pixels = (color[0]) | (color[1] << 8)
| (color[2] << 16) | alpha;
-#endif
+#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN
}
#endif // ENABLE_CILKPLUS
}
diff --git a/src/resources/dye/dye_unittest.cc b/src/resources/dye/dye_unittest.cc
index 06abc09c7..09645039d 100644
--- a/src/resources/dye/dye_unittest.cc
+++ b/src/resources/dye/dye_unittest.cc
@@ -323,17 +323,16 @@ TEST_CASE("Dye real dye")
#ifdef USE_SDL2
imageHelper = new SurfaceImageHelper;
-#else
- imageHelper = new SDLImageHelper;
-#endif
-#ifdef USE_SDL2
SDLImageHelper::setRenderer(graphicsManager.createRenderer(
graphicsManager.createWindow(640, 480, 0,
SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE));
-#else
+#else // USE_SDL2
+
+ imageHelper = new SDLImageHelper;
+
graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
-#endif
+#endif // USE_SDL2
ActorSprite::load();
diff --git a/src/resources/dye/dyepalette.cpp b/src/resources/dye/dyepalette.cpp
index 9b2a2a8a8..9ea08331d 100644
--- a/src/resources/dye/dyepalette.cpp
+++ b/src/resources/dye/dyepalette.cpp
@@ -26,7 +26,7 @@
#ifndef DYECMD
#include "resources/db/palettedb.h"
-#endif
+#endif // DYECMD
#include "utils/stringutils.h"
@@ -40,7 +40,7 @@
#ifndef SDL_BYTEORDER
#error missing SDL_endian.h
-#endif
+#endif // SDL_BYTEORDER
DyePalette::DyePalette(const std::string &restrict description,
const uint8_t blockSize) :
@@ -94,7 +94,8 @@ DyePalette::DyePalette(const std::string &restrict description,
}
return;
}
-#endif
+#endif // DYECMD
+
logger->log("Error, invalid embedded palette: %s", description.c_str());
}
@@ -242,10 +243,12 @@ void DyePalette::replaceSColor(uint32_t *restrict pixels,
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
const int alpha = pixels[ptr] & 0xff000000;
const unsigned int data = pixels[ptr] & 0x00ffffff;
-#else
+#else // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
const int alpha = *p & 0xff;
const unsigned int data = pixels[ptr] & 0xffffff00;
-#endif
+#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
// logger->log("c:%04d %08x", c, *pixels);
// logger->log("data: %08x", data);
if (!alpha)
@@ -264,10 +267,11 @@ void DyePalette::replaceSColor(uint32_t *restrict pixels,
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
const unsigned int coldata = (col.value[2] << 16U)
| (col.value[1] << 8U) | (col.value[0]);
-#else
+#else // SDL_BYTEORDER == SDL_BIG_ENDIAN
const unsigned int coldata = (col.value[2] << 8U)
| (col.value[1] << 16U) | (col.value[0] << 24U);
-#endif
+#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
// logger->log("coldata: %08x", coldata);
if (data == coldata)
{
@@ -291,10 +295,12 @@ void DyePalette::replaceSColor(uint32_t *restrict pixels,
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
const int alpha = *pixels & 0xff000000;
const unsigned int data = (*pixels) & 0x00ffffff;
-#else
+#else // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
const int alpha = *p & 0xff;
const unsigned int data = (*pixels) & 0xffffff00;
-#endif
+#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
// logger->log("c:%04d %08x", c, *pixels);
// logger->log("data: %08x", data);
if (!alpha)
@@ -313,10 +319,12 @@ void DyePalette::replaceSColor(uint32_t *restrict pixels,
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
const unsigned int coldata = (col.value[2] << 16U)
| (col.value[1] << 8U) | (col.value[0]);
-#else
+#else // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
const unsigned int coldata = (col.value[2] << 8U)
| (col.value[1] << 16U) | (col.value[0] << 24U);
-#endif
+#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
// logger->log("coldata: %08x", coldata);
if (data == coldata)
{
@@ -361,12 +369,13 @@ void DyePalette::replaceAColor(uint32_t *restrict pixels,
| (col.value[2] << 16U)
| (col.value[1] << 8U)
| (col.value[0]);
-#else
+#else // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
const unsigned int coldata = (col.value[3])
| (col.value[2] << 8U)
| (col.value[1] << 16U) |
(col.value[0] << 24U);
-#endif
+#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN
if (data == coldata)
{
@@ -402,12 +411,12 @@ void DyePalette::replaceAColor(uint32_t *restrict pixels,
| (col.value[2] << 16U)
| (col.value[1] << 8U)
| (col.value[0]);
-#else
+#else // SDL_BYTEORDER == SDL_BIG_ENDIAN
const unsigned int coldata = (col.value[3])
| (col.value[2] << 8U)
| (col.value[1] << 16U) |
(col.value[0] << 24U);
-#endif
+#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN
if (data == coldata)
{
@@ -441,10 +450,12 @@ void DyePalette::replaceSOGLColor(uint32_t *restrict pixels,
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
const int alpha = *p & 0xff;
const unsigned int data = (pixels[ptr]) & 0xffffff00;
-#else
+#else // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
const int alpha = pixels[ptr] & 0xff000000;
const unsigned int data = (pixels[ptr]) & 0x00ffffff;
-#endif
+#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
if (alpha)
{
std::vector<DyeColor>::const_iterator it = mColors.begin();
@@ -457,10 +468,12 @@ void DyePalette::replaceSOGLColor(uint32_t *restrict pixels,
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
const unsigned int coldata = (col.value[0] << 24)
| (col.value[1] << 16) | (col.value[2] << 8);
-#else
+#else // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
const unsigned int coldata = (col.value[0])
| (col.value[1] << 8) | (col.value[2] << 16);
-#endif
+#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
if (data == coldata)
{
p[0] = col2.value[0];
@@ -484,10 +497,12 @@ void DyePalette::replaceSOGLColor(uint32_t *restrict pixels,
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
const int alpha = *p & 0xff;
const unsigned int data = (*pixels) & 0xffffff00;
-#else
+#else // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
const int alpha = *pixels & 0xff000000;
const unsigned int data = (*pixels) & 0x00ffffff;
-#endif
+#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
if (!alpha)
continue;
@@ -501,10 +516,12 @@ void DyePalette::replaceSOGLColor(uint32_t *restrict pixels,
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
const unsigned int coldata = (col.value[0] << 24)
| (col.value[1] << 16) | (col.value[2] << 8);
-#else
+#else // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
const unsigned int coldata = (col.value[0])
| (col.value[1] << 8) | (col.value[2] << 16);
-#endif
+#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
if (data == coldata)
{
p[0] = col2.value[0];
@@ -547,12 +564,14 @@ void DyePalette::replaceAOGLColor(uint32_t *restrict pixels,
| (col.value[1] << 16U)
| (col.value[2] << 8U)
| col.value[3];
-#else
+#else // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
const unsigned int coldata = (col.value[0])
| (col.value[1] << 8U)
| (col.value[2] << 16U)
| (col.value[3] << 24U);
-#endif
+#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
if (data == coldata)
{
p[0] = col2.value[0];
@@ -587,12 +606,14 @@ void DyePalette::replaceAOGLColor(uint32_t *restrict pixels,
| (col.value[1] << 16U)
| (col.value[2] << 8U)
| col.value[3];
-#else
+#else // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
const unsigned int coldata = (col.value[0])
| (col.value[1] << 8U)
| (col.value[2] << 16U)
| (col.value[3] << 24U);
-#endif
+#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN
+
if (data == coldata)
{
p[0] = col2.value[0];
diff --git a/src/resources/dye/dyepalette.h b/src/resources/dye/dyepalette.h
index 9796f40c5..f7258b4ec 100644
--- a/src/resources/dye/dyepalette.h
+++ b/src/resources/dye/dyepalette.h
@@ -92,7 +92,7 @@ class DyePalette final
#ifndef UNITTESTS
private:
-#endif
+#endif // UNITTESTS
std::vector<DyeColor> mColors;
};
diff --git a/src/resources/dye/dyepalette_unittest.cc b/src/resources/dye/dyepalette_unittest.cc
index 9d9f5fda6..d42e98b2e 100644
--- a/src/resources/dye/dyepalette_unittest.cc
+++ b/src/resources/dye/dyepalette_unittest.cc
@@ -64,9 +64,10 @@ TEST_CASE("DyePalette tests")
SDLImageHelper::setRenderer(graphicsManager.createRenderer(
graphicsManager.createWindow(640, 480, 0,
SDL_WINDOW_SHOWN | SDL_SWSURFACE), SDL_RENDERER_SOFTWARE));
-#else
+#else // USE_SDL2
+
graphicsManager.createWindow(640, 480, 0, SDL_ANYFORMAT | SDL_SWSURFACE);
-#endif
+#endif // USE_SDL2
ActorSprite::load();
paths.setDefaultValues(getPathsDefaults());