OpenXcom  1.0
Open-source clone of the original X-Com
xbrz.h
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 #include <cstddef> //size_t
20 #include <stdint.h> //uint32_t
21 #include <climits>
22 #include "config.h"
23 
24 namespace xbrz
25 {
26 /*
27 -------------------------------------------------------------------------
28 | xBRZ: "Scale by rules" - high quality image upscaling filter by Zenju |
29 -------------------------------------------------------------------------
30 using a modified approach of xBR:
31 http://board.byuu.org/viewtopic.php?f=10&t=2248
32 - new rule set preserving small image features
33 - support multithreading
34 - support 64 bit architectures
35 - support processing image slices
36 */
37 
38 /*
39 -> map source (srcWidth * srcHeight) to target (scale * width x scale * height) image, optionally processing a half-open slice of rows [yFirst, yLast) only
40 -> color format: ARGB (BGRA byte order), alpha channel unused
41 -> support for source/target pitch in bytes!
42 -> 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:
43  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)
44  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
45  if you are using multiple threads for processing each enlarged slice!
46 
47 THREAD-SAFETY: - parts of the same image may be scaled by multiple threads as long as the [yFirst, yLast) ranges do not overlap!
48  - there is a minor inefficiency for the first row of a slice, so avoid processing single rows only
49 
50 
51 */
52 void scale(size_t factor, //valid range: 2 - 5
53  const uint32_t* src, uint32_t* trg, int srcWidth, int srcHeight,
54  const ScalerCfg& cfg = ScalerCfg(),
55  int yFirst = 0, int yLast = INT_MAX); //slice of source image
56 
57 void nearestNeighborScale(const uint32_t* src, int srcWidth, int srcHeight,
58  uint32_t* trg, int trgWidth, int trgHeight);
59 
60 enum SliceType
61 {
62  NN_SCALE_SLICE_SOURCE,
63  NN_SCALE_SLICE_TARGET,
64 };
65 void nearestNeighborScale(const uint32_t* src, int srcWidth, int srcHeight, int srcPitch, //pitch in bytes!
66  uint32_t* trg, int trgWidth, int trgHeight, int trgPitch,
67  SliceType st, int yFirst, int yLast);
68 
69 //parameter tuning
70 bool equalColor(uint32_t col1, uint32_t col2, double luminanceWeight, double equalColorTolerance);
71 
72 
73 
74 
75 
76 //########################### implementation ###########################
77 inline
78 void nearestNeighborScale(const uint32_t* src, int srcWidth, int srcHeight,
79  uint32_t* trg, int trgWidth, int trgHeight)
80 {
81  nearestNeighborScale(src, srcWidth, srcHeight, srcWidth * sizeof(uint32_t),
82  trg, trgWidth, trgHeight, trgWidth * sizeof(uint32_t),
83  NN_SCALE_SLICE_TARGET, 0, trgHeight);
84 }
85 }
86 
87 #endif
Definition: config.h:21