GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/dye/dyepalette.h Lines: 1 1 100.0 %
Date: 2017-11-29 Branches: 0 0 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2007-2009  The Mana World Development Team
4
 *  Copyright (C) 2009-2010  The Mana Developers
5
 *  Copyright (C) 2011-2017  The ManaPlus Developers
6
 *
7
 *  This file is part of The ManaPlus Client.
8
 *
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
#ifndef RESOURCES_DYE_DYEPALETTE_H
24
#define RESOURCES_DYE_DYEPALETTE_H
25
26
#include "resources/dye/dyecolor.h"
27
28
#include "utils/vector.h"
29
30
#include "resources/dye/dyepaletteptr.h"
31
32
#include <string>
33
34
#include "localconsts.h"
35
36
#define DYEPALETTE(palette, color) \
37
    ((palette).*DyePalette::funcReplace##color)
38
39
#define DYEPALETTEP(palette, color) \
40
    ((palette)->*DyePalette::funcReplace##color)
41
42
/**
43
 * Class for performing a linear interpolation between colors.
44
 */
45
9760
class DyePalette final
46
{
47
    public:
48
        /**
49
         * Creates a palette based on the given string.
50
         * The string is either a file name or a sequence of hexadecimal RGB
51
         * values separated by ',' and starting with '#'.
52
         */
53
        DyePalette(const std::string &restrict pallete,
54
                   const uint8_t blockSize);
55
56
        A_DELETE_COPY(DyePalette)
57
58
        /**
59
         * Gets a pixel color depending on its intensity. First color is
60
         * implicitly black (0, 0, 0).
61
         */
62
        void getColor(const unsigned int intensity,
63
                      unsigned int (&restrict color)[3]) const restrict2;
64
65
        /**
66
         * Gets a pixel color depending on its intensity.
67
         */
68
        void getColor(double intensity,
69
                      int (&restrict color)[3]) const restrict2;
70
71
        /**
72
         * replace colors for SDL for S dye.
73
         */
74
        void replaceSColorDefault(uint32_t *restrict pixels,
75
                                  const int bufSize) const restrict2;
76
77
        /**
78
         * replace colors for SDL for A dye.
79
         */
80
        void replaceAColorDefault(uint32_t *restrict pixels,
81
                                  const int bufSize) const restrict2;
82
83
#ifdef SIMD_SUPPORTED
84
        /**
85
         * replace colors for SDL for S dye.
86
         */
87
        __attribute__ ((target ("sse2")))
88
        void replaceSColorSse2(uint32_t *restrict pixels,
89
                               const int bufSize) const restrict2;
90
91
        /**
92
         * replace colors for SDL for S dye.
93
         */
94
        __attribute__ ((target ("avx2")))
95
        void replaceSColorAvx2(uint32_t *restrict pixels,
96
                               const int bufSize) const restrict2;
97
98
        /**
99
         * replace colors for SDL for A dye.
100
         */
101
        __attribute__ ((target ("sse2")))
102
        void replaceAColorSse2(uint32_t *restrict pixels,
103
                               const int bufSize) const restrict2;
104
105
        /**
106
         * replace colors for SDL for A dye.
107
         */
108
        __attribute__ ((target ("avx2")))
109
        void replaceAColorAvx2(uint32_t *restrict pixels,
110
                               const int bufSize) const restrict2;
111
#endif  // SIMD_SUPPORTED
112
113
#ifdef USE_OPENGL
114
        /**
115
         * replace colors for OpenGL for S dye.
116
         */
117
        void replaceSOGLColorDefault(uint32_t *restrict pixels,
118
                                     const int bufSize) const restrict2;
119
#ifdef SIMD_SUPPORTED
120
        /**
121
         * replace colors for OpenGL for A dye.
122
         */
123
        __attribute__ ((target ("avx2")))
124
        void replaceAOGLColorAvx2(uint32_t *restrict pixels,
125
                                  const int bufSize) const restrict2;
126
127
        /**
128
         * replace colors for OpenGL for S dye.
129
         */
130
        __attribute__ ((target ("sse2")))
131
        void replaceSOGLColorSse2(uint32_t *restrict pixels,
132
                                  const int bufSize) const restrict2;
133
        /**
134
         * replace colors for OpenGL for S dye.
135
         */
136
        __attribute__ ((target ("avx2")))
137
        void replaceSOGLColorAvx2(uint32_t *restrict pixels,
138
                                  const int bufSize) const restrict2;
139
140
        /**
141
         * replace colors for OpenGL for A dye.
142
         */
143
        __attribute__ ((target ("sse2")))
144
        void replaceAOGLColorSse2(uint32_t *restrict pixels,
145
                                  const int bufSize) const restrict2;
146
#endif  // SIMD_SUPPORTED
147
148
        /**
149
         * replace colors for OpenGL for A dye.
150
         */
151
        void replaceAOGLColorDefault(uint32_t *restrict pixels,
152
                                     const int bufSize) const restrict2;
153
154
#endif  // USE_OPENGL
155
156
        static unsigned int hexDecode(const signed char c)
157
                                      noexcept2 A_CONST A_WARN_UNUSED;
158
159
        static void hexToColor(const std::string &restrict hexStr,
160
                               const uint8_t blockSize,
161
                               DyeColor &color) noexcept2;
162
163
        static void initFunctions();
164
165
#ifdef USE_OPENGL
166
        static DyeFunctionPtr funcReplaceSOGLColor;
167
        static DyeFunctionPtr funcReplaceSOGLColorSse2;
168
        static DyeFunctionPtr funcReplaceSOGLColorAvx2;
169
        static DyeFunctionPtr funcReplaceAOGLColor;
170
        static DyeFunctionPtr funcReplaceAOGLColorSse2;
171
        static DyeFunctionPtr funcReplaceAOGLColorAvx2;
172
#endif  // USE_OPENGL
173
174
        static DyeFunctionPtr funcReplaceSColor;
175
        static DyeFunctionPtr funcReplaceSColorSse2;
176
        static DyeFunctionPtr funcReplaceSColorAvx2;
177
        static DyeFunctionPtr funcReplaceAColor;
178
        static DyeFunctionPtr funcReplaceAColorSse2;
179
        static DyeFunctionPtr funcReplaceAColorAvx2;
180
181
#ifndef UNITTESTS
182
    private:
183
#endif  // UNITTESTS
184
        STD_VECTOR<DyeColor> mColors;
185
};
186
187
#endif  // RESOURCES_DYE_DYEPALETTE_H