2013-04-30 01:44:54 +00:00
|
|
|
// ****************************************************************************
|
|
|
|
// * This file is part of the HqMAME project. It is distributed under *
|
|
|
|
// * GNU General Public License: http://www.gnu.org/licenses/gpl.html *
|
|
|
|
// * 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. *
|
|
|
|
// * 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
|
|
|
|
|
2013-09-15 10:46:14 +00:00
|
|
|
#undef min
|
|
|
|
#undef max
|
|
|
|
|
2013-04-30 01:44:54 +00:00
|
|
|
#include <cstddef> //size_t
|
2014-06-23 22:28:20 +00:00
|
|
|
#if defined(IOS)
|
2013-05-02 06:31:18 +00:00
|
|
|
#include <stdint.h>
|
2013-04-30 18:53:44 +00:00
|
|
|
#else
|
2013-04-30 01:44:54 +00:00
|
|
|
#include <cstdint> //uint32_t
|
2013-04-30 18:53:44 +00:00
|
|
|
#endif
|
2013-04-30 01:44:54 +00:00
|
|
|
#include <limits>
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
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-02-07 09:16:58 +00:00
|
|
|
- highly optimized for performance
|
2014-11-02 22:17:24 +00:00
|
|
|
- support alpha channel
|
2013-04-30 01:44:54 +00:00
|
|
|
- support multithreading
|
2015-02-07 09:16:58 +00:00
|
|
|
- support 64-bit architectures
|
2014-11-02 22:17:24 +00:00
|
|
|
- support processing image slices
|
2015-12-30 21:05:44 +00:00
|
|
|
- support scaling up to 6xBRZ
|
2013-04-30 01:44:54 +00:00
|
|
|
*/
|
|
|
|
|
2014-11-02 22:17:24 +00:00
|
|
|
enum class ColorFormat //from high bits -> low bits, 8 bit per channel
|
|
|
|
{
|
|
|
|
RGB, //8 bit for each red, green, blue, upper 8 bits unused
|
2015-12-30 21:05:44 +00:00
|
|
|
ARGB, //including alpha channel, BGRA byte order on little-endian machines
|
2014-11-02 22:17:24 +00:00
|
|
|
};
|
|
|
|
|
2013-04-30 01:44:54 +00:00
|
|
|
/*
|
2014-11-02 22:17:24 +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!
|
|
|
|
-> 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!
|
2013-04-30 01:44:54 +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!
|
2015-12-30 21:05:44 +00:00
|
|
|
- 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
|
2013-04-30 01:44:54 +00:00
|
|
|
*/
|
2015-12-30 21:05:44 +00:00
|
|
|
void scale(size_t factor, //valid range: 2 - 6
|
2013-04-30 01:44:54 +00:00
|
|
|
const uint32_t* src, uint32_t* trg, int srcWidth, int srcHeight,
|
2014-11-02 22:17:24 +00:00
|
|
|
ColorFormat colFmt,
|
2013-04-30 01:44:54 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
//parameter tuning
|
2014-11-02 22:17:24 +00:00
|
|
|
bool equalColorTest(uint32_t col1, uint32_t col2, ColorFormat colFmt, double luminanceWeight, double equalColorTolerance);
|
2013-04-30 01:44:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//########################### 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|