snes9x/filter/xbrz.h

81 lines
4.1 KiB
C
Raw Normal View History

2014-06-24 19:53:00 +00:00
// ****************************************************************************
2018-02-27 20:39:50 +00:00
// * This file is part of the xBRZ project. It is distributed under *
// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
2014-06-24 19:53:00 +00:00
// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved *
// * *
// * Additionally and as a special exception, the author gives permission *
2018-02-27 20:39:50 +00:00
// * 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 *
// * You must obey the GNU General Public License in all respects for all of *
// * the code used other than MAME, FreeFileSync, Snes9x. *
2014-06-24 19:53:00 +00:00
// * 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_HEADER_3847894708239054
#define XBRZ_HEADER_3847894708239054
#include "port.h"
//#include <cstddef> //size_t
//#include <cstdint> //uint32_t
#include <limits>
2018-02-27 20:39:50 +00:00
#include "xbrz_config.h"
2014-06-24 19:53:00 +00:00
namespace xbrz
{
/*
-------------------------------------------------------------------------
| xBRZ: "Scale by rules" - high quality image upscaling filter by Zenju |
-------------------------------------------------------------------------
using a modified approach of xBR:
http://board.byuu.org/viewtopic.php?f=10&t=2248
- new rule set preserving small image features
2015-01-29 20:42:32 +00:00
- highly optimized for performance
- support alpha channel
2014-06-24 19:53:00 +00:00
- support multithreading
2015-01-29 20:42:32 +00:00
- support 64-bit architectures
2014-06-24 19:53:00 +00:00
- support processing image slices
2016-10-07 19:39:32 +00:00
- support scaling up to 6xBRZ
2014-06-24 19:53:00 +00:00
*/
2016-10-07 19:39:32 +00:00
enum class ColorFormat //from high bits -> low bits, 8 bit per channel
2015-01-29 20:42:32 +00:00
{
RGB, //8 bit for each red, green, blue, upper 8 bits unused
2016-10-07 19:39:32 +00:00
ARGB, //including alpha channel, BGRA byte order on little-endian machines
2018-02-27 20:39:50 +00:00
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
2015-01-29 20:42:32 +00:00
};
2018-02-27 20:39:50 +00:00
const int SCALE_FACTOR_MAX = 6;
2014-06-24 19:53:00 +00:00
/*
-> 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!
2015-01-29 20:42:32 +00:00
-> 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:
2014-06-24 19:53:00 +00:00
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)
2018-02-27 20:39:50 +00:00
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
2015-01-29 20:42:32 +00:00
in the target image data if you are using multiple threads for processing each enlarged slice!
2014-06-24 19:53:00 +00:00
THREAD-SAFETY: - parts of the same image may be scaled by multiple threads as long as the [yFirst, yLast) ranges do not overlap!
2018-02-27 20:39:50 +00:00
- 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
2014-06-24 19:53:00 +00:00
*/
2018-02-27 20:39:50 +00:00
void scale(size_t factor, //valid range: 2 - SCALE_FACTOR_MAX
2014-06-24 19:53:00 +00:00
const uint32_t* src, uint32_t* trg, int srcWidth, int srcHeight,
2015-01-29 20:42:32 +00:00
ColorFormat colFmt,
2014-06-24 19:53:00 +00:00
const ScalerCfg& cfg = ScalerCfg(),
int yFirst = 0, int yLast = std::numeric_limits<int>::max()); //slice of source image
2018-02-27 20:39:50 +00:00
void bilinearScale(const uint32_t* src, int srcWidth, int srcHeight,
/**/ uint32_t* trg, int trgWidth, int trgHeight);
2014-06-24 19:53:00 +00:00
void nearestNeighborScale(const uint32_t* src, int srcWidth, int srcHeight,
2018-02-27 20:39:50 +00:00
/**/ uint32_t* trg, int trgWidth, int trgHeight);
2014-06-24 19:53:00 +00:00
//parameter tuning
2015-01-29 20:42:32 +00:00
bool equalColorTest(uint32_t col1, uint32_t col2, ColorFormat colFmt, double luminanceWeight, double equalColorTolerance);
2014-06-24 19:53:00 +00:00
}
#endif