Skip to content
Permalink
Browse files

Update to xBRZ `1.7`.

Get files from here `https://sourceforge.net/projects/xbrz/files/xBRZ/`.

Then, update the src to handle pitch params. For our case, the pitch
is necessary because we deal with borders (top and right) of our source
image. Normally, we would want to scale without it, and therefore we
need to adjust the pointers to skip the borders.

If we have a `width + 1 pixel border` per line, the we need to scale
a image with `width` line size, but advancing the pointer for each new
line processed including the border on the count.

Also, since our output pointer also allocates for the border, we need
to adjust the output moving pointer for each line in a custom way.
(output border in this case)

- Fix #164.
  • Loading branch information
denisfa authored and rkitover committed Aug 22, 2019
1 parent 290012d commit 234f1e9b1a3ac0b409071fe144804a8aad655a99
Showing with 643 additions and 300 deletions.
  1. +2 −1 CMakeLists.txt
  2. +292 −236 src/filters/xBRZ/xbrz.cpp
  3. +34 −56 src/filters/xBRZ/xbrz.h
  4. +35 −0 src/filters/xBRZ/xbrz_config.h
  5. +272 −0 src/filters/xBRZ/xbrz_tools.h
  6. +5 −5 src/filters/xbrzfilter.cpp
  7. +3 −2 src/wx/panel.cpp
@@ -814,8 +814,9 @@ set(
src/filters/hq2x.h
src/filters/interp.h
src/filters/lq2x.h
src/filters/xBRZ/config.h
src/filters/xBRZ/xbrz_config.h
src/filters/xBRZ/xbrz.h
src/filters/xBRZ/xbrz_tools.h
)

set(

Large diffs are not rendered by default.

@@ -1,13 +1,14 @@
// ****************************************************************************
// * This file is part of the HqMAME project. It is distributed under *
// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
// * This file is part of the xBRZ project. It is distributed under *
// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved *
// * *
// * Additionally and as a special exception, the author gives permission *
// * to link the code of this program with the MAME library (or with modified *
// * versions of MAME that use the same license as MAME), and distribute *
// * linked combinations including the two. You must obey the GNU General *
// * Public License in all respects for all of the code used other than MAME. *
// * to link the code of this program with the following libraries *
// * (or with modified versions that use the same licenses), and distribute *
// * linked combinations including the two: MAME, FreeFileSync, Snes9x, ePSXe *
// * You must obey the GNU General Public License in all respects for all of *
// * the code used other than MAME, FreeFileSync, Snes9x, ePSXe. *
// * 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 *
// * do so, delete this exception statement from your version. *
@@ -16,10 +17,11 @@
#ifndef XBRZ_HEADER_3847894708239054
#define XBRZ_HEADER_3847894708239054

#include "config.h"
#include <cstddef> //size_t
#include <cstdint> //uint32_t
#include <limits>
#include <stdint.h> //uint32_t
#include "xbrz_config.h"


namespace xbrz
{
@@ -38,65 +40,41 @@ using a modified approach of xBR:
- support scaling up to 6xBRZ
*/

enum ColorFormat // from high bits -> low bits, 8 bit per channel
{ RGB, // 8 bit for each red, green, blue, upper 8 bits unused
ARGB, // including alpha channel, BGRA byte order on little-endian machines
enum class ColorFormat //from high bits -> low bits, 8 bit per channel
{
RGB, //8 bit for each red, green, blue, upper 8 bits unused
ARGB, //including alpha channel, BGRA byte order on little-endian machines
ARGB_UNBUFFERED, //like ARGB, but without the one-time buffer creation overhead (ca. 100 - 300 ms) at the expense of a slightly slower scaling time
};

const int SCALE_FACTOR_MAX = 6;

/*
-> map source (srcWidth * srcHeight) to target (scale * width x scale * height) image, optionally
processing a half-open slice of rows [yFirst, yLast) only
-> map source (srcWidth * srcHeight) to target (scale * width x scale * height) image, optionally processing a half-open slice of rows [yFirst, yLast) only
-> support for source/target pitch in bytes!
-> if your emulator changes only a few image slices during each cycle (e.g. DOSBox) then there's no
need to run xBRZ on the complete image:
Just make sure you enlarge the source image slice by 2 rows on top and 2 on bottom (this is the
additional range the xBRZ algorithm is using during analysis)
Caveat: If there are multiple changed slices, make sure they do not overlap after adding these
additional rows in order to avoid a memory race condition
-> if your emulator changes only a few image slices during each cycle (e.g. DOSBox) then there's no need to run xBRZ on the complete image:
Just make sure you enlarge the source image slice by 2 rows on top and 2 on bottom (this is the additional range the xBRZ algorithm is using during analysis)
CAVEAT: If there are multiple changed slices, make sure they do not overlap after adding these additional rows in order to avoid a memory race condition
in the target image data if you are using multiple threads for processing each enlarged slice!
THREAD-SAFETY: - parts of the same image may be scaled by multiple threads as long as the [yFirst,
yLast) ranges do not overlap!
- there is a minor inefficiency for the first row of a slice, so avoid processing
single rows only; suggestion: process 8-16 rows at least
THREAD-SAFETY: - parts of the same image may be scaled by multiple threads as long as the [yFirst, yLast) ranges do not overlap!
- there is a minor inefficiency for the first row of a slice, so avoid processing single rows only; suggestion: process at least 8-16 rows
*/
void scale(size_t factor, // valid range: 2 - 6
const uint32_t *src, int srcWidth, int srcHeight, int srcPitch, uint32_t *trg,
int trgPitch, ColorFormat colFmt, const ScalerCfg &cfg = ScalerCfg(), int yFirst = 0,
int yLast = std::numeric_limits<int>::max()); // slice of source image
void scale(size_t factor, //valid range: 2 - SCALE_FACTOR_MAX
const uint32_t* src, uint32_t* trg, int srcWidth, int srcHeight,
ColorFormat colFmt, int srcPitch, int trgPitch,
const ScalerCfg& cfg = ScalerCfg(),
int yFirst = 0, int yLast = std::numeric_limits<int>::max()); //slice of source image

void nearestNeighborScale(const uint32_t *src, int srcWidth, int srcHeight, uint32_t *trg,
int trgWidth, int trgHeight);
void bilinearScale(const uint32_t* src, int srcWidth, int srcHeight,
/**/ uint32_t* trg, int trgWidth, int trgHeight);

enum SliceType {
NN_SCALE_SLICE_SOURCE,
NN_SCALE_SLICE_TARGET,
};
void nearestNeighborScale(const uint32_t *src, int srcWidth, int srcHeight,
int srcPitch, // pitch in bytes!
uint32_t *trg, int trgWidth, int trgHeight, int trgPitch, SliceType st,
int yFirst, int yLast);
void nearestNeighborScale(const uint32_t* src, int srcWidth, int srcHeight,
/**/ uint32_t* trg, int trgWidth, int trgHeight);

// parameter tuning
bool equalColorTest(uint32_t col1, uint32_t col2, ColorFormat colFmt, double luminanceWeight,
double equalColorTolerance);

//########################### implementation ###########################
inline void nearestNeighborScale(const uint32_t *src, int srcWidth, int srcHeight, uint32_t *trg,
int trgWidth, int trgHeight)
{
nearestNeighborScale(src,
srcWidth,
srcHeight,
srcWidth * sizeof(uint32_t),
trg,
trgWidth,
trgHeight,
trgWidth * sizeof(uint32_t),
NN_SCALE_SLICE_TARGET,
0,
trgHeight);
}
//parameter tuning
bool equalColorTest(uint32_t col1, uint32_t col2, ColorFormat colFmt, double luminanceWeight, double equalColorTolerance);
}

#endif
@@ -0,0 +1,35 @@
// ****************************************************************************
// * This file is part of the xBRZ project. It is distributed under *
// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved *
// * *
// * Additionally and as a special exception, the author gives permission *
// * to link the code of this program with the following libraries *
// * (or with modified versions that use the same licenses), and distribute *
// * linked combinations including the two: MAME, FreeFileSync, Snes9x, ePSXe *
// * You must obey the GNU General Public License in all respects for all of *
// * the code used other than MAME, FreeFileSync, Snes9x, ePSXe. *
// * 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 *
// * do so, delete this exception statement from your version. *
// ****************************************************************************

#ifndef XBRZ_CONFIG_HEADER_284578425345
#define XBRZ_CONFIG_HEADER_284578425345

//do NOT include any headers here! used by xBRZ_dll!!!

namespace xbrz
{
struct ScalerCfg
{
double luminanceWeight = 1;
double equalColorTolerance = 30;
double centerDirectionBias = 4;
double dominantDirectionThreshold = 3.6;
double steepDirectionThreshold = 2.2;
double newTestAttribute = 0; //unused; test new parameters
};
}

#endif

0 comments on commit 234f1e9

Please sign in to comment.
You can’t perform that action at this time.