mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-10 06:41:41 +00:00
- inlined the entire ColorMatcher.
This commit is contained in:
parent
f9a41cf11e
commit
cf15ebc966
6 changed files with 106 additions and 168 deletions
|
@ -1308,7 +1308,6 @@ set (PCH_SOURCES
|
|||
utility/stats.cpp
|
||||
utility/atterm.cpp
|
||||
utility/cmdlib.cpp
|
||||
utility/colormatcher.cpp
|
||||
utility/configfile.cpp
|
||||
utility/i_module.cpp
|
||||
utility/i_time.cpp
|
||||
|
|
|
@ -10,10 +10,6 @@
|
|||
#ifndef __DOOMTYPE__
|
||||
#define __DOOMTYPE__
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
// VC++ does not define PATH_MAX, but the Windows headers do define MAX_PATH.
|
||||
// However, we want to avoid including the Windows headers in most of the
|
||||
|
@ -104,84 +100,7 @@ enum
|
|||
DMSG_SPAMMY, // for those who want to see everything, regardless of its usefulness.
|
||||
};
|
||||
|
||||
struct PalEntry
|
||||
{
|
||||
PalEntry() = default;
|
||||
PalEntry (uint32_t argb) { d = argb; }
|
||||
operator uint32_t () const { return d; }
|
||||
void SetRGB(PalEntry other)
|
||||
{
|
||||
d = other.d & 0xffffff;
|
||||
}
|
||||
PalEntry Modulate(PalEntry other) const
|
||||
{
|
||||
if (isWhite())
|
||||
{
|
||||
return other;
|
||||
}
|
||||
else if (other.isWhite())
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
else
|
||||
{
|
||||
other.r = (r * other.r) / 255;
|
||||
other.g = (g * other.g) / 255;
|
||||
other.b = (b * other.b) / 255;
|
||||
return other;
|
||||
}
|
||||
}
|
||||
int Luminance() const
|
||||
{
|
||||
return (r * 77 + g * 143 + b * 37) >> 8;
|
||||
}
|
||||
|
||||
void Decolorize() // this for 'nocoloredspritelighting' and not the same as desaturation. The normal formula results in a value that's too dark.
|
||||
{
|
||||
int v = (r + g + b);
|
||||
r = g = b = ((255*3) + v + v) / 9;
|
||||
}
|
||||
bool isBlack() const
|
||||
{
|
||||
return (d & 0xffffff) == 0;
|
||||
}
|
||||
bool isWhite() const
|
||||
{
|
||||
return (d & 0xffffff) == 0xffffff;
|
||||
}
|
||||
PalEntry &operator= (const PalEntry &other) = default;
|
||||
PalEntry &operator= (uint32_t other) { d = other; return *this; }
|
||||
PalEntry InverseColor() const { PalEntry nc; nc.a = a; nc.r = 255 - r; nc.g = 255 - g; nc.b = 255 - b; return nc; }
|
||||
#ifdef __BIG_ENDIAN__
|
||||
PalEntry (uint8_t ir, uint8_t ig, uint8_t ib) : a(0), r(ir), g(ig), b(ib) {}
|
||||
PalEntry (uint8_t ia, uint8_t ir, uint8_t ig, uint8_t ib) : a(ia), r(ir), g(ig), b(ib) {}
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint8_t a,r,g,b;
|
||||
};
|
||||
uint32_t d;
|
||||
};
|
||||
#else
|
||||
PalEntry (uint8_t ir, uint8_t ig, uint8_t ib) : b(ib), g(ig), r(ir), a(0) {}
|
||||
PalEntry (uint8_t ia, uint8_t ir, uint8_t ig, uint8_t ib) : b(ib), g(ig), r(ir), a(ia) {}
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint8_t b,g,r,a;
|
||||
};
|
||||
uint32_t d;
|
||||
};
|
||||
#endif
|
||||
};
|
||||
|
||||
inline int Luminance(int r, int g, int b)
|
||||
{
|
||||
return (r * 77 + g * 143 + b * 37) >> 8;
|
||||
}
|
||||
|
||||
#include "palentry.h"
|
||||
|
||||
enum class ETextureType : uint8_t
|
||||
{
|
||||
|
|
|
@ -1,79 +0,0 @@
|
|||
/*
|
||||
** colormatcher.cpp
|
||||
** My attempt at a fast color matching system
|
||||
**
|
||||
**---------------------------------------------------------------------------
|
||||
** Copyright 1998-2006 Randy Heit
|
||||
** All rights reserved.
|
||||
**
|
||||
** Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions
|
||||
** are met:
|
||||
**
|
||||
** 1. Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** 2. Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in the
|
||||
** documentation and/or other materials provided with the distribution.
|
||||
** 3. The name of the author may not be used to endorse or promote products
|
||||
** derived from this software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**---------------------------------------------------------------------------
|
||||
**
|
||||
** Once upon a time, this tried to be a fast closest color finding system.
|
||||
** It was, but the results were not as good as I would like, so I didn't
|
||||
** actually use it. But I did keep the code around in case I ever felt like
|
||||
** revisiting the problem. I never did, so now it's relegated to the mists
|
||||
** of SVN history, and this is just a thin wrapper around BestColor().
|
||||
**
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "doomtype.h"
|
||||
#include "colormatcher.h"
|
||||
#include "v_palette.h"
|
||||
|
||||
FColorMatcher::FColorMatcher ()
|
||||
{
|
||||
Pal = NULL;
|
||||
}
|
||||
|
||||
FColorMatcher::FColorMatcher (const uint32_t *palette)
|
||||
{
|
||||
SetPalette (palette);
|
||||
}
|
||||
|
||||
FColorMatcher::FColorMatcher (const FColorMatcher &other)
|
||||
{
|
||||
*this = other;
|
||||
}
|
||||
|
||||
FColorMatcher &FColorMatcher::operator= (const FColorMatcher &other)
|
||||
{
|
||||
Pal = other.Pal;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void FColorMatcher::SetPalette (const uint32_t *palette)
|
||||
{
|
||||
Pal = (const PalEntry *)palette;
|
||||
}
|
||||
|
||||
uint8_t FColorMatcher::Pick (int r, int g, int b)
|
||||
{
|
||||
if (Pal == NULL)
|
||||
return 1;
|
||||
|
||||
return (uint8_t)BestColor ((uint32_t *)Pal, r, g, b);
|
||||
}
|
|
@ -29,26 +29,43 @@
|
|||
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**---------------------------------------------------------------------------
|
||||
**
|
||||
** Once upon a time, this tried to be a fast closest color finding system.
|
||||
** It was, but the results were not as good as I would like, so I didn't
|
||||
** actually use it. But I did keep the code around in case I ever felt like
|
||||
** revisiting the problem. I never did, so now it's relegated to the mists
|
||||
** of SVN history, and this is just a thin wrapper around BestColor().
|
||||
**
|
||||
*/
|
||||
|
||||
#ifndef __COLORMATCHER_H__
|
||||
#define __COLORMATCHER_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
int BestColor (const uint32_t *pal_in, int r, int g, int b, int first, int num);
|
||||
|
||||
class FColorMatcher
|
||||
{
|
||||
public:
|
||||
FColorMatcher ();
|
||||
FColorMatcher (const uint32_t *palette);
|
||||
FColorMatcher (const FColorMatcher &other);
|
||||
FColorMatcher () = default;
|
||||
FColorMatcher (const uint32_t *palette) { Pal = reinterpret_cast<const PalEntry*>(palette); }
|
||||
FColorMatcher (const FColorMatcher &other) = default;
|
||||
|
||||
void SetPalette (const uint32_t *palette);
|
||||
uint8_t Pick (int r, int g, int b);
|
||||
void SetPalette (const uint32_t *palette) { Pal = reinterpret_cast<const PalEntry*>(palette); }
|
||||
uint8_t Pick (int r, int g, int b)
|
||||
{
|
||||
if (Pal == nullptr)
|
||||
return 1;
|
||||
|
||||
return (uint8_t)BestColor ((uint32_t *)Pal, r, g, b, 1, 255);
|
||||
}
|
||||
|
||||
uint8_t Pick (PalEntry pe)
|
||||
{
|
||||
return Pick(pe.r, pe.g, pe.b);
|
||||
}
|
||||
|
||||
FColorMatcher &operator= (const FColorMatcher &other);
|
||||
FColorMatcher &operator= (const FColorMatcher &other) = default;
|
||||
|
||||
private:
|
||||
const PalEntry *Pal;
|
||||
|
|
82
src/utility/palentry.h
Normal file
82
src/utility/palentry.h
Normal file
|
@ -0,0 +1,82 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct PalEntry
|
||||
{
|
||||
PalEntry() = default;
|
||||
PalEntry (uint32_t argb) { d = argb; }
|
||||
operator uint32_t () const { return d; }
|
||||
void SetRGB(PalEntry other)
|
||||
{
|
||||
d = other.d & 0xffffff;
|
||||
}
|
||||
PalEntry Modulate(PalEntry other) const
|
||||
{
|
||||
if (isWhite())
|
||||
{
|
||||
return other;
|
||||
}
|
||||
else if (other.isWhite())
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
else
|
||||
{
|
||||
other.r = (r * other.r) / 255;
|
||||
other.g = (g * other.g) / 255;
|
||||
other.b = (b * other.b) / 255;
|
||||
return other;
|
||||
}
|
||||
}
|
||||
int Luminance() const
|
||||
{
|
||||
return (r * 77 + g * 143 + b * 37) >> 8;
|
||||
}
|
||||
|
||||
void Decolorize() // this for 'nocoloredspritelighting' and not the same as desaturation. The normal formula results in a value that's too dark.
|
||||
{
|
||||
int v = (r + g + b);
|
||||
r = g = b = ((255*3) + v + v) / 9;
|
||||
}
|
||||
bool isBlack() const
|
||||
{
|
||||
return (d & 0xffffff) == 0;
|
||||
}
|
||||
bool isWhite() const
|
||||
{
|
||||
return (d & 0xffffff) == 0xffffff;
|
||||
}
|
||||
PalEntry &operator= (const PalEntry &other) = default;
|
||||
PalEntry &operator= (uint32_t other) { d = other; return *this; }
|
||||
PalEntry InverseColor() const { PalEntry nc; nc.a = a; nc.r = 255 - r; nc.g = 255 - g; nc.b = 255 - b; return nc; }
|
||||
#ifdef __BIG_ENDIAN__
|
||||
PalEntry (uint8_t ir, uint8_t ig, uint8_t ib) : a(0), r(ir), g(ig), b(ib) {}
|
||||
PalEntry (uint8_t ia, uint8_t ir, uint8_t ig, uint8_t ib) : a(ia), r(ir), g(ig), b(ib) {}
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint8_t a,r,g,b;
|
||||
};
|
||||
uint32_t d;
|
||||
};
|
||||
#else
|
||||
PalEntry (uint8_t ir, uint8_t ig, uint8_t ib) : b(ib), g(ig), r(ir), a(0) {}
|
||||
PalEntry (uint8_t ia, uint8_t ir, uint8_t ig, uint8_t ib) : b(ib), g(ig), r(ir), a(ia) {}
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint8_t b,g,r,a;
|
||||
};
|
||||
uint32_t d;
|
||||
};
|
||||
#endif
|
||||
};
|
||||
|
||||
inline int Luminance(int r, int g, int b)
|
||||
{
|
||||
return (r * 77 + g * 143 + b * 37) >> 8;
|
||||
}
|
||||
|
Loading…
Reference in a new issue