summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-12-21 23:02:27 +0300
committerAndrei Karas <akaras@inbox.ru>2016-12-21 23:15:11 +0300
commit6addecc3615d5e3f9caaafd39aa639c8ff49115b (patch)
treed448d51378fbf6b05215109632734212b51d27e7 /src/resources
parente59b20b4cff4bf54c0b2ea91dbf09345da9d5fe4 (diff)
downloadplus-6addecc3615d5e3f9caaafd39aa639c8ff49115b.tar.gz
plus-6addecc3615d5e3f9caaafd39aa639c8ff49115b.tar.bz2
plus-6addecc3615d5e3f9caaafd39aa639c8ff49115b.tar.xz
plus-6addecc3615d5e3f9caaafd39aa639c8ff49115b.zip
Use precalculated values for A and S dyes.
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/dye/dyecolor.h33
-rw-r--r--src/resources/dye/dyepalette.cpp1
-rw-r--r--src/resources/dye/dyepalette_replaceacolor.cpp12
-rw-r--r--src/resources/dye/dyepalette_replaceaoglcolor.cpp12
-rw-r--r--src/resources/dye/dyepalette_replacescolor.cpp12
-rw-r--r--src/resources/dye/dyepalette_replacesoglcolor.cpp12
6 files changed, 35 insertions, 47 deletions
diff --git a/src/resources/dye/dyecolor.h b/src/resources/dye/dyecolor.h
index 11e12a038..11257fc22 100644
--- a/src/resources/dye/dyecolor.h
+++ b/src/resources/dye/dyecolor.h
@@ -27,42 +27,61 @@
#include "localconsts.h"
+#define buildHex(a, b, c, d) \
+ (a) * 16777216U + (b) * 65536U + (c) * 256U + CAST_U32(d)
+
struct DyeColor final
{
- DyeColor() noexcept2
+ DyeColor() noexcept2 :
+ valueA(buildHex(0, 0, 0, 255)),
+ valueS(buildHex(0, 0, 0, 0)),
+ valueSOgl(buildHex(0, 0, 0, 0))
{
value[3] = 255;
}
DyeColor(const uint8_t r,
const uint8_t g,
- const uint8_t b) noexcept2
+ const uint8_t b) noexcept2 :
+ valueA(buildHex(r, g, b, 255)),
+ valueS(buildHex(r, g, b, 0)),
+ valueSOgl(buildHex(0, b, g, r))
{
value[0] = r;
value[1] = g;
value[2] = b;
value[3] = 255;
-// value2 = buildHex(r, g, b, 255);
}
DyeColor(const uint8_t r,
const uint8_t g,
const uint8_t b,
- const uint8_t a) noexcept2
+ const uint8_t a) noexcept2 :
+ valueA(buildHex(r, g, b, a)),
+ valueS(buildHex(r, g, b, 0)),
+ valueSOgl(buildHex(0, b, g, r))
{
value[0] = r;
value[1] = g;
value[2] = b;
value[3] = a;
-// value2 = buildHex(r, g, b, a);
+ }
+
+ void update()
+ {
+ valueA = buildHex(value[0], value[1], value[2], value[3]);
+ valueS = buildHex(value[0], value[1], value[2], 0);
+ valueSOgl = buildHex(0, value[2], value[1], value[0]);
}
union
{
uint8_t value[4];
- uint32_t value1;
+ uint32_t valueAOgl;
};
-// uint32_t value2;
+ 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
index 76f82b439..28efd76ba 100644
--- a/src/resources/dye/dyepalette.cpp
+++ b/src/resources/dye/dyepalette.cpp
@@ -109,6 +109,7 @@ void DyePalette::hexToColor(const std::string &restrict hexStr,
hexDecode(hexStr[i]) << 4)
+ hexDecode(hexStr[i + 1]));
}
+ color.update();
}
unsigned int DyePalette::hexDecode(const signed char c) noexcept2
diff --git a/src/resources/dye/dyepalette_replaceacolor.cpp b/src/resources/dye/dyepalette_replaceacolor.cpp
index f98c52343..7c24d6c1f 100644
--- a/src/resources/dye/dyepalette_replaceacolor.cpp
+++ b/src/resources/dye/dyepalette_replaceacolor.cpp
@@ -31,14 +31,6 @@
#ifdef __x86_64__
// avx2
#include "immintrin.h"
-
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
-#define buildHex(a, b, c, d) \
- (d) * 16777216U + (c) * 65536U + (b) * 256U + CAST_U32(a)
-#else // SDL_BYTEORDER == SDL_BIG_ENDIAN
-#define buildHex(a, b, c, d) \
- (a) * 16777216U + (b) * 65536U + (c) * 256U + CAST_U32(d)
-#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN
#endif // __x86_64__
#include "debug.h"
@@ -177,8 +169,8 @@ void DyePalette::replaceAColorSimd(uint32_t *restrict pixels,
++ it;
const DyeColor &col2 = *it;
- __m256i newMask = _mm256_set1_epi32(buildHex(col2.value[0], col2.value[1], col2.value[2], col2.value[3]));
- __m256i cmpMask = _mm256_set1_epi32(buildHex(col.value[0], col.value[1], col.value[2], col.value[3]));
+ __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);
diff --git a/src/resources/dye/dyepalette_replaceaoglcolor.cpp b/src/resources/dye/dyepalette_replaceaoglcolor.cpp
index 2b2d7a54c..8ed7af643 100644
--- a/src/resources/dye/dyepalette_replaceaoglcolor.cpp
+++ b/src/resources/dye/dyepalette_replaceaoglcolor.cpp
@@ -33,14 +33,6 @@
#ifdef __x86_64__
// avx2
#include "immintrin.h"
-
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
-#define buildHex(a, b, c, d) \
- (d) * 16777216U + (c) * 65536U + (b) * 256U + CAST_U32(a)
-#else // SDL_BYTEORDER == SDL_BIG_ENDIAN
-#define buildHex(a, b, c, d) \
- (a) * 16777216U + (b) * 65536U + (c) * 256U + CAST_U32(d)
-#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN
#endif // __x86_64__
#include "debug.h"
@@ -185,8 +177,8 @@ void DyePalette::replaceAOGLColorSimd(uint32_t *restrict pixels,
++ it;
const DyeColor &col2 = *it;
- __m256i newMask = _mm256_set1_epi32(buildHex(col2.value[3], col2.value[2], col2.value[1], col2.value[0]));
- __m256i cmpMask = _mm256_set1_epi32(buildHex(col.value[3], col.value[2], col.value[1], col.value[0]));
+ __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);
diff --git a/src/resources/dye/dyepalette_replacescolor.cpp b/src/resources/dye/dyepalette_replacescolor.cpp
index 22f4e6ac4..02412b186 100644
--- a/src/resources/dye/dyepalette_replacescolor.cpp
+++ b/src/resources/dye/dyepalette_replacescolor.cpp
@@ -29,14 +29,6 @@
#ifdef __x86_64__
// avx2
#include "immintrin.h"
-
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
-#define buildHex(a, b, c, d) \
- (d) * 16777216U + (c) * 65536U + (b) * 256U + CAST_U32(a)
-#else // SDL_BYTEORDER == SDL_BIG_ENDIAN
-#define buildHex(a, b, c, d) \
- (a) * 16777216U + (b) * 65536U + (c) * 256U + CAST_U32(d)
-#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN
#endif // __x86_64__
#include "debug.h"
@@ -178,9 +170,9 @@ void DyePalette::replaceSColorSimd(uint32_t *restrict pixels,
__m256i base2 = _mm256_and_si256(mask, base);
//print256("base2 ", base2);
- __m256i newMask = _mm256_set1_epi32(buildHex(col2.value[0], col2.value[1], col2.value[2], 0));
+ __m256i newMask = _mm256_set1_epi32(col2.valueS);
//print256("newMask ", newMask);
- __m256i cmpMask = _mm256_set1_epi32(buildHex(col.value[0], col.value[1], col.value[2], 0));
+ __m256i cmpMask = _mm256_set1_epi32(col.valueS);
//print256("cmpMask ", cmpMask);
__m256i cmpRes = _mm256_cmpeq_epi32(base2, cmpMask);
//print256("cmpRes ", cmpRes);
diff --git a/src/resources/dye/dyepalette_replacesoglcolor.cpp b/src/resources/dye/dyepalette_replacesoglcolor.cpp
index a023d8f79..899286240 100644
--- a/src/resources/dye/dyepalette_replacesoglcolor.cpp
+++ b/src/resources/dye/dyepalette_replacesoglcolor.cpp
@@ -31,14 +31,6 @@
#ifdef __x86_64__
// avx2
#include "immintrin.h"
-
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
-#define buildHex(a, b, c, d) \
- (d) * 16777216U + (c) * 65536U + (b) * 256U + CAST_U32(a)
-#else // SDL_BYTEORDER == SDL_BIG_ENDIAN
-#define buildHex(a, b, c, d) \
- (a) * 16777216U + (b) * 65536U + (c) * 256U + CAST_U32(d)
-#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN
#endif // __x86_64__
#include "debug.h"
@@ -186,9 +178,9 @@ void DyePalette::replaceSOGLColorSimd(uint32_t *restrict pixels,
__m256i base2 = _mm256_and_si256(mask, base);
//print256("base2 ", base2);
- __m256i newMask = _mm256_set1_epi32(buildHex(0, col2.value[2], col2.value[1], col2.value[0]));
+ __m256i newMask = _mm256_set1_epi32(col2.valueSOgl);
//print256("newMask ", newMask);
- __m256i cmpMask = _mm256_set1_epi32(buildHex(0, col.value[2], col.value[1], col.value[0]));
+ __m256i cmpMask = _mm256_set1_epi32(col.valueSOgl);
//print256("cmpMask ", cmpMask);
__m256i cmpRes = _mm256_cmpeq_epi32(base2, cmpMask);
//print256("cmpRes ", cmpRes);