Subversion Repositories eduke32

Rev

Rev 8489 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8489 Rev 8491
Line 78... Line 78...
78
{
78
{
79
    Bmemset(colmatchresults, 0, COLRESULTSIZ * sizeof(uint32_t));
79
    Bmemset(colmatchresults, 0, COLRESULTSIZ * sizeof(uint32_t));
80
    numcolmatchresults = 0;
80
    numcolmatchresults = 0;
81
}
81
}
82
82
-
 
83
#define checkbitfield(field, idx) ((field)[(idx)>>3] & (1u<<((idx)&7)))
-
 
84
83
// Finds a color index in [0 .. lastokcol] closest to (r, g, b).
85
// Finds a color index in [0 .. lastokcol] closest to (r, g, b).
84
// <lastokcol> must be in [0 .. 255].
86
// <lastokcol> must be in [0 .. 255].
85
int32_t paletteGetClosestColorUpToIndex(int32_t const r, int32_t const g, int32_t const b, int32_t const lastokcol)
87
int32_t paletteGetClosestColorWithBlacklist(int32_t const r, int32_t const g, int32_t const b, int32_t const lastokcol, uint8_t const * const blacklist)
86
{
88
{
87
#ifdef DEBUGGINGAIDS
89
#ifdef DEBUGGINGAIDS
88
    Bassert(lastokcol >= 0 && lastokcol <= 255);
90
    Bassert(lastokcol >= 0 && lastokcol <= 255);
89
#endif
91
#endif
90
92
Line 111... Line 113...
111
113
112
    if (mindist == -1)
114
    if (mindist == -1)
113
    for (; i < k; i++)
115
    for (; i < k; i++)
114
        if (col == (colmatchresults[i] & 0x00ffffff)) { mindist = i; break; }
116
        if (col == (colmatchresults[i] & 0x00ffffff)) { mindist = i; break; }
115
117
116
    if (mindist != -1 && colmatchresults[mindist]>>24 <= (unsigned)lastokcol)
118
    if (mindist != -1)
-
 
119
    {
117
        return colmatchresults[mindist]>>24;
120
        uint32_t const idx = colmatchresults[mindist]>>24;
-
 
121
        if (idx <= (unsigned)lastokcol && (blacklist == nullptr || !checkbitfield(blacklist, idx)))
-
 
122
            return idx;
-
 
123
    }
118
124
119
skip:
125
skip:
120
    i = paletteGetClosestColorUpToIndexNoCache(r, g, b, lastokcol);
126
    i = paletteGetClosestColorWithBlacklistNoCache(r, g, b, lastokcol, blacklist);
121
    colmatchresults[numcolmatchresults++ & (COLRESULTSIZ-1)] = col | (i << 24);
127
    colmatchresults[numcolmatchresults++ & (COLRESULTSIZ-1)] = col | (i << 24);
122
    return i;
128
    return i;
123
}
129
}
124
130
125
int32_t paletteGetClosestColorUpToIndexNoCache(int32_t r, int32_t g, int32_t b, int32_t const lastokcol)
131
int32_t paletteGetClosestColorWithBlacklistNoCache(int32_t r, int32_t g, int32_t b, int32_t const lastokcol, uint8_t const * const blacklist)
126
{
132
{
127
#ifdef DEBUGGINGAIDS
133
#ifdef DEBUGGINGAIDS
128
    Bassert(lastokcol >= 0 && lastokcol <= 255);
134
    Bassert(lastokcol >= 0 && lastokcol <= 255);
129
#endif
135
#endif
130
136
Line 156... Line 162...
156
        do
162
        do
157
        {
163
        {
158
            char const * const pal1 = (char const *)&colmatch_palette[i*3];
164
            char const * const pal1 = (char const *)&colmatch_palette[i*3];
159
            int dist = gdist[pal1[1]+g];
165
            int dist = gdist[pal1[1]+g];
160
166
161
            if (dist >= mindist || i > lastokcol) continue;
167
            if (dist >= mindist || i > lastokcol || (blacklist != nullptr && checkbitfield(blacklist, i))) continue;
162
            if ((dist += rdist[pal1[0]+r]) >= mindist) continue;
168
            if ((dist += rdist[pal1[0]+r]) >= mindist) continue;
163
            if ((dist += bdist[pal1[2]+b]) >= mindist) continue;
169
            if ((dist += bdist[pal1[2]+b]) >= mindist) continue;
164
170
165
            mindist = dist;
171
            mindist = dist;
166
            retcol = i;
172
            retcol = i;
Line 173... Line 179...
173
179
174
    mindist = INT32_MAX;
180
    mindist = INT32_MAX;
175
181
176
    for (bssize_t i = 0; i <= lastokcol; ++i)
182
    for (bssize_t i = 0; i <= lastokcol; ++i)
177
    {
183
    {
-
 
184
        if (blacklist != nullptr && checkbitfield(blacklist, i))
-
 
185
            continue;
-
 
186
178
        char const * const pal1 = (char const *)&colmatch_palette[i*3];
187
        char const * const pal1 = (char const *)&colmatch_palette[i*3];
179
        int dist = gdist[pal1[1]+g];
188
        int dist = gdist[pal1[1]+g];
180
189
181
        if (dist >= mindist) continue;
190
        if (dist >= mindist) continue;
182
        if ((dist += rdist[pal1[0]+r]) >= mindist) continue;
191
        if ((dist += rdist[pal1[0]+r]) >= mindist) continue;