~ppsspp/ppsspp/ppsspp_1.3.0

« back to all changes in this revision

Viewing changes to ext/xbrz/xbrz.h

  • Committer: Sérgio Benjamim
  • Date: 2017-01-02 00:12:05 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20170102001205-cxbta9za203nmjwm
1.3.0 source (from ppsspp_1.3.0-r160.p5.l1762.a165.t83~56~ubuntu16.04.1.tar.xz).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// ****************************************************************************
 
2
// * This file is part of the HqMAME project. It is distributed under         *
 
3
// * GNU General Public License: http://www.gnu.org/licenses/gpl.html         *
 
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 MAME library (or with modified *
 
8
// * versions of MAME that use the same license as MAME), and distribute      *
 
9
// * linked combinations including the two. You must obey the GNU General     *
 
10
// * Public License in all respects for all of the code used other than MAME. *
 
11
// * If you modify this file, you may extend this exception to your version   *
 
12
// * of the file, but you are not obligated to do so. If you do not wish to   *
 
13
// * do so, delete this exception statement from your version.                *
 
14
// ****************************************************************************
 
15
 
 
16
#ifndef XBRZ_HEADER_3847894708239054
 
17
#define XBRZ_HEADER_3847894708239054
 
18
 
 
19
#undef min
 
20
#undef max
 
21
 
 
22
#include <cstddef> //size_t
 
23
#if defined(IOS)
 
24
#include <stdint.h>
 
25
#else
 
26
#include <cstdint> //uint32_t
 
27
#endif
 
28
#include <limits>
 
29
#include "config.h"
 
30
 
 
31
namespace xbrz
 
32
{
 
33
/*
 
34
-------------------------------------------------------------------------
 
35
| xBRZ: "Scale by rules" - high quality image upscaling filter by Zenju |
 
36
-------------------------------------------------------------------------
 
37
using a modified approach of xBR:
 
38
http://board.byuu.org/viewtopic.php?f=10&t=2248
 
39
- new rule set preserving small image features
 
40
- highly optimized for performance
 
41
- support alpha channel
 
42
- support multithreading
 
43
- support 64-bit architectures
 
44
- support processing image slices
 
45
- support scaling up to 6xBRZ
 
46
*/
 
47
 
 
48
enum class ColorFormat //from high bits -> low bits, 8 bit per channel
 
49
{
 
50
    RGB,  //8 bit for each red, green, blue, upper 8 bits unused
 
51
    ARGB, //including alpha channel, BGRA byte order on little-endian machines
 
52
};
 
53
 
 
54
/*
 
55
-> map source (srcWidth * srcHeight) to target (scale * width x scale * height) image, optionally processing a half-open slice of rows [yFirst, yLast) only
 
56
-> support for source/target pitch in bytes!
 
57
-> 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:
 
58
   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)
 
59
   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
 
60
   in the target image data if you are using multiple threads for processing each enlarged slice!
 
61
 
 
62
THREAD-SAFETY: - parts of the same image may be scaled by multiple threads as long as the [yFirst, yLast) ranges do not overlap!
 
63
               - 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
 
64
*/
 
65
void scale(size_t factor, //valid range: 2 - 6
 
66
           const uint32_t* src, uint32_t* trg, int srcWidth, int srcHeight,
 
67
           ColorFormat colFmt,
 
68
           const ScalerCfg& cfg = ScalerCfg(),
 
69
           int yFirst = 0, int yLast = std::numeric_limits<int>::max()); //slice of source image
 
70
 
 
71
void nearestNeighborScale(const uint32_t* src, int srcWidth, int srcHeight,
 
72
                          uint32_t* trg, int trgWidth, int trgHeight);
 
73
 
 
74
enum SliceType
 
75
{
 
76
    NN_SCALE_SLICE_SOURCE,
 
77
    NN_SCALE_SLICE_TARGET,
 
78
};
 
79
void nearestNeighborScale(const uint32_t* src, int srcWidth, int srcHeight, int srcPitch, //pitch in bytes!
 
80
                          uint32_t* trg, int trgWidth, int trgHeight, int trgPitch,
 
81
                          SliceType st, int yFirst, int yLast);
 
82
 
 
83
//parameter tuning
 
84
bool equalColorTest(uint32_t col1, uint32_t col2, ColorFormat colFmt, double luminanceWeight, double equalColorTolerance);
 
85
 
 
86
 
 
87
 
 
88
 
 
89
 
 
90
//########################### implementation ###########################
 
91
inline
 
92
void nearestNeighborScale(const uint32_t* src, int srcWidth, int srcHeight,
 
93
                          uint32_t* trg, int trgWidth, int trgHeight)
 
94
{
 
95
    nearestNeighborScale(src, srcWidth, srcHeight, srcWidth * sizeof(uint32_t),
 
96
                         trg, trgWidth, trgHeight, trgWidth * sizeof(uint32_t),
 
97
                         NN_SCALE_SLICE_TARGET, 0, trgHeight);
 
98
}
 
99
}
 
100
 
 
101
#endif