mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-16 17:41:19 +00:00
- cleaned up old xBRZ 1.0 upscaler
Removed obsolete header comments and support for C++98 Disabled Windows only debug features # Conflicts: # src/gl/xbr/xbrz_old.cpp
This commit is contained in:
parent
6dd17b4ef0
commit
8197bf436d
3 changed files with 13 additions and 90 deletions
|
@ -11,11 +11,6 @@
|
||||||
// * If you modify this file, you may extend this exception to your version *
|
// * If you modify this file, you may extend this exception to your version *
|
||||||
// * of the file, but you are not obligated to do so. If you do not wish to *
|
// * of the file, but you are not obligated to do so. If you do not wish to *
|
||||||
// * do so, delete this exception statement from your version. *
|
// * do so, delete this exception statement from your version. *
|
||||||
// * *
|
|
||||||
// * An explicit permission was granted to use xBRZ in combination with ZDoom *
|
|
||||||
// * and derived projects as long as it is used for non-commercial purposes. *
|
|
||||||
// * *
|
|
||||||
// * Backported to C++98 by Alexey Lysiuk *
|
|
||||||
// ****************************************************************************
|
// ****************************************************************************
|
||||||
|
|
||||||
#ifndef __XBRZ_CONFIG_OLD_HEADER_INCLUDED__
|
#ifndef __XBRZ_CONFIG_OLD_HEADER_INCLUDED__
|
||||||
|
|
|
@ -11,11 +11,6 @@
|
||||||
// * If you modify this file, you may extend this exception to your version *
|
// * If you modify this file, you may extend this exception to your version *
|
||||||
// * of the file, but you are not obligated to do so. If you do not wish to *
|
// * of the file, but you are not obligated to do so. If you do not wish to *
|
||||||
// * do so, delete this exception statement from your version. *
|
// * do so, delete this exception statement from your version. *
|
||||||
// * *
|
|
||||||
// * An explicit permission was granted to use xBRZ in combination with ZDoom *
|
|
||||||
// * and derived projects as long as it is used for non-commercial purposes. *
|
|
||||||
// * *
|
|
||||||
// * Backported to C++98 by Alexey Lysiuk *
|
|
||||||
// ****************************************************************************
|
// ****************************************************************************
|
||||||
|
|
||||||
#include "xbrz_old.h"
|
#include "xbrz_old.h"
|
||||||
|
@ -24,12 +19,6 @@
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#ifndef __MINGW32__
|
|
||||||
#if __cplusplus > 199711
|
|
||||||
#define XBRZ_CXX11
|
|
||||||
#endif // __cplusplus > 199711
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
template <uint32_t N> inline
|
template <uint32_t N> inline
|
||||||
|
@ -42,9 +31,7 @@ inline unsigned char getBlue (uint32_t val) { return getByte<0>(val); }
|
||||||
template <class T> inline
|
template <class T> inline
|
||||||
T abs(T value)
|
T abs(T value)
|
||||||
{
|
{
|
||||||
#ifdef XBRZ_CXX11
|
static_assert(std::is_signed<T>::value, "");
|
||||||
static_assert(std::numeric_limits<T>::is_signed, "");
|
|
||||||
#endif // XBRZ_CXX11
|
|
||||||
return value < 0 ? -value : value;
|
return value < 0 ? -value : value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,11 +42,9 @@ const uint32_t blueMask = 0x0000ff;
|
||||||
template <unsigned int N, unsigned int M> inline
|
template <unsigned int N, unsigned int M> inline
|
||||||
void alphaBlend(uint32_t& dst, uint32_t col) //blend color over destination with opacity N / M
|
void alphaBlend(uint32_t& dst, uint32_t col) //blend color over destination with opacity N / M
|
||||||
{
|
{
|
||||||
#ifdef XBRZ_CXX11
|
|
||||||
static_assert(N < 256, "possible overflow of (col & redMask) * N");
|
static_assert(N < 256, "possible overflow of (col & redMask) * N");
|
||||||
static_assert(M < 256, "possible overflow of (col & redMask ) * N + (dst & redMask ) * (M - N)");
|
static_assert(M < 256, "possible overflow of (col & redMask ) * N + (dst & redMask ) * (M - N)");
|
||||||
static_assert(0 < N && N < M, "");
|
static_assert(0 < N && N < M, "");
|
||||||
#endif // XBRZ_CXX11
|
|
||||||
|
|
||||||
static const uint32_t ALPHA_MASK = 0xFF000000;
|
static const uint32_t ALPHA_MASK = 0xFF000000;
|
||||||
static const uint32_t ALPHA_SHIFT = 24;
|
static const uint32_t ALPHA_SHIFT = 24;
|
||||||
|
@ -528,20 +513,12 @@ BlendResult preProcessCorners(const Kernel_4x4& ker, const xbrz_old::ScalerCfg&
|
||||||
ker.g == ker.k))
|
ker.g == ker.k))
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
#ifdef XBRZ_CXX11
|
|
||||||
auto dist = [&](uint32_t col1, uint32_t col2) { return colorDist(col1, col2, cfg.luminanceWeight_); };
|
auto dist = [&](uint32_t col1, uint32_t col2) { return colorDist(col1, col2, cfg.luminanceWeight_); };
|
||||||
#else // !XBRZ_CXX11
|
|
||||||
#define dist(C1, C2) colorDist((C1), (C2), cfg.luminanceWeight_)
|
|
||||||
#endif // XBRZ_CXX11
|
|
||||||
|
|
||||||
const int weight = 4;
|
const int weight = 4;
|
||||||
double jg = dist(ker.i, ker.f) + dist(ker.f, ker.c) + dist(ker.n, ker.k) + dist(ker.k, ker.h) + weight * dist(ker.j, ker.g);
|
double jg = dist(ker.i, ker.f) + dist(ker.f, ker.c) + dist(ker.n, ker.k) + dist(ker.k, ker.h) + weight * dist(ker.j, ker.g);
|
||||||
double fk = dist(ker.e, ker.j) + dist(ker.j, ker.o) + dist(ker.b, ker.g) + dist(ker.g, ker.l) + weight * dist(ker.f, ker.k);
|
double fk = dist(ker.e, ker.j) + dist(ker.j, ker.o) + dist(ker.b, ker.g) + dist(ker.g, ker.l) + weight * dist(ker.f, ker.k);
|
||||||
|
|
||||||
#ifndef XBRZ_CXX11
|
|
||||||
#undef dist
|
|
||||||
#endif // !XBRZ_CXX11
|
|
||||||
|
|
||||||
if (jg < fk) //test sample: 70% of values max(jg, fk) / min(jg, fk) are between 1.1 and 3.7 with median being 1.8
|
if (jg < fk) //test sample: 70% of values max(jg, fk) / min(jg, fk) are between 1.1 and 3.7 with median being 1.8
|
||||||
{
|
{
|
||||||
const bool dominantGradient = cfg.dominantDirectionThreshold * jg < fk;
|
const bool dominantGradient = cfg.dominantDirectionThreshold * jg < fk;
|
||||||
|
@ -623,42 +600,6 @@ int debugPixelY = 84;
|
||||||
bool breakIntoDebugger = false;
|
bool breakIntoDebugger = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define a get_a<rotDeg>(ker)
|
|
||||||
#define b get_b<rotDeg>(ker)
|
|
||||||
#define c get_c<rotDeg>(ker)
|
|
||||||
#define d get_d<rotDeg>(ker)
|
|
||||||
#define e get_e<rotDeg>(ker)
|
|
||||||
#define f get_f<rotDeg>(ker)
|
|
||||||
#define g get_g<rotDeg>(ker)
|
|
||||||
#define h get_h<rotDeg>(ker)
|
|
||||||
#define i get_i<rotDeg>(ker)
|
|
||||||
|
|
||||||
#ifndef XBRZ_CXX11
|
|
||||||
|
|
||||||
template <RotationDegree rotDeg>
|
|
||||||
bool doLineBlend(const Kernel_3x3& ker, const xbrz_old::ScalerCfg& cfg, const unsigned char blend)
|
|
||||||
{
|
|
||||||
if (getBottomR(blend) >= BLEND_DOMINANT)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
#define eq(C1, C2) (colorDist((C1), (C2), cfg.luminanceWeight_) < cfg.equalColorTolerance_)
|
|
||||||
|
|
||||||
//make sure there is no second blending in an adjacent rotation for this pixel: handles insular pixels, mario eyes
|
|
||||||
if (getTopR(blend) != BLEND_NONE && !eq(e, g)) //but support double-blending for 90 degree corners
|
|
||||||
return false;
|
|
||||||
if (getBottomL(blend) != BLEND_NONE && !eq(e, c))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
//no full blending for L-shapes; blend corner only (handles "mario mushroom eyes")
|
|
||||||
if (eq(g, h) && eq(h , i) && eq(i, f) && eq(f, c) && !eq(e, i))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
#undef eq
|
|
||||||
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // !XBRZ_CXX11
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
input kernel area naming convention:
|
input kernel area naming convention:
|
||||||
|
@ -677,20 +618,25 @@ void scalePixel(const Kernel_3x3& ker,
|
||||||
unsigned char blendInfo, //result of preprocessing all four corners of pixel "e"
|
unsigned char blendInfo, //result of preprocessing all four corners of pixel "e"
|
||||||
const xbrz_old::ScalerCfg& cfg)
|
const xbrz_old::ScalerCfg& cfg)
|
||||||
{
|
{
|
||||||
#ifndef NDEBUG
|
#define a get_a<rotDeg>(ker)
|
||||||
|
#define b get_b<rotDeg>(ker)
|
||||||
|
#define c get_c<rotDeg>(ker)
|
||||||
|
#define d get_d<rotDeg>(ker)
|
||||||
|
#define e get_e<rotDeg>(ker)
|
||||||
|
#define f get_f<rotDeg>(ker)
|
||||||
|
#define g get_g<rotDeg>(ker)
|
||||||
|
#define h get_h<rotDeg>(ker)
|
||||||
|
#define i get_i<rotDeg>(ker)
|
||||||
|
|
||||||
|
#if 0 //#ifndef NDEBUG
|
||||||
if (breakIntoDebugger)
|
if (breakIntoDebugger)
|
||||||
#ifdef _MSC_VER
|
|
||||||
__debugbreak(); //__asm int 3;
|
__debugbreak(); //__asm int 3;
|
||||||
#else // !_MSC_VER
|
|
||||||
__builtin_trap();
|
|
||||||
#endif // _MSC_VER
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const unsigned char blend = rotateBlendInfo<rotDeg>(blendInfo);
|
const unsigned char blend = rotateBlendInfo<rotDeg>(blendInfo);
|
||||||
|
|
||||||
if (getBottomR(blend) >= BLEND_NORMAL)
|
if (getBottomR(blend) >= BLEND_NORMAL)
|
||||||
{
|
{
|
||||||
#ifdef XBRZ_CXX11
|
|
||||||
auto eq = [&](uint32_t col1, uint32_t col2) { return colorDist(col1, col2, cfg.luminanceWeight_) < cfg.equalColorTolerance_; };
|
auto eq = [&](uint32_t col1, uint32_t col2) { return colorDist(col1, col2, cfg.luminanceWeight_) < cfg.equalColorTolerance_; };
|
||||||
auto dist = [&](uint32_t col1, uint32_t col2) { return colorDist(col1, col2, cfg.luminanceWeight_); };
|
auto dist = [&](uint32_t col1, uint32_t col2) { return colorDist(col1, col2, cfg.luminanceWeight_); };
|
||||||
|
|
||||||
|
@ -711,19 +657,12 @@ void scalePixel(const Kernel_3x3& ker,
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}();
|
}();
|
||||||
#else // !XBRZ_CXX11
|
|
||||||
#define dist(C1, C2) colorDist((C1), (C2), cfg.luminanceWeight_)
|
|
||||||
#endif // XBRZ_CXX11
|
|
||||||
|
|
||||||
const uint32_t px = dist(e, f) <= dist(e, h) ? f : h; //choose most similar color
|
const uint32_t px = dist(e, f) <= dist(e, h) ? f : h; //choose most similar color
|
||||||
|
|
||||||
OutputMatrix<Scaler::scale, rotDeg> out(target, trgWidth);
|
OutputMatrix<Scaler::scale, rotDeg> out(target, trgWidth);
|
||||||
|
|
||||||
#ifdef XBRZ_CXX11
|
|
||||||
if (doLineBlend)
|
if (doLineBlend)
|
||||||
#else // !XBRZ_CXX11
|
|
||||||
if (doLineBlend<rotDeg>(ker, cfg, blend))
|
|
||||||
#endif // XBRZ_CXX11
|
|
||||||
{
|
{
|
||||||
const double fg = dist(f, g); //test sample: 70% of values max(fg, hc) / min(fg, hc) are between 1.1 and 3.7 with median being 1.9
|
const double fg = dist(f, g); //test sample: 70% of values max(fg, hc) / min(fg, hc) are between 1.1 and 3.7 with median being 1.9
|
||||||
const double hc = dist(h, c); //
|
const double hc = dist(h, c); //
|
||||||
|
@ -750,10 +689,6 @@ void scalePixel(const Kernel_3x3& ker,
|
||||||
Scaler::blendCorner(px, out);
|
Scaler::blendCorner(px, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef XBRZ_CXX11
|
|
||||||
#undef dist
|
|
||||||
#endif // XBRZ_CXX11
|
|
||||||
|
|
||||||
#undef a
|
#undef a
|
||||||
#undef b
|
#undef b
|
||||||
#undef c
|
#undef c
|
||||||
|
@ -781,9 +716,7 @@ void scaleImage(const uint32_t* src, uint32_t* trg, int srcWidth, int srcHeight,
|
||||||
const int bufferSize = srcWidth;
|
const int bufferSize = srcWidth;
|
||||||
unsigned char* preProcBuffer = reinterpret_cast<unsigned char*>(trg + yLast * Scaler::scale * trgWidth) - bufferSize;
|
unsigned char* preProcBuffer = reinterpret_cast<unsigned char*>(trg + yLast * Scaler::scale * trgWidth) - bufferSize;
|
||||||
std::fill(preProcBuffer, preProcBuffer + bufferSize, 0);
|
std::fill(preProcBuffer, preProcBuffer + bufferSize, 0);
|
||||||
#ifdef XBRZ_CXX11
|
|
||||||
static_assert(BLEND_NONE == 0, "");
|
static_assert(BLEND_NONE == 0, "");
|
||||||
#endif // XBRZ_CXX11
|
|
||||||
|
|
||||||
//initialize preprocessing buffer for first row: detect upper left and right corner blending
|
//initialize preprocessing buffer for first row: detect upper left and right corner blending
|
||||||
//this cannot be optimized for adjacent processing stripes; we must not allow for a memory race condition!
|
//this cannot be optimized for adjacent processing stripes; we must not allow for a memory race condition!
|
||||||
|
|
|
@ -11,18 +11,13 @@
|
||||||
// * If you modify this file, you may extend this exception to your version *
|
// * If you modify this file, you may extend this exception to your version *
|
||||||
// * of the file, but you are not obligated to do so. If you do not wish to *
|
// * of the file, but you are not obligated to do so. If you do not wish to *
|
||||||
// * do so, delete this exception statement from your version. *
|
// * do so, delete this exception statement from your version. *
|
||||||
// * *
|
|
||||||
// * An explicit permission was granted to use xBRZ in combination with ZDoom *
|
|
||||||
// * and derived projects as long as it is used for non-commercial purposes. *
|
|
||||||
// * *
|
|
||||||
// * Backported to C++98 by Alexey Lysiuk *
|
|
||||||
// ****************************************************************************
|
// ****************************************************************************
|
||||||
|
|
||||||
#ifndef __XBRZ_OLD_HEADER_INCLUDED__
|
#ifndef __XBRZ_OLD_HEADER_INCLUDED__
|
||||||
#define __XBRZ_OLD_HEADER_INCLUDED__
|
#define __XBRZ_OLD_HEADER_INCLUDED__
|
||||||
|
|
||||||
#include <cstddef> //size_t
|
#include <cstddef> //size_t
|
||||||
#include <stdint.h> //uint32_t
|
#include <cstdint> //uint32_t
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include "xbrz_config_old.h"
|
#include "xbrz_config_old.h"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue