diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-10-10 22:14:45 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-10-10 22:15:57 +0300 |
commit | aa3f63fd497558a02feb3ddbc44f31eac091f39b (patch) | |
tree | 0e28b9b1f0501dd8be9e1a38db4ec1777fa3fbfa /src/resources/dye | |
parent | 7c10a6b61e9d06a4ae9cc9f942dfacb6fcfd9d3d (diff) | |
download | plus-aa3f63fd497558a02feb3ddbc44f31eac091f39b.tar.gz plus-aa3f63fd497558a02feb3ddbc44f31eac091f39b.tar.bz2 plus-aa3f63fd497558a02feb3ddbc44f31eac091f39b.tar.xz plus-aa3f63fd497558a02feb3ddbc44f31eac091f39b.zip |
Remove most unused files.
Diffstat (limited to 'src/resources/dye')
-rw-r--r-- | src/resources/dye/dye.cpp | 411 | ||||
-rw-r--r-- | src/resources/dye/dye.h | 95 | ||||
-rw-r--r-- | src/resources/dye/dyecolor.h | 84 | ||||
-rw-r--r-- | src/resources/dye/dyepalette.cpp | 311 | ||||
-rw-r--r-- | src/resources/dye/dyepalette.h | 187 | ||||
-rw-r--r-- | src/resources/dye/dyepalette_replaceacolor.cpp | 282 | ||||
-rw-r--r-- | src/resources/dye/dyepalette_replaceaoglcolor.cpp | 398 | ||||
-rw-r--r-- | src/resources/dye/dyepalette_replacescolor.cpp | 300 | ||||
-rw-r--r-- | src/resources/dye/dyepalette_replacesoglcolor.cpp | 402 | ||||
-rw-r--r-- | src/resources/dye/dyepaletteptr.h | 31 |
10 files changed, 0 insertions, 2501 deletions
diff --git a/src/resources/dye/dye.cpp b/src/resources/dye/dye.cpp deleted file mode 100644 index 65755bb87..000000000 --- a/src/resources/dye/dye.cpp +++ /dev/null @@ -1,411 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2007-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "resources/dye/dye.h" - -#include "logger.h" - -#include "resources/dye/dyepalette.h" - -#include "utils/delete2.h" - -#include <sstream> - -PRAGMA48(GCC diagnostic push) -PRAGMA48(GCC diagnostic ignored "-Wshadow") -#ifndef SDL_BIG_ENDIAN -#include <SDL_endian.h> -#endif // SDL_BYTEORDER -PRAGMA48(GCC diagnostic pop) - -#include "debug.h" - -Dye::Dye(const std::string &restrict description) -{ - for (int i = 0; i < dyePalateSize; ++i) - mDyePalettes[i] = nullptr; - - if (description.empty()) - return; - - size_t next_pos = 0; - const size_t length = description.length(); - do - { - const size_t pos = next_pos; - next_pos = description.find(';', pos); - - if (next_pos == std::string::npos) - next_pos = length; - - if (next_pos <= pos + 3 || description[pos + 1] != ':') - { - logger->log("Error, invalid dye: %s", description.c_str()); - return; - } - - int i = 0; - - switch (description[pos]) - { - case 'R': i = 0; break; - case 'G': i = 1; break; - case 'Y': i = 2; break; - case 'B': i = 3; break; - case 'M': i = 4; break; - case 'C': i = 5; break; - case 'W': i = 6; break; - case 'S': i = 7; break; - case 'A': i = 8; break; - default: - logger->log("Error, invalid dye: %s", description.c_str()); - return; - } - mDyePalettes[i] = new DyePalette(description.substr( - pos + 2, next_pos - pos - 2), i != 8 ? 6 : 8); - ++next_pos; - } - while (next_pos < length); -} - -Dye::~Dye() -{ - for (int i = 0; i < dyePalateSize; ++i) - delete2(mDyePalettes[i]) -} - -void Dye::instantiate(std::string &restrict target, - const std::string &restrict palettes) -{ - size_t next_pos = target.find('|'); - - if (next_pos == std::string::npos || palettes.empty()) - return; - - ++next_pos; - - std::ostringstream s; - s << target.substr(0, next_pos); - size_t last_pos = target.length(), pal_pos = 0; - do - { - const size_t pos = next_pos; - next_pos = target.find(';', pos); - - if (next_pos == std::string::npos) - next_pos = last_pos; - - if (next_pos == pos + 1 && pal_pos != std::string::npos) - { - const size_t pal_next_pos = palettes.find(';', pal_pos); - s << target[pos] << ':'; - if (pal_next_pos == std::string::npos) - { - s << palettes.substr(pal_pos); - s << target.substr(next_pos); - break; - } - s << palettes.substr(pal_pos, pal_next_pos - pal_pos); - pal_pos = pal_next_pos + 1; - } - else if (next_pos > pos + 2) - { - s << target.substr(pos, next_pos - pos); - } - else - { - logger->log("Error, invalid dye placeholder: %s", target.c_str()); - return; - } - s << target[next_pos]; - ++next_pos; - } - while (next_pos < last_pos); - - target = s.str(); -} - -int Dye::getType() const restrict2 noexcept2 -{ - if (mDyePalettes[sPaleteIndex] != nullptr) - return 1; - if (mDyePalettes[aPaleteIndex] != nullptr) - return 2; - return 0; -} - -void Dye::normalDye(uint32_t *restrict pixels, - const int bufSize) const restrict2 -{ - if (pixels == nullptr) - return; - -#ifdef ENABLE_CILKPLUS - cilk_for (int ptr = 0; ptr < bufSize; ptr ++) - { - const uint32_t p = pixels[ptr]; -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const int alpha = p & 0xff000000; -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - const int alpha = p & 0xff; -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - - if (alpha) - { - unsigned int color[3]; -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - color[0] = (p) & 255U; - color[1] = (p >> 8U) & 255U; - color[2] = (p >> 16U) & 255U; -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - color[0] = (p >> 24U) & 255U; - color[1] = (p >> 16U) & 255U; - color[2] = (p >> 8U) & 255U; -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - - const unsigned int cmax = std::max( - color[0], std::max(color[1], color[2])); - if (cmax == 0) - goto endlabel; - - const unsigned int cmin = std::min( - color[0], std::min(color[1], color[2])); - const unsigned int intensity = color[0] + color[1] + color[2]; - unsigned int i; - - if (cmin != cmax && (cmin != 0 || (intensity != cmax - && intensity != 2 * cmax))) - { - // not pure - goto endlabel; - } - - i = (color[0] != 0) | ((color[1] != 0) << 1) - | ((color[2] != 0) << 2); - - if (mDyePalettes[i - 1]) - mDyePalettes[i - 1]->getColor(cmax, color); - -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - pixels[ptr] = (color[0]) | (color[1] << 8) - | (color[2] << 16) | alpha; -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - pixels[ptr] = (color[0] << 24) | (color[1] << 16) - | (color[2] << 8) | alpha; -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - } -endlabel:{} - } - -#else // ENABLE_CILKPLUS - - for (const uint32_t *const p_end = pixels + CAST_SIZE(bufSize); - pixels != p_end; - ++ pixels) - { - const uint32_t p = *pixels; -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const int alpha = p & 0xff000000; -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - const int alpha = p & 0xff; -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - - if (alpha == 0) - continue; - unsigned int color[3]; -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - color[0] = (p) & 255U; - color[1] = (p >> 8U) & 255U; - color[2] = (p >> 16U) & 255U; -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - color[0] = (p >> 24U) & 255U; - color[1] = (p >> 16U) & 255U; - color[2] = (p >> 8U) & 255U; -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - - const unsigned int cmax = std::max( - color[0], std::max(color[1], color[2])); - if (cmax == 0) - continue; - - const unsigned int cmin = std::min( - color[0], std::min(color[1], color[2])); - const unsigned int intensity = color[0] + color[1] + color[2]; - - if (cmin != cmax && (cmin != 0 || (intensity != cmax - && intensity != 2 * cmax))) - { - // not pure - continue; - } - - const unsigned int i = static_cast<int>(color[0] != 0) | - (static_cast<int>(color[1] != 0) << 1) | - (static_cast<int>(color[2] != 0) << 2); - - if (mDyePalettes[i - 1] != nullptr) - mDyePalettes[i - 1]->getColor(cmax, color); - -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - *pixels = (color[0]) | (color[1] << 8) - | (color[2] << 16) | alpha; -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - *pixels = (color[0] << 24) | (color[1] << 16) - | (color[2] << 8) | alpha; -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - } -#endif // ENABLE_CILKPLUS -} - -void Dye::normalOGLDye(uint32_t *restrict pixels, - const int bufSize) const restrict2 -{ - if (pixels == nullptr) - return; - -#ifdef ENABLE_CILKPLUS - cilk_for (int ptr = 0; ptr < bufSize; ptr ++) - { - const uint32_t p = pixels[ptr]; -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const int alpha = p & 255; -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - const int alpha = p & 0xff000000; -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - - if (alpha) - { - unsigned int color[3]; -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - color[0] = (p >> 24U) & 255U; - color[1] = (p >> 16U) & 255U; - color[2] = (p >> 8U) & 255U; -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - color[0] = (p) & 255U; - color[1] = (p >> 8U) & 255U; - color[2] = (p >> 16U) & 255U; -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - - const unsigned int cmax = std::max( - color[0], std::max(color[1], color[2])); - if (cmax == 0) - goto endlabel; - - const unsigned int cmin = std::min( - color[0], std::min(color[1], color[2])); - const unsigned int intensity = color[0] + color[1] + color[2]; - - if (cmin != cmax && (cmin != 0 || (intensity != cmax - && intensity != 2 * cmax))) - { - // not pure - goto endlabel; - } - - const unsigned int i = (color[0] != 0) | ((color[1] != 0) << 1) - | ((color[2] != 0) << 2); - - if (mDyePalettes[i - 1]) - mDyePalettes[i - 1]->getColor(cmax, color); - -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - pixels[ptr] = (color[0] << 24) | (color[1] << 16) - | (color[2] << 8) | alpha; -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - pixels[ptr] = (color[0]) | (color[1] << 8) - | (color[2] << 16) | alpha; -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - } -endlabel:{} - } - -#else // ENABLE_CILKPLUS - - for (const uint32_t *const p_end = pixels + CAST_SIZE(bufSize); - pixels != p_end; - ++ pixels) - { - const uint32_t p = *pixels; -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const int alpha = p & 255; -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - const int alpha = p & 0xff000000; -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - - if (alpha == 0) - continue; - unsigned int color[3]; -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - color[0] = (p >> 24U) & 255U; - color[1] = (p >> 16U) & 255U; - color[2] = (p >> 8U) & 255U; -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - color[0] = (p) & 255U; - color[1] = (p >> 8U) & 255U; - color[2] = (p >> 16U) & 255U; -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - - const unsigned int cmax = std::max( - color[0], std::max(color[1], color[2])); - if (cmax == 0) - continue; - - const unsigned int cmin = std::min( - color[0], std::min(color[1], color[2])); - const unsigned int intensity = color[0] + color[1] + color[2]; - - if (cmin != cmax && (cmin != 0 || (intensity != cmax - && intensity != 2 * cmax))) - { - // not pure - continue; - } - - const unsigned int i = static_cast<int>(color[0] != 0) | - (static_cast<int>(color[1] != 0) << 1) | - (static_cast<int>(color[2] != 0) << 2); - - if (mDyePalettes[i - 1] != nullptr) - mDyePalettes[i - 1]->getColor(cmax, color); - -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - *pixels = (color[0] << 24) | (color[1] << 16) - | (color[2] << 8) | alpha; -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - *pixels = (color[0]) | (color[1] << 8) - | (color[2] << 16) | alpha; -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - } -#endif // ENABLE_CILKPLUS -} diff --git a/src/resources/dye/dye.h b/src/resources/dye/dye.h deleted file mode 100644 index 1f8eb2fdd..000000000 --- a/src/resources/dye/dye.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2007-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef RESOURCES_DYE_DYE_H -#define RESOURCES_DYE_DYE_H - -#include <string> - -#include "localconsts.h" - -class DyePalette; - -const int dyePalateSize = 9; -const int sPaleteIndex = 7; -const int aPaleteIndex = 8; - -/** - * Class for dispatching pixel-recoloring amongst several palettes. - */ -class Dye final -{ - public: - /** - * Creates a set of palettes based on the given string. - * - * The parts of string are separated by semi-colons. Each part starts - * by an uppercase letter, followed by a colon and then a palette name. - */ - explicit Dye(const std::string &restrict dye); - - A_DELETE_COPY(Dye) - - /** - * Destroys the associated palettes. - */ - ~Dye(); - - /** - * Fills the blank in a dye placeholder with some palette names. - */ - static void instantiate(std::string &restrict target, - const std::string &restrict palettes); - - /** - * Return special dye palete (S) - */ - const DyePalette *getSPalete() const restrict2 noexcept2 A_WARN_UNUSED - { return mDyePalettes[sPaleteIndex]; } - - /** - * Return special dye palete (A) - */ - const DyePalette *getAPalete() const restrict2 noexcept2 A_WARN_UNUSED - { return mDyePalettes[aPaleteIndex]; } - - /** - * Return dye type for S - 1, for A - 2, 0 for other - */ - int getType() const restrict2 noexcept2 A_WARN_UNUSED; - - void normalDye(uint32_t *restrict pixels, - const int bufSize) const restrict2; - - void normalOGLDye(uint32_t *restrict pixels, - const int bufSize) const restrict2; - - private: - /** - * The order of the palettes, as well as their uppercase letter, is: - * - * Red, Green, Yellow, Blue, Magenta, White (or rather gray), Simple. - */ - DyePalette *restrict mDyePalettes[dyePalateSize]; -}; - -#endif // RESOURCES_DYE_DYE_H diff --git a/src/resources/dye/dyecolor.h b/src/resources/dye/dyecolor.h deleted file mode 100644 index 229f9d86b..000000000 --- a/src/resources/dye/dyecolor.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2013-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef RESOURCES_DYE_DYECOLOR_H -#define RESOURCES_DYE_DYECOLOR_H - -#include "utils/buildhex.h" - -#include "localconsts.h" - -struct DyeColor final -{ - DyeColor() noexcept2 : - valueA(buildHex(0, 0, 0, 255)), - valueS(buildHex(0, 0, 0, 0)), - valueSOgl(buildHexOgl(0, 0, 0, 0)) - { - value[3] = 255; - } - - DyeColor(const uint8_t r, - const uint8_t g, - const uint8_t b) noexcept2 : - valueA(buildHex(r, g, b, 255)), - valueS(buildHex(r, g, b, 0)), - valueSOgl(buildHexOgl(0, b, g, r)) - { - value[0] = r; - value[1] = g; - value[2] = b; - value[3] = 255; - } - - DyeColor(const uint8_t r, - const uint8_t g, - const uint8_t b, - const uint8_t a) noexcept2 : - valueA(buildHex(r, g, b, a)), - valueS(buildHex(r, g, b, 0)), - valueSOgl(buildHexOgl(0, b, g, r)) - { - value[0] = r; - value[1] = g; - value[2] = b; - value[3] = a; - } - - A_DEFAULT_COPY(DyeColor) - - void update() - { - valueA = buildHex(value[0], value[1], value[2], value[3]); - valueS = buildHex(value[0], value[1], value[2], 0); - valueSOgl = buildHexOgl(0, value[2], value[1], value[0]); - } - - union - { - uint8_t value[4]; - uint32_t valueAOgl; - }; - uint32_t valueA; - uint32_t valueS; - uint32_t valueSOgl; -}; - -#endif // RESOURCES_DYE_DYECOLOR_H diff --git a/src/resources/dye/dyepalette.cpp b/src/resources/dye/dyepalette.cpp deleted file mode 100644 index 0e0784d63..000000000 --- a/src/resources/dye/dyepalette.cpp +++ /dev/null @@ -1,311 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2007-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "resources/dye/dyepalette.h" - -#include "logger.h" - -#ifndef DYECMD -#include "resources/db/palettedb.h" -#endif // DYECMD - -#include "utils/stringutils.h" - -#ifndef USE_SDL2 -#include <cmath> -#endif // USE_SDL2 - -PRAGMA48(GCC diagnostic push) -PRAGMA48(GCC diagnostic ignored "-Wshadow") -#ifndef SDL_BIG_ENDIAN -#include <SDL_endian.h> -#endif // SDL_BYTEORDER -PRAGMA48(GCC diagnostic pop) - -#ifdef SIMD_SUPPORTED -#include "utils/cpu.h" -#endif // SIMD_SUPPORTED -#include "utils/foreach.h" - -#include "debug.h" - -DyeFunctionPtr DyePalette::funcReplaceSColor = nullptr; -DyeFunctionPtr DyePalette::funcReplaceSColorSse2 = nullptr; -DyeFunctionPtr DyePalette::funcReplaceSColorAvx2 = nullptr; -DyeFunctionPtr DyePalette::funcReplaceAColor = nullptr; -DyeFunctionPtr DyePalette::funcReplaceAColorSse2 = nullptr; -DyeFunctionPtr DyePalette::funcReplaceAColorAvx2 = nullptr; - -#ifdef USE_OPENGL -DyeFunctionPtr DyePalette::funcReplaceSOGLColor = nullptr; -DyeFunctionPtr DyePalette::funcReplaceSOGLColorSse2 = nullptr; -DyeFunctionPtr DyePalette::funcReplaceSOGLColorAvx2 = nullptr; -DyeFunctionPtr DyePalette::funcReplaceAOGLColor = nullptr; -DyeFunctionPtr DyePalette::funcReplaceAOGLColorSse2 = nullptr; -DyeFunctionPtr DyePalette::funcReplaceAOGLColorAvx2 = nullptr; -#endif // USE_OPENGL - -DyePalette::DyePalette(const std::string &restrict description, - const uint8_t blockSize) : - mColors() -{ - const size_t size = CAST_SIZE(description.length()); - if (size == 0) - return; - - StringVect parts; - splitToStringVector(parts, description.substr(1), ','); - if (description[0] == '#') - { - FOR_EACH (StringVectCIter, it, parts) - { - DyeColor color(0, 0, 0, 0); - hexToColor(*it, blockSize, color); - mColors.push_back(color); - } - return; - } -#ifndef DYECMD - else if (description[0] == '@') - { - uint8_t alpha = 255; - FOR_EACH (StringVectCIter, it, parts) - { - const std::string str = *it; - if (str.empty()) - continue; - if (str[0] == '+') - { - if (str.size() != 3) - continue; - alpha = CAST_U8((hexDecode(str[1]) << 4) + hexDecode(str[2])); - continue; - } - const DyeColor *const color = PaletteDB::getColor(str); - if (color != nullptr) - { - DyeColor color2 = *color; - color2.value[3] = alpha; - mColors.push_back(color2); - } - else - { - DyeColor color2(0, 0, 0, 0); - hexToColor(str, blockSize, color2); - mColors.push_back(color2); - } - } - return; - } -#endif // DYECMD - - logger->log("Error, invalid embedded palette: %s", description.c_str()); -} - -void DyePalette::hexToColor(const std::string &restrict hexStr, - const uint8_t blockSize, - DyeColor &color) noexcept2 -{ - for (size_t i = 0, colorIdx = 0; - i < blockSize && colorIdx < 4; - i += 2, colorIdx ++) - { - color.value[colorIdx] = CAST_U8(( - hexDecode(hexStr[i]) << 4) - + hexDecode(hexStr[i + 1])); - } - color.update(); -} - -unsigned int DyePalette::hexDecode(const signed char c) noexcept2 -{ - if ('0' <= c && c <= '9') - return c - '0'; - else if ('A' <= c && c <= 'F') - return c - 'A' + 10; - else if ('a' <= c && c <= 'f') - return c - 'a' + 10; - else - return 0; -} - -void DyePalette::getColor(const unsigned int intensity, - unsigned int (&restrict color)[3]) const restrict2 -{ - if (intensity == 0) - { - color[0] = 0; - color[1] = 0; - color[2] = 0; - return; - } - - const int last = CAST_S32(mColors.size()); - if (last == 0) - return; - - const int intLast = intensity * last; - const int i = intLast / 255; - const int t = intLast % 255; - - int j = t != 0 ? i : i - 1; - - if (j >= last) - j = 0; - - // Get the exact color if any, the next color otherwise. - const DyeColor &colorJ = mColors[j]; - const int r2 = colorJ.value[0]; - const int g2 = colorJ.value[1]; - const int b2 = colorJ.value[2]; - - if (t == 0) - { - // Exact color. - color[0] = r2; - color[1] = g2; - color[2] = b2; - return; - } - - // Get the previous color. First color is implicitly black. - if (i > 0 && i < last + 1) - { - const DyeColor &colorI = mColors[i - 1]; - const int t2 = 255 - t; - // Perform a linear interpolation. - color[0] = (t2 * colorI.value[0] + t * r2) / 255; - color[1] = (t2 * colorI.value[1] + t * g2) / 255; - color[2] = (t2 * colorI.value[2] + t * b2) / 255; - } - else - { - // Perform a linear interpolation. - color[0] = (t * r2) / 255; - color[1] = (t * g2) / 255; - color[2] = (t * b2) / 255; - } -} - -void DyePalette::getColor(double intensity, - int (&restrict color)[3]) const restrict2 -{ - // Nothing to do here - if (mColors.empty()) - return; - - // Force range - if (intensity > 1.0) - intensity = 1.0; - else if (intensity < 0.0) - intensity = 0.0; - - // Scale up - intensity *= static_cast<double>(mColors.size() - 1); - - // Color indices - const int i = CAST_S32(floor(intensity)); - const int j = CAST_S32(ceil(intensity)); - const DyeColor &colorI = mColors[i]; - - if (i == j) - { - // Exact color. - color[0] = colorI.value[0]; - color[1] = colorI.value[1]; - color[2] = colorI.value[2]; - return; - } - - intensity -= i; - const double rest = 1 - intensity; - const DyeColor &colorJ = mColors[j]; - - // Perform the interpolation. - color[0] = CAST_S32(rest * colorI.value[0] + - intensity * colorJ.value[0]); - color[1] = CAST_S32(rest * colorI.value[1] + - intensity * colorJ.value[1]); - color[2] = CAST_S32(rest * colorI.value[2] + - intensity * colorJ.value[2]); -} - -void DyePalette::initFunctions() -{ -#ifdef SIMD_SUPPORTED - const uint32_t flags = Cpu::getFlags(); - if ((flags & Cpu::FEATURE_AVX2) != 0u) - { - funcReplaceSColor = &DyePalette::replaceSColorAvx2; - funcReplaceSColorAvx2 = &DyePalette::replaceSColorAvx2; - funcReplaceSColorSse2 = &DyePalette::replaceSColorSse2; - funcReplaceAColor = &DyePalette::replaceAColorAvx2; - funcReplaceAColorAvx2 = &DyePalette::replaceAColorAvx2; - funcReplaceAColorSse2 = &DyePalette::replaceAColorSse2; - -#ifdef USE_OPENGL - funcReplaceSOGLColor = &DyePalette::replaceSOGLColorAvx2; - funcReplaceSOGLColorAvx2 = &DyePalette::replaceSOGLColorAvx2; - funcReplaceSOGLColorSse2 = &DyePalette::replaceSOGLColorSse2; - funcReplaceAOGLColor = &DyePalette::replaceAOGLColorAvx2; - funcReplaceAOGLColorAvx2 = &DyePalette::replaceAOGLColorAvx2; - funcReplaceAOGLColorSse2 = &DyePalette::replaceAOGLColorSse2; -#endif // USE_OPENGL - } - else if ((flags & Cpu::FEATURE_SSE2) != 0u) - { - funcReplaceSColor = &DyePalette::replaceSColorSse2; - funcReplaceSColorAvx2 = &DyePalette::replaceSColorSse2; - funcReplaceSColorSse2 = &DyePalette::replaceSColorSse2; - funcReplaceAColor = &DyePalette::replaceAColorSse2; - funcReplaceAColorAvx2 = &DyePalette::replaceAColorSse2; - funcReplaceAColorSse2 = &DyePalette::replaceAColorSse2; - -#ifdef USE_OPENGL - funcReplaceSOGLColor = &DyePalette::replaceSOGLColorSse2; - funcReplaceSOGLColorAvx2 = &DyePalette::replaceSOGLColorSse2; - funcReplaceSOGLColorSse2 = &DyePalette::replaceSOGLColorSse2; - funcReplaceAOGLColor = &DyePalette::replaceAOGLColorSse2; - funcReplaceAOGLColorAvx2 = &DyePalette::replaceAOGLColorSse2; - funcReplaceAOGLColorSse2 = &DyePalette::replaceAOGLColorSse2; -#endif // USE_OPENGL - } - else -#endif // SIMD_SUPPORTED - { - funcReplaceSColor = &DyePalette::replaceSColorDefault; - funcReplaceSColorAvx2 = &DyePalette::replaceSColorDefault; - funcReplaceSColorSse2 = &DyePalette::replaceSColorDefault; - funcReplaceAColor = &DyePalette::replaceAColorDefault; - funcReplaceAColorAvx2 = &DyePalette::replaceAColorDefault; - funcReplaceAColorSse2 = &DyePalette::replaceAColorDefault; - -#ifdef USE_OPENGL - funcReplaceSOGLColor = &DyePalette::replaceSOGLColorDefault; - funcReplaceSOGLColorAvx2 = &DyePalette::replaceSOGLColorDefault; - funcReplaceSOGLColorSse2 = &DyePalette::replaceSOGLColorDefault; - funcReplaceAOGLColor = &DyePalette::replaceAOGLColorDefault; - funcReplaceAOGLColorAvx2 = &DyePalette::replaceAOGLColorDefault; - funcReplaceAOGLColorSse2 = &DyePalette::replaceAOGLColorDefault; -#endif // USE_OPENGL - } -} diff --git a/src/resources/dye/dyepalette.h b/src/resources/dye/dyepalette.h deleted file mode 100644 index 2db7bd13b..000000000 --- a/src/resources/dye/dyepalette.h +++ /dev/null @@ -1,187 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2007-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef RESOURCES_DYE_DYEPALETTE_H -#define RESOURCES_DYE_DYEPALETTE_H - -#include "resources/dye/dyecolor.h" - -#include "utils/vector.h" - -#include "resources/dye/dyepaletteptr.h" - -#include <string> - -#include "localconsts.h" - -#define DYEPALETTE(palette, color) \ - ((palette).*DyePalette::funcReplace##color) - -#define DYEPALETTEP(palette, color) \ - ((palette)->*DyePalette::funcReplace##color) - -/** - * Class for performing a linear interpolation between colors. - */ -class DyePalette final -{ - public: - /** - * Creates a palette based on the given string. - * The string is either a file name or a sequence of hexadecimal RGB - * values separated by ',' and starting with '#'. - */ - DyePalette(const std::string &restrict pallete, - const uint8_t blockSize); - - A_DELETE_COPY(DyePalette) - - /** - * Gets a pixel color depending on its intensity. First color is - * implicitly black (0, 0, 0). - */ - void getColor(const unsigned int intensity, - unsigned int (&restrict color)[3]) const restrict2; - - /** - * Gets a pixel color depending on its intensity. - */ - void getColor(double intensity, - int (&restrict color)[3]) const restrict2; - - /** - * replace colors for SDL for S dye. - */ - void replaceSColorDefault(uint32_t *restrict pixels, - const int bufSize) const restrict2; - - /** - * replace colors for SDL for A dye. - */ - void replaceAColorDefault(uint32_t *restrict pixels, - const int bufSize) const restrict2; - -#ifdef SIMD_SUPPORTED - /** - * replace colors for SDL for S dye. - */ - __attribute__ ((target ("sse2"))) - void replaceSColorSse2(uint32_t *restrict pixels, - const int bufSize) const restrict2; - - /** - * replace colors for SDL for S dye. - */ - __attribute__ ((target ("avx2"))) - void replaceSColorAvx2(uint32_t *restrict pixels, - const int bufSize) const restrict2; - - /** - * replace colors for SDL for A dye. - */ - __attribute__ ((target ("sse2"))) - void replaceAColorSse2(uint32_t *restrict pixels, - const int bufSize) const restrict2; - - /** - * replace colors for SDL for A dye. - */ - __attribute__ ((target ("avx2"))) - void replaceAColorAvx2(uint32_t *restrict pixels, - const int bufSize) const restrict2; -#endif // SIMD_SUPPORTED - -#ifdef USE_OPENGL - /** - * replace colors for OpenGL for S dye. - */ - void replaceSOGLColorDefault(uint32_t *restrict pixels, - const int bufSize) const restrict2; -#ifdef SIMD_SUPPORTED - /** - * replace colors for OpenGL for A dye. - */ - __attribute__ ((target ("avx2"))) - void replaceAOGLColorAvx2(uint32_t *restrict pixels, - const int bufSize) const restrict2; - - /** - * replace colors for OpenGL for S dye. - */ - __attribute__ ((target ("sse2"))) - void replaceSOGLColorSse2(uint32_t *restrict pixels, - const int bufSize) const restrict2; - /** - * replace colors for OpenGL for S dye. - */ - __attribute__ ((target ("avx2"))) - void replaceSOGLColorAvx2(uint32_t *restrict pixels, - const int bufSize) const restrict2; - - /** - * replace colors for OpenGL for A dye. - */ - __attribute__ ((target ("sse2"))) - void replaceAOGLColorSse2(uint32_t *restrict pixels, - const int bufSize) const restrict2; -#endif // SIMD_SUPPORTED - - /** - * replace colors for OpenGL for A dye. - */ - void replaceAOGLColorDefault(uint32_t *restrict pixels, - const int bufSize) const restrict2; - -#endif // USE_OPENGL - - static unsigned int hexDecode(const signed char c) - noexcept2 A_CONST A_WARN_UNUSED; - - static void hexToColor(const std::string &restrict hexStr, - const uint8_t blockSize, - DyeColor &color) noexcept2; - - static void initFunctions(); - -#ifdef USE_OPENGL - static DyeFunctionPtr funcReplaceSOGLColor; - static DyeFunctionPtr funcReplaceSOGLColorSse2; - static DyeFunctionPtr funcReplaceSOGLColorAvx2; - static DyeFunctionPtr funcReplaceAOGLColor; - static DyeFunctionPtr funcReplaceAOGLColorSse2; - static DyeFunctionPtr funcReplaceAOGLColorAvx2; -#endif // USE_OPENGL - - static DyeFunctionPtr funcReplaceSColor; - static DyeFunctionPtr funcReplaceSColorSse2; - static DyeFunctionPtr funcReplaceSColorAvx2; - static DyeFunctionPtr funcReplaceAColor; - static DyeFunctionPtr funcReplaceAColorSse2; - static DyeFunctionPtr funcReplaceAColorAvx2; - -#ifndef UNITTESTS - private: -#endif // UNITTESTS - STD_VECTOR<DyeColor> mColors; -}; - -#endif // RESOURCES_DYE_DYEPALETTE_H diff --git a/src/resources/dye/dyepalette_replaceacolor.cpp b/src/resources/dye/dyepalette_replaceacolor.cpp deleted file mode 100644 index 256efb8bb..000000000 --- a/src/resources/dye/dyepalette_replaceacolor.cpp +++ /dev/null @@ -1,282 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2007-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "resources/dye/dyepalette.h" - -PRAGMA48(GCC diagnostic push) -PRAGMA48(GCC diagnostic ignored "-Wshadow") -#ifndef SDL_BIG_ENDIAN -#include <SDL_endian.h> -#endif // SDL_BYTEORDER -PRAGMA48(GCC diagnostic pop) - -#ifdef SIMD_SUPPORTED -// avx2 -#include <immintrin.h> -#endif // SIMD_SUPPORTED - -#include "debug.h" - -void DyePalette::replaceAColorDefault(uint32_t *restrict pixels, - const int bufSize) const restrict2 -{ - STD_VECTOR<DyeColor>::const_iterator it_end = mColors.end(); - const size_t sz = mColors.size(); - if ((sz == 0u) || (pixels == nullptr)) - return; - if ((sz % 2) != 0u) - -- it_end; - -#ifdef ENABLE_CILKPLUS - cilk_for (int ptr = 0; ptr < bufSize; ptr ++) - { - uint8_t *const p = reinterpret_cast<uint8_t *>(&pixels[ptr]); - const unsigned int data = pixels[ptr]; - - STD_VECTOR<DyeColor>::const_iterator it = mColors.begin(); - while (it != it_end) - { - const DyeColor &col = *it; - ++ it; - const DyeColor &col2 = *it; - -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int coldata = (col.value[3] << 24U) - | (col.value[2] << 16U) - | (col.value[1] << 8U) - | (col.value[0]); -#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 // SDL_BYTEORDER == SDL_BIG_ENDIAN - - if (data == coldata) - { - p[3] = col2.value[0]; - p[2] = col2.value[1]; - p[1] = col2.value[2]; - p[0] = col2.value[3]; - break; - } - - ++ it; - } - } - -#else // ENABLE_CILKPLUS - - for (const uint32_t *const p_end = pixels + CAST_SIZE(bufSize); - pixels != p_end; - ++pixels) - { - uint8_t *const p = reinterpret_cast<uint8_t *>(pixels); - const unsigned int data = *pixels; - - STD_VECTOR<DyeColor>::const_iterator it = mColors.begin(); - while (it != it_end) - { - const DyeColor &col = *it; - ++ it; - const DyeColor &col2 = *it; - -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int coldata = (col.value[3] << 24U) - | (col.value[2] << 16U) - | (col.value[1] << 8U) - | (col.value[0]); -#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 // SDL_BYTEORDER == SDL_BIG_ENDIAN - - if (data == coldata) - { - p[3] = col2.value[0]; - p[2] = col2.value[1]; - p[1] = col2.value[2]; - p[0] = col2.value[3]; - break; - } - - ++ it; - } - } -#endif // ENABLE_CILKPLUS -} - -#ifdef SIMD_SUPPORTED -/* -static void print256(const char *const text, const __m256i &val); -static void print256(const char *const text, const __m256i &val) -{ - printf("%s 0x%016llx%016llx%016llx%016llx\n", text, val[0], val[1], val[2], val[3]); -} -*/ - -__attribute__ ((target ("sse2"))) -void DyePalette::replaceAColorSse2(uint32_t *restrict pixels, - const int bufSize) const restrict2 -{ - STD_VECTOR<DyeColor>::const_iterator it_end = mColors.end(); - const size_t sz = mColors.size(); - if ((sz == 0u) || (pixels == nullptr)) - return; - if ((sz % 2) != 0u) - -- it_end; - const int mod = bufSize % 4; - const int bufEnd = bufSize - mod; - - for (int ptr = 0; ptr < bufEnd; ptr += 4) - { -// __m128i base = _mm_load_si128(reinterpret_cast<__m128i*>(pixels)); - __m128i base = _mm_loadu_si128(reinterpret_cast<__m128i*>( - &pixels[ptr])); - - STD_VECTOR<DyeColor>::const_iterator it = mColors.begin(); - while (it != it_end) - { - const DyeColor &col = *it; - ++ it; - const DyeColor &col2 = *it; - - __m128i newMask = _mm_set1_epi32(col2.valueA); - __m128i cmpMask = _mm_set1_epi32(col.valueA); - __m128i cmpRes = _mm_cmpeq_epi32(base, cmpMask); - __m128i srcAnd = _mm_andnot_si128(cmpRes, base); - __m128i dstAnd = _mm_and_si128(cmpRes, newMask); - base = _mm_or_si128(srcAnd, dstAnd); - - ++ it; - } -// _mm_store_si128(reinterpret_cast<__m128i*>(pixels), base); - _mm_storeu_si128(reinterpret_cast<__m128i*>(&pixels[ptr]), base); - } - - // complete end without simd - for (int ptr = bufSize - mod; ptr < bufSize; ptr ++) - { - uint8_t *const p = reinterpret_cast<uint8_t *>(&pixels[ptr]); - const unsigned int data = pixels[ptr]; - - STD_VECTOR<DyeColor>::const_iterator it = mColors.begin(); - while (it != it_end) - { - const DyeColor &col = *it; - ++ it; - const DyeColor &col2 = *it; - - const unsigned int coldata = (col.value[3]) | - (col.value[2] << 8U) | - (col.value[1] << 16U) | - (col.value[0] << 24U); - - if (data == coldata) - { - p[3] = col2.value[0]; - p[2] = col2.value[1]; - p[1] = col2.value[2]; - p[0] = col2.value[3]; - break; - } - - ++ it; - } - } -} - -__attribute__ ((target ("avx2"))) -void DyePalette::replaceAColorAvx2(uint32_t *restrict pixels, - const int bufSize) const restrict2 -{ - STD_VECTOR<DyeColor>::const_iterator it_end = mColors.end(); - const size_t sz = mColors.size(); - if ((sz == 0u) || (pixels == nullptr)) - return; - if ((sz % 2) != 0u) - -- it_end; - const int mod = bufSize % 8; - const int bufEnd = bufSize - mod; - - for (int ptr = 0; ptr < bufEnd; ptr += 8) - { -// __m256i base = _mm256_load_si256(reinterpret_cast<__m256i*>(pixels)); - __m256i base = _mm256_loadu_si256(reinterpret_cast<__m256i*>( - &pixels[ptr])); - - STD_VECTOR<DyeColor>::const_iterator it = mColors.begin(); - while (it != it_end) - { - const DyeColor &col = *it; - ++ it; - const DyeColor &col2 = *it; - - __m256i newMask = _mm256_set1_epi32(col2.valueA); - __m256i cmpMask = _mm256_set1_epi32(col.valueA); - __m256i cmpRes = _mm256_cmpeq_epi32(base, cmpMask); - __m256i srcAnd = _mm256_andnot_si256(cmpRes, base); - __m256i dstAnd = _mm256_and_si256(cmpRes, newMask); - base = _mm256_or_si256(srcAnd, dstAnd); - - ++ it; - } -// _mm256_store_si256(reinterpret_cast<__m256i*>(pixels), base); - _mm256_storeu_si256(reinterpret_cast<__m256i*>(&pixels[ptr]), base); - } - - // complete end without simd - for (int ptr = bufSize - mod; ptr < bufSize; ptr ++) - { - uint8_t *const p = reinterpret_cast<uint8_t *>(&pixels[ptr]); - const unsigned int data = pixels[ptr]; - - STD_VECTOR<DyeColor>::const_iterator it = mColors.begin(); - while (it != it_end) - { - const DyeColor &col = *it; - ++ it; - const DyeColor &col2 = *it; - - const unsigned int coldata = (col.value[3]) | - (col.value[2] << 8U) | - (col.value[1] << 16U) | - (col.value[0] << 24U); - - if (data == coldata) - { - p[3] = col2.value[0]; - p[2] = col2.value[1]; - p[1] = col2.value[2]; - p[0] = col2.value[3]; - break; - } - - ++ it; - } - } -} - -#endif // SIMD_SUPPORTED diff --git a/src/resources/dye/dyepalette_replaceaoglcolor.cpp b/src/resources/dye/dyepalette_replaceaoglcolor.cpp deleted file mode 100644 index 4d4588bb5..000000000 --- a/src/resources/dye/dyepalette_replaceaoglcolor.cpp +++ /dev/null @@ -1,398 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2007-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifdef USE_OPENGL - -#include "resources/dye/dyepalette.h" - -PRAGMA48(GCC diagnostic push) -PRAGMA48(GCC diagnostic ignored "-Wshadow") -#ifndef SDL_BIG_ENDIAN -#include <SDL_endian.h> -#endif // SDL_BYTEORDER -PRAGMA48(GCC diagnostic pop) - -#ifdef SIMD_SUPPORTED -// avx2 -#include <immintrin.h> -#endif // SIMD_SUPPORTED - -#include "debug.h" - -void DyePalette::replaceAOGLColorDefault(uint32_t *restrict pixels, - const int bufSize) const restrict2 -{ - STD_VECTOR<DyeColor>::const_iterator it_end = mColors.end(); - const size_t sz = mColors.size(); - if (sz == 0u || pixels == nullptr) - return; - if ((sz % 2) != 0u) - -- it_end; - -#ifdef ENABLE_CILKPLUS - cilk_for (int ptr = 0; ptr < bufSize; ptr ++) - { - uint8_t *const p = reinterpret_cast<uint8_t *>(&pixels[ptr]); - const unsigned int data = pixels[ptr]; - - STD_VECTOR<DyeColor>::const_iterator it = mColors.begin(); - while (it != it_end) - { - const DyeColor &col = *it; - ++ it; - const DyeColor &col2 = *it; - -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int coldata = (col.value[0] << 24U) - | (col.value[1] << 16U) - | (col.value[2] << 8U) - | col.value[3]; -#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 // SDL_BYTEORDER == SDL_BIG_ENDIAN - - if (data == coldata) - { - p[0] = col2.value[0]; - p[1] = col2.value[1]; - p[2] = col2.value[2]; - p[3] = col2.value[3]; - break; - } - - ++ it; - } - } - -#else // ENABLE_CILKPLUS - - for (const uint32_t *const p_end = pixels + CAST_SIZE(bufSize); - pixels != p_end; - ++pixels) - { - uint8_t *const p = reinterpret_cast<uint8_t *>(pixels); - const unsigned int data = *pixels; - - STD_VECTOR<DyeColor>::const_iterator it = mColors.begin(); - while (it != it_end) - { - const DyeColor &col = *it; - ++ it; - const DyeColor &col2 = *it; - -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int coldata = (col.value[0] << 24U) - | (col.value[1] << 16U) - | (col.value[2] << 8U) - | col.value[3]; -#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 // SDL_BYTEORDER == SDL_BIG_ENDIAN - - if (data == coldata) - { - p[0] = col2.value[0]; - p[1] = col2.value[1]; - p[2] = col2.value[2]; - p[3] = col2.value[3]; - break; - } - - ++ it; - } - } -#endif // ENABLE_CILKPLUS -} - -#ifdef SIMD_SUPPORTED -/* -static void print256(const char *const text, const __m256i &val); -static void print256(const char *const text, const __m256i &val) -{ - printf("%s 0x%016llx%016llx%016llx%016llx\n", text, val[0], val[1], val[2], val[3]); -} -*/ - -__attribute__ ((target ("sse2"))) -void DyePalette::replaceAOGLColorSse2(uint32_t *restrict pixels, - const int bufSize) const restrict2 -{ - STD_VECTOR<DyeColor>::const_iterator it_end = mColors.end(); - const size_t sz = mColors.size(); - if (sz == 0u || pixels == nullptr) - return; - if ((sz % 2) != 0u) - -- it_end; - - if (bufSize >= 8) - { - for (int ptr = 0; ptr < bufSize; ptr += 4) - { -// __m128i base = _mm_load_si128(reinterpret_cast<__m128i*>( -// &pixels[ptr])); - __m128i base = _mm_loadu_si128(reinterpret_cast<__m128i*>( - &pixels[ptr])); - - STD_VECTOR<DyeColor>::const_iterator it = mColors.begin(); - while (it != it_end) - { - const DyeColor &col = *it; - ++ it; - const DyeColor &col2 = *it; - - __m128i newMask = _mm_set1_epi32(col2.valueAOgl); - __m128i cmpMask = _mm_set1_epi32(col.valueAOgl); - __m128i cmpRes = _mm_cmpeq_epi32(base, cmpMask); - __m128i srcAnd = _mm_andnot_si128(cmpRes, base); - __m128i dstAnd = _mm_and_si128(cmpRes, newMask); - base = _mm_or_si128(srcAnd, dstAnd); - - ++ it; - } -// _mm_store_si128(reinterpret_cast<__m128i*>(&pixels[ptr]), base); - _mm_storeu_si128(reinterpret_cast<__m128i*>(&pixels[ptr]), base); - } - } - else - { -#ifdef ENABLE_CILKPLUS - cilk_for (int ptr = 0; ptr < bufSize; ptr ++) - { - uint8_t *const p = reinterpret_cast<uint8_t *>(&pixels[ptr]); - const unsigned int data = pixels[ptr]; - - STD_VECTOR<DyeColor>::const_iterator it = mColors.begin(); - while (it != it_end) - { - const DyeColor &col = *it; - ++ it; - const DyeColor &col2 = *it; - -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int coldata = (col.value[0] << 24U) - | (col.value[1] << 16U) - | (col.value[2] << 8U) - | col.value[3]; -#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 // SDL_BYTEORDER == SDL_BIG_ENDIAN - - if (data == coldata) - { - p[0] = col2.value[0]; - p[1] = col2.value[1]; - p[2] = col2.value[2]; - p[3] = col2.value[3]; - break; - } - - ++ it; - } - } - -#else // ENABLE_CILKPLUS - - for (const uint32_t *const p_end = pixels + CAST_SIZE(bufSize); - pixels != p_end; - ++pixels) - { - uint8_t *const p = reinterpret_cast<uint8_t *>(pixels); - const unsigned int data = *pixels; - - STD_VECTOR<DyeColor>::const_iterator it = mColors.begin(); - while (it != it_end) - { - const DyeColor &col = *it; - ++ it; - const DyeColor &col2 = *it; - -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int coldata = (col.value[0] << 24U) - | (col.value[1] << 16U) - | (col.value[2] << 8U) - | col.value[3]; -#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 // SDL_BYTEORDER == SDL_BIG_ENDIAN - - if (data == coldata) - { - p[0] = col2.value[0]; - p[1] = col2.value[1]; - p[2] = col2.value[2]; - p[3] = col2.value[3]; - break; - } - - ++ it; - } - } -#endif // ENABLE_CILKPLUS - } -} - -__attribute__ ((target ("avx2"))) -void DyePalette::replaceAOGLColorAvx2(uint32_t *restrict pixels, - const int bufSize) const restrict2 -{ - STD_VECTOR<DyeColor>::const_iterator it_end = mColors.end(); - const size_t sz = mColors.size(); - if (sz == 0u || pixels == nullptr) - return; - if ((sz % 2) != 0u) - -- it_end; - - if (bufSize >= 8) - { - for (int ptr = 0; ptr < bufSize; ptr += 8) - { -// __m256i base = _mm256_load_si256(reinterpret_cast<__m256i*>( -// &pixels[ptr])); - __m256i base = _mm256_loadu_si256(reinterpret_cast<__m256i*>( - &pixels[ptr])); - - STD_VECTOR<DyeColor>::const_iterator it = mColors.begin(); - while (it != it_end) - { - const DyeColor &col = *it; - ++ it; - const DyeColor &col2 = *it; - - __m256i newMask = _mm256_set1_epi32(col2.valueAOgl); - __m256i cmpMask = _mm256_set1_epi32(col.valueAOgl); - __m256i cmpRes = _mm256_cmpeq_epi32(base, cmpMask); - __m256i srcAnd = _mm256_andnot_si256(cmpRes, base); - __m256i dstAnd = _mm256_and_si256(cmpRes, newMask); - base = _mm256_or_si256(srcAnd, dstAnd); - - ++ it; - } -// _mm256_store_si256(reinterpret_cast<__m256i*>(&pixels[ptr]), -// base); - _mm256_storeu_si256(reinterpret_cast<__m256i*>(&pixels[ptr]), - base); - } - } - else - { -#ifdef ENABLE_CILKPLUS - cilk_for (int ptr = 0; ptr < bufSize; ptr ++) - { - uint8_t *const p = reinterpret_cast<uint8_t *>(&pixels[ptr]); - const unsigned int data = pixels[ptr]; - - STD_VECTOR<DyeColor>::const_iterator it = mColors.begin(); - while (it != it_end) - { - const DyeColor &col = *it; - ++ it; - const DyeColor &col2 = *it; - -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int coldata = (col.value[0] << 24U) - | (col.value[1] << 16U) - | (col.value[2] << 8U) - | col.value[3]; -#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 // SDL_BYTEORDER == SDL_BIG_ENDIAN - - if (data == coldata) - { - p[0] = col2.value[0]; - p[1] = col2.value[1]; - p[2] = col2.value[2]; - p[3] = col2.value[3]; - break; - } - - ++ it; - } - } - -#else // ENABLE_CILKPLUS - - for (const uint32_t *const p_end = pixels + CAST_SIZE(bufSize); - pixels != p_end; - ++pixels) - { - uint8_t *const p = reinterpret_cast<uint8_t *>(pixels); - const unsigned int data = *pixels; - - STD_VECTOR<DyeColor>::const_iterator it = mColors.begin(); - while (it != it_end) - { - const DyeColor &col = *it; - ++ it; - const DyeColor &col2 = *it; - -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int coldata = (col.value[0] << 24U) - | (col.value[1] << 16U) - | (col.value[2] << 8U) - | col.value[3]; -#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 // SDL_BYTEORDER == SDL_BIG_ENDIAN - - if (data == coldata) - { - p[0] = col2.value[0]; - p[1] = col2.value[1]; - p[2] = col2.value[2]; - p[3] = col2.value[3]; - break; - } - - ++ it; - } - } -#endif // ENABLE_CILKPLUS - } -} - -#endif // SIMD_SUPPORTED -#endif // USE_OPENGL diff --git a/src/resources/dye/dyepalette_replacescolor.cpp b/src/resources/dye/dyepalette_replacescolor.cpp deleted file mode 100644 index 1d1c2676e..000000000 --- a/src/resources/dye/dyepalette_replacescolor.cpp +++ /dev/null @@ -1,300 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2007-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "resources/dye/dyepalette.h" - -PRAGMA48(GCC diagnostic push) -PRAGMA48(GCC diagnostic ignored "-Wshadow") -#ifndef SDL_BIG_ENDIAN -#include <SDL_endian.h> -#endif // SDL_BYTEORDER -PRAGMA48(GCC diagnostic pop) - -#ifdef SIMD_SUPPORTED -// avx2 -#include <immintrin.h> -#endif // SIMD_SUPPORTED - -#include "debug.h" - -void DyePalette::replaceSColorDefault(uint32_t *restrict pixels, - const int bufSize) const restrict2 -{ - STD_VECTOR<DyeColor>::const_iterator it_end = mColors.end(); - const size_t sz = mColors.size(); - if (sz == 0u || pixels == nullptr) - return; - if ((sz % 2) != 0u) - -- it_end; - -#ifdef ENABLE_CILKPLUS - cilk_for (int ptr = 0; ptr < bufSize; ptr ++) - { - uint8_t *const p = reinterpret_cast<uint8_t *>(&pixels[ptr]); -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int data = pixels[ptr] & 0x00ffffff; -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - const unsigned int data = pixels[ptr] & 0xffffff00; -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - - STD_VECTOR<DyeColor>::const_iterator it = mColors.begin(); - while (it != it_end) - { - const DyeColor &col = *it; - ++ it; - const DyeColor &col2 = *it; - -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int coldata = (col.value[2] << 16U) - | (col.value[1] << 8U) | (col.value[0]); -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int coldata = (col.value[2] << 8U) - | (col.value[1] << 16U) | (col.value[0] << 24U); -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - - if (data == coldata) - { - p[3] = col2.value[0]; - p[2] = col2.value[1]; - p[1] = col2.value[2]; - break; - } - ++ it; - } - } -#else // ENABLE_CILKPLUS - - for (const uint32_t *const p_end = pixels + CAST_SIZE(bufSize); - pixels != p_end; - ++ pixels) - { - uint8_t *const p = reinterpret_cast<uint8_t *>(pixels); -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int data = (*pixels) & 0x00ffffff; -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - const unsigned int data = (*pixels) & 0xffffff00; -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - - STD_VECTOR<DyeColor>::const_iterator it = mColors.begin(); - while (it != it_end) - { - const DyeColor &col = *it; - ++ it; - const DyeColor &col2 = *it; - -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int coldata = (col.value[2] << 16U) - | (col.value[1] << 8U) | (col.value[0]); -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - const unsigned int coldata = (col.value[2] << 8U) - | (col.value[1] << 16U) | (col.value[0] << 24U); -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - - if (data == coldata) - { - p[3] = col2.value[0]; - p[2] = col2.value[1]; - p[1] = col2.value[2]; - break; - } - - ++ it; - } - } -#endif // ENABLE_CILKPLUS -} - -#ifdef SIMD_SUPPORTED -/* -static void print256(const char *const text, const __m256i &val); -static void print256(const char *const text, const __m256i &val) -{ - printf("%s 0x%016llx%016llx%016llx%016llx\n", text, val[0], val[1], val[2], val[3]); -} -*/ - -__attribute__ ((target ("sse2"))) -void DyePalette::replaceSColorSse2(uint32_t *restrict pixels, - const int bufSize) const restrict2 -{ - STD_VECTOR<DyeColor>::const_iterator it_end = mColors.end(); - const size_t sz = mColors.size(); - if (sz == 0u || pixels == nullptr) - return; - if ((sz % 2) != 0u) - -- it_end; - const int mod = bufSize % 8; - const int bufEnd = bufSize - mod; - - for (int ptr = 0; ptr < bufEnd; ptr += 4) - { - __m128i mask = _mm_set1_epi32(0xffffff00); -// __m128i base = _mm_load_si128(reinterpret_cast<__m128i*>(pixels)); - __m128i base = _mm_loadu_si128(reinterpret_cast<__m128i*>( - &pixels[ptr])); - - STD_VECTOR<DyeColor>::const_iterator it = mColors.begin(); - while (it != it_end) - { - const DyeColor &col = *it; - ++ it; - const DyeColor &col2 = *it; - - __m128i base2 = _mm_and_si128(mask, base); - __m128i newMask = _mm_set1_epi32(col2.valueS); - __m128i cmpMask = _mm_set1_epi32(col.valueS); - __m128i cmpRes = _mm_cmpeq_epi32(base2, cmpMask); - cmpRes = _mm_and_si128(mask, cmpRes); - __m128i srcAnd = _mm_andnot_si128(cmpRes, base); - __m128i dstAnd = _mm_and_si128(cmpRes, newMask); - base = _mm_or_si128(srcAnd, dstAnd); - ++ it; - } -// _mm_store_si128(reinterpret_cast<__m128i*>(pixels), base); - _mm_storeu_si128(reinterpret_cast<__m128i*>(&pixels[ptr]), base); - } - - // complete end without simd - for (int ptr = bufSize - mod; ptr < bufSize; ptr ++) - { - uint8_t *const p = reinterpret_cast<uint8_t *>(&pixels[ptr]); -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int data = pixels[ptr] & 0x00ffffff; -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - const unsigned int data = pixels[ptr] & 0xffffff00; -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - - STD_VECTOR<DyeColor>::const_iterator it = mColors.begin(); - while (it != it_end) - { - const DyeColor &col = *it; - ++ it; - const DyeColor &col2 = *it; - -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int coldata = (col.value[2] << 16U) - | (col.value[1] << 8U) | (col.value[0]); -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - const unsigned int coldata = (col.value[2] << 8U) - | (col.value[1] << 16U) | (col.value[0] << 24U); -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - - if (data == coldata) - { - p[3] = col2.value[0]; - p[2] = col2.value[1]; - p[1] = col2.value[2]; - break; - } - - ++ it; - } - } -} - -__attribute__ ((target ("avx2"))) -void DyePalette::replaceSColorAvx2(uint32_t *restrict pixels, - const int bufSize) const restrict2 -{ - STD_VECTOR<DyeColor>::const_iterator it_end = mColors.end(); - const size_t sz = mColors.size(); - if (sz == 0u || pixels == nullptr) - return; - if ((sz % 2) != 0u) - -- it_end; - const int mod = bufSize % 8; - const int bufEnd = bufSize - mod; - - for (int ptr = 0; ptr < bufEnd; ptr += 8) - { - __m256i mask = _mm256_set1_epi32(0xffffff00); -// __m256i base = _mm256_load_si256(reinterpret_cast<__m256i*>(pixels)); - __m256i base = _mm256_loadu_si256(reinterpret_cast<__m256i*>( - &pixels[ptr])); - - STD_VECTOR<DyeColor>::const_iterator it = mColors.begin(); - while (it != it_end) - { - const DyeColor &col = *it; - ++ it; - const DyeColor &col2 = *it; - - __m256i base2 = _mm256_and_si256(mask, base); - __m256i newMask = _mm256_set1_epi32(col2.valueS); - __m256i cmpMask = _mm256_set1_epi32(col.valueS); - __m256i cmpRes = _mm256_cmpeq_epi32(base2, cmpMask); - cmpRes = _mm256_and_si256(mask, cmpRes); - __m256i srcAnd = _mm256_andnot_si256(cmpRes, base); - __m256i dstAnd = _mm256_and_si256(cmpRes, newMask); - base = _mm256_or_si256(srcAnd, dstAnd); - ++ it; - } -// _mm256_store_si256(reinterpret_cast<__m256i*>(pixels), base); - _mm256_storeu_si256(reinterpret_cast<__m256i*>(&pixels[ptr]), base); - } - - // complete end without simd - for (int ptr = bufSize - mod; ptr < bufSize; ptr ++) - { - uint8_t *const p = reinterpret_cast<uint8_t *>(&pixels[ptr]); -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int data = pixels[ptr] & 0x00ffffff; -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - const unsigned int data = pixels[ptr] & 0xffffff00; -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - - STD_VECTOR<DyeColor>::const_iterator it = mColors.begin(); - while (it != it_end) - { - const DyeColor &col = *it; - ++ it; - const DyeColor &col2 = *it; - -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int coldata = (col.value[2] << 16U) - | (col.value[1] << 8U) | (col.value[0]); -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - const unsigned int coldata = (col.value[2] << 8U) - | (col.value[1] << 16U) | (col.value[0] << 24U); -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - - if (data == coldata) - { - p[3] = col2.value[0]; - p[2] = col2.value[1]; - p[1] = col2.value[2]; - break; - } - - ++ it; - } - } -} - -#endif // SIMD_SUPPORTED diff --git a/src/resources/dye/dyepalette_replacesoglcolor.cpp b/src/resources/dye/dyepalette_replacesoglcolor.cpp deleted file mode 100644 index b5c2c621a..000000000 --- a/src/resources/dye/dyepalette_replacesoglcolor.cpp +++ /dev/null @@ -1,402 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2007-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifdef USE_OPENGL - -#include "resources/dye/dyepalette.h" - -PRAGMA48(GCC diagnostic push) -PRAGMA48(GCC diagnostic ignored "-Wshadow") -#ifndef SDL_BIG_ENDIAN -#include <SDL_endian.h> -#endif // SDL_BYTEORDER -PRAGMA48(GCC diagnostic pop) - -#ifdef SIMD_SUPPORTED -// avx2 -#include <immintrin.h> -#endif // SIMD_SUPPORTED - -#include "debug.h" - -void DyePalette::replaceSOGLColorDefault(uint32_t *restrict pixels, - const int bufSize) const restrict2 -{ - STD_VECTOR<DyeColor>::const_iterator it_end = mColors.end(); - const size_t sz = mColors.size(); - if ((sz == 0u) || (pixels == nullptr)) - return; - if ((sz % 2) != 0u) - -- it_end; - -#ifdef ENABLE_CILKPLUS - cilk_for (int ptr = 0; ptr < bufSize; ptr ++) - { - uint8_t *const p = reinterpret_cast<uint8_t *>(&pixels[ptr]); -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int data = (pixels[ptr]) & 0xffffff00; -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - const unsigned int data = (pixels[ptr]) & 0x00ffffff; -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - - STD_VECTOR<DyeColor>::const_iterator it = mColors.begin(); - while (it != it_end) - { - const DyeColor &col = *it; - ++ it; - const DyeColor &col2 = *it; - -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int coldata = (col.value[0] << 24) - | (col.value[1] << 16) | (col.value[2] << 8); -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - const unsigned int coldata = (col.value[0]) - | (col.value[1] << 8) | (col.value[2] << 16); -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - - if (data == coldata) - { - p[0] = col2.value[0]; - p[1] = col2.value[1]; - p[2] = col2.value[2]; - break; - } - - ++ it; - } - } - -#else // ENABLE_CILKPLUS - - for (const uint32_t *const p_end = pixels + CAST_SIZE(bufSize); - pixels != p_end; - ++pixels) - { - uint8_t *const p = reinterpret_cast<uint8_t *>(pixels); -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int data = (*pixels) & 0xffffff00; -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - const unsigned int data = (*pixels) & 0x00ffffff; -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - - STD_VECTOR<DyeColor>::const_iterator it = mColors.begin(); - while (it != it_end) - { - const DyeColor &col = *it; - ++ it; - const DyeColor &col2 = *it; - -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int coldata = (col.value[0] << 24) - | (col.value[1] << 16) | (col.value[2] << 8); -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - const unsigned int coldata = (col.value[0]) - | (col.value[1] << 8) | (col.value[2] << 16); -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - - if (data == coldata) - { - p[0] = col2.value[0]; - p[1] = col2.value[1]; - p[2] = col2.value[2]; - break; - } - - ++ it; - } - } -#endif // ENABLE_CILKPLUS -} - -#ifdef SIMD_SUPPORTED -/* -static void print256(const char *const text, const __m256i &val); -static void print256(const char *const text, const __m256i &val) -{ - printf("%s 0x%016llx%016llx%016llx%016llx\n", text, val[0], val[1], val[2], val[3]); -} -*/ - -__attribute__ ((target ("sse2"))) -void DyePalette::replaceSOGLColorSse2(uint32_t *restrict pixels, - const int bufSize) const restrict2 -{ - STD_VECTOR<DyeColor>::const_iterator it_end = mColors.end(); - const size_t sz = mColors.size(); - if ((sz == 0u) || (pixels == nullptr)) - return; - if ((sz % 2) != 0u) - -- it_end; - - if (bufSize >= 8) - { - for (int ptr = 0; ptr < bufSize; ptr += 4) - { - __m128i mask = _mm_set1_epi32(0x00ffffff); -// __m128i base = _mm_load_si128(reinterpret_cast<__m128i*>( -// &pixels[ptr])); - __m128i base = _mm_loadu_si128(reinterpret_cast<__m128i*>( - &pixels[ptr])); - - STD_VECTOR<DyeColor>::const_iterator it = mColors.begin(); - while (it != it_end) - { - const DyeColor &col = *it; - ++ it; - const DyeColor &col2 = *it; - - __m128i base2 = _mm_and_si128(mask, base); - __m128i newMask = _mm_set1_epi32(col2.valueSOgl); - __m128i cmpMask = _mm_set1_epi32(col.valueSOgl); - __m128i cmpRes = _mm_cmpeq_epi32(base2, cmpMask); - cmpRes = _mm_and_si128(mask, cmpRes); - __m128i srcAnd = _mm_andnot_si128(cmpRes, base); - __m128i dstAnd = _mm_and_si128(cmpRes, newMask); - base = _mm_or_si128(srcAnd, dstAnd); - ++ it; - } -// _mm_store_si128(reinterpret_cast<__m128i*>(&pixels[ptr]), base); - _mm_storeu_si128(reinterpret_cast<__m128i*>(&pixels[ptr]), base); - } - } - else - { -#ifdef ENABLE_CILKPLUS - cilk_for (int ptr = 0; ptr < bufSize; ptr ++) - { - uint8_t *const p = reinterpret_cast<uint8_t *>(&pixels[ptr]); -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int data = (pixels[ptr]) & 0xffffff00; -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - const unsigned int data = (pixels[ptr]) & 0x00ffffff; -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - - STD_VECTOR<DyeColor>::const_iterator it = mColors.begin(); - while (it != it_end) - { - const DyeColor &col = *it; - ++ it; - const DyeColor &col2 = *it; - -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int coldata = (col.value[0] << 24) - | (col.value[1] << 16) | (col.value[2] << 8); -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - const unsigned int coldata = (col.value[0]) - | (col.value[1] << 8) | (col.value[2] << 16); -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - - if (data == coldata) - { - p[0] = col2.value[0]; - p[1] = col2.value[1]; - p[2] = col2.value[2]; - break; - } - - ++ it; - } - } - -#else // ENABLE_CILKPLUS - - for (const uint32_t *const p_end = pixels + CAST_SIZE(bufSize); - pixels != p_end; - ++pixels) - { - uint8_t *const p = reinterpret_cast<uint8_t *>(pixels); -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int data = (*pixels) & 0xffffff00; -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - const unsigned int data = (*pixels) & 0x00ffffff; -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - - STD_VECTOR<DyeColor>::const_iterator it = mColors.begin(); - while (it != it_end) - { - const DyeColor &col = *it; - ++ it; - const DyeColor &col2 = *it; - -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int coldata = (col.value[0] << 24) - | (col.value[1] << 16) | (col.value[2] << 8); -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - const unsigned int coldata = (col.value[0]) - | (col.value[1] << 8) | (col.value[2] << 16); -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - - if (data == coldata) - { - p[0] = col2.value[0]; - p[1] = col2.value[1]; - p[2] = col2.value[2]; - break; - } - - ++ it; - } - } -#endif // ENABLE_CILKPLUS - } -} - -__attribute__ ((target ("avx2"))) -void DyePalette::replaceSOGLColorAvx2(uint32_t *restrict pixels, - const int bufSize) const restrict2 -{ - STD_VECTOR<DyeColor>::const_iterator it_end = mColors.end(); - const size_t sz = mColors.size(); - if ((sz == 0u) || (pixels == nullptr)) - return; - if ((sz % 2) != 0u) - -- it_end; - - if (bufSize >= 8) - { - for (int ptr = 0; ptr < bufSize; ptr += 8) - { - __m256i mask = _mm256_set1_epi32(0x00ffffff); -// __m256i base = _mm256_load_si256(reinterpret_cast<__m256i*>( -// &pixels[ptr])); - __m256i base = _mm256_loadu_si256(reinterpret_cast<__m256i*>( - &pixels[ptr])); - - STD_VECTOR<DyeColor>::const_iterator it = mColors.begin(); - while (it != it_end) - { - const DyeColor &col = *it; - ++ it; - const DyeColor &col2 = *it; - - __m256i base2 = _mm256_and_si256(mask, base); - __m256i newMask = _mm256_set1_epi32(col2.valueSOgl); - __m256i cmpMask = _mm256_set1_epi32(col.valueSOgl); - __m256i cmpRes = _mm256_cmpeq_epi32(base2, cmpMask); - cmpRes = _mm256_and_si256(mask, cmpRes); - __m256i srcAnd = _mm256_andnot_si256(cmpRes, base); - __m256i dstAnd = _mm256_and_si256(cmpRes, newMask); - base = _mm256_or_si256(srcAnd, dstAnd); - ++ it; - } -// _mm256_store_si256(reinterpret_cast<__m256i*>(&pixels[ptr]), -// base); - _mm256_storeu_si256(reinterpret_cast<__m256i*>(&pixels[ptr]), - base); - } - } - else - { -#ifdef ENABLE_CILKPLUS - cilk_for (int ptr = 0; ptr < bufSize; ptr ++) - { - uint8_t *const p = reinterpret_cast<uint8_t *>(&pixels[ptr]); -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int data = (pixels[ptr]) & 0xffffff00; -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - const unsigned int data = (pixels[ptr]) & 0x00ffffff; -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - - STD_VECTOR<DyeColor>::const_iterator it = mColors.begin(); - while (it != it_end) - { - const DyeColor &col = *it; - ++ it; - const DyeColor &col2 = *it; - -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int coldata = (col.value[0] << 24) - | (col.value[1] << 16) | (col.value[2] << 8); -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - const unsigned int coldata = (col.value[0]) - | (col.value[1] << 8) | (col.value[2] << 16); -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - - if (data == coldata) - { - p[0] = col2.value[0]; - p[1] = col2.value[1]; - p[2] = col2.value[2]; - break; - } - - ++ it; - } - } - -#else // ENABLE_CILKPLUS - - for (const uint32_t *const p_end = pixels + CAST_SIZE(bufSize); - pixels != p_end; - ++pixels) - { - uint8_t *const p = reinterpret_cast<uint8_t *>(pixels); -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int data = (*pixels) & 0xffffff00; -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - const unsigned int data = (*pixels) & 0x00ffffff; -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - - STD_VECTOR<DyeColor>::const_iterator it = mColors.begin(); - while (it != it_end) - { - const DyeColor &col = *it; - ++ it; - const DyeColor &col2 = *it; - -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - const unsigned int coldata = (col.value[0] << 24) - | (col.value[1] << 16) | (col.value[2] << 8); -#else // SDL_BYTEORDER == SDL_BIG_ENDIAN - - const unsigned int coldata = (col.value[0]) - | (col.value[1] << 8) | (col.value[2] << 16); -#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN - - if (data == coldata) - { - p[0] = col2.value[0]; - p[1] = col2.value[1]; - p[2] = col2.value[2]; - break; - } - - ++ it; - } - } -#endif // ENABLE_CILKPLUS - } -} - -#endif // SIMD_SUPPORTED -#endif // USE_OPENGL diff --git a/src/resources/dye/dyepaletteptr.h b/src/resources/dye/dyepaletteptr.h deleted file mode 100644 index baf81549d..000000000 --- a/src/resources/dye/dyepaletteptr.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2011-2017 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef RESOURCES_DYE_DYEPALETTEPTR_H -#define RESOURCES_DYE_DYEPALETTEPTR_H - -#include "localconsts.h" - -class DyePalette; - -typedef void (DyePalette::*DyeFunctionPtr) (uint32_t *restrict pixels, - const int bufSize) const restrict2; - -#endif // RESOURCES_DYE_DYEPALETTEPTR_H |