The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
xbrz.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// * This file is part of the xBRZ project. It is distributed under *
3// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
4// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved *
5// * *
6// * Additionally and as a special exception, the author gives permission *
7// * to link the code of this program with the following libraries *
8// * (or with modified versions that use the same licenses), and distribute *
9// * linked combinations including the two: MAME, FreeFileSync, Snes9x, ePSXe *
10// * You must obey the GNU General Public License in all respects for all of *
11// * the code used other than MAME, FreeFileSync, Snes9x, ePSXe. *
12// * If you modify this file, you may extend this exception to your version *
13// * of the file, but you are not obligated to do so. If you do not wish to *
14// * do so, delete this exception statement from your version. *
15// ****************************************************************************
16
17#ifndef XBRZ_HEADER_3847894708239054
18#define XBRZ_HEADER_3847894708239054
19
20#include <cstddef> //size_t
21#include <cstdint> //uint32_t
22#include <limits>
23#include "xbrz_config.hpp"
24
25
26namespace xbrz
27{
28/*
29-------------------------------------------------------------------------
30| xBRZ: "Scale by rules" - high quality image upscaling filter by Zenju |
31-------------------------------------------------------------------------
32using a modified approach of xBR:
33http://board.byuu.org/viewtopic.php?f=10&t=2248
34- new rule set preserving small image features
35- highly optimized for performance
36- support alpha channel
37- support multithreading
38- support 64-bit architectures
39- support processing image slices
40- support scaling up to 6xBRZ
41*/
42
43enum class ColorFormat //from high bits -> low bits, 8 bit per channel
44{
45 RGB, //8 bit for each red, green, blue, upper 8 bits unused
46 ARGB, //including alpha channel, BGRA byte order on little-endian machines
47 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
48};
49
50const int SCALE_FACTOR_MAX = 6;
51
52/*
53-> map source (srcWidth * srcHeight) to target (scale * width x scale * height) image, optionally processing a half-open slice of rows [yFirst, yLast) only
54-> 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:
55 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)
56 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
57 in the target image data if you are using multiple threads for processing each enlarged slice!
58
59THREAD-SAFETY: - parts of the same image may be scaled by multiple threads as long as the [yFirst, yLast) ranges do not overlap!
60 - 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
61*/
62void scale(size_t factor, //valid range: 2 - SCALE_FACTOR_MAX
63 const uint32_t* src, uint32_t* trg, int srcWidth, int srcHeight,
64 ColorFormat colFmt,
65 const ScalerCfg& cfg = ScalerCfg(),
66 int yFirst = 0, int yLast = std::numeric_limits<int>::max()); //slice of source image
67
68void bilinearScale(const uint32_t* src, int srcWidth, int srcHeight,
69 /**/ uint32_t* trg, int trgWidth, int trgHeight);
70
71void nearestNeighborScale(const uint32_t* src, int srcWidth, int srcHeight,
72 /**/ uint32_t* trg, int trgWidth, int trgHeight);
73
74
75//parameter tuning
76bool equalColorTest(uint32_t col1, uint32_t col2, ColorFormat colFmt, double luminanceWeight, double equalColorTolerance);
77}
78
79#endif
const config * cfg
Definition xbrz.hpp:27
void scale(size_t factor, const uint32_t *src, uint32_t *trg, int srcWidth, int srcHeight, ColorFormat colFmt, const ScalerCfg &cfg=ScalerCfg(), int yFirst=0, int yLast=std::numeric_limits< int >::max())
Definition xbrz.cpp:1175
bool equalColorTest(uint32_t col1, uint32_t col2, ColorFormat colFmt, double luminanceWeight, double equalColorTolerance)
Definition xbrz.cpp:1238
void nearestNeighborScale(const uint32_t *src, int srcWidth, int srcHeight, uint32_t *trg, int trgWidth, int trgHeight)
Definition xbrz.cpp:1263
const int SCALE_FACTOR_MAX
Definition xbrz.hpp:50
void bilinearScale(const uint32_t *src, int srcWidth, int srcHeight, uint32_t *trg, int trgWidth, int trgHeight)
Definition xbrz.cpp:1254
ColorFormat
Definition xbrz.hpp:44
rect src
Non-transparent portion of the surface to compose.