The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
xbrz.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2016 by Chris Beck <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY.
10  See the COPYING file for more details.
11 
12  This is a derivative work of the xBRZ component of the HqMAME project
13  by Zenju. The original Licensing statment follows, indented with //
14  The primary changes are, syntactic to make it compile with C99+Boost,
15  and to make it handle an alpha channel in the image in a manner proper
16  for SDL.
17 
18  It is not possible to extend the MAME 'special exception' to all of
19  the Battle for Wesnoth project, however, the special exception is
20  granted for my derivative forms of this work.
21 */
22 
23 // ****************************************************************************
24 // * This file is part of the HqMAME project. It is distributed under *
25 // * GNU General Public License: http://www.gnu.org/licenses/gpl.html *
26 // * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved *
27 // * *
28 // * Additionally and as a special exception, the author gives permission *
29 // * to link the code of this program with the MAME library (or with modified *
30 // * versions of MAME that use the same license as MAME), and distribute *
31 // * linked combinations including the two. You must obey the GNU General *
32 // * Public License in all respects for all of the code used other than MAME. *
33 // * If you modify this file, you may extend this exception to your version *
34 // * of the file, but you are not obligated to do so. If you do not wish to *
35 // * do so, delete this exception statement from your version. *
36 // ****************************************************************************
37 
38 #ifndef XBRZ_HEADER_3847894708239054
39 #define XBRZ_HEADER_3847894708239054
40 
41 #include <cstddef> //size_t
42 //#include <cstdint> //uint32_t
43 #include <boost/cstdint.hpp>
44 
46 
47 #include <limits>
48 #include "config.hpp"
49 
50 namespace xbrz
51 {
52 /*
53 -------------------------------------------------------------------------
54 | xBRZ: "Scale by rules" - high quality image upscaling filter by Zenju |
55 -------------------------------------------------------------------------
56 using a modified approach of xBR:
57 http://board.byuu.org/viewtopic.php?f=10&t=2248
58 - new rule set preserving small image features
59 - support multithreading
60 - support 64 bit architectures
61 - support processing image slices
62 */
63 
64 /*
65 -> map source (srcWidth * srcHeight) to target (scale * width x scale * height) image, optionally processing a half-open slice of rows [yFirst, yLast) only
66 -> color format: ARGB (BGRA byte order), alpha channel unused
67 -> support for source/target pitch in bytes!
68 -> 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:
69  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)
70  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
71  if you are using multiple threads for processing each enlarged slice!
72 
73 THREAD-SAFETY: - parts of the same image may be scaled by multiple threads as long as the [yFirst, yLast) ranges do not overlap!
74  - there is a minor inefficiency for the first row of a slice, so avoid processing single rows only
75 
76 
77 */
78 void scale(size_t factor, //valid range: 2 - 5
79  const uint32_t* src, uint32_t* trg, int srcWidth, int srcHeight,
80  const ScalerCfg& cfg = ScalerCfg(),
81  int yFirst = 0, int yLast = std::numeric_limits<int>::max()); //slice of source image
82 
83 void nearestNeighborScale(const uint32_t* src, int srcWidth, int srcHeight,
84  uint32_t* trg, int trgWidth, int trgHeight);
85 
87 {
90 };
91 void nearestNeighborScale(const uint32_t* src, int srcWidth, int srcHeight, int srcPitch, //pitch in bytes!
92  uint32_t* trg, int trgWidth, int trgHeight, int trgPitch,
93  SliceType st, int yFirst, int yLast);
94 
95 //parameter tuning
96 bool equalColor(uint32_t col1, uint32_t col2, double luminanceWeight, double equalColorTolerance);
97 
98 
99 
100 
101 
102 //########################### implementation ###########################
103 inline
104 void nearestNeighborScale(const uint32_t* src, int srcWidth, int srcHeight,
105  uint32_t* trg, int trgWidth, int trgHeight)
106 {
107  nearestNeighborScale(src, srcWidth, srcHeight, srcWidth * sizeof(uint32_t),
108  trg, trgWidth, trgHeight, trgWidth * sizeof(uint32_t),
109  NN_SCALE_SLICE_TARGET, 0, trgHeight);
110 }
111 }
112 
113 #endif
Definition: config.hpp:43
boost::uint32_t uint32_t
Definition: xbrz.hpp:45
SliceType
Definition: xbrz.hpp:86
GLenum src
Definition: glew.h:2392
void scale(size_t factor, const uint32_t *src, uint32_t *trg, int srcWidth, int srcHeight, const ScalerCfg &cfg=ScalerCfg(), int yFirst=0, int yLast=std::numeric_limits< int >::max())
Definition: xbrz.cpp:1196
bool equalColor(uint32_t col1, uint32_t col2, double luminanceWeight, double equalColorTolerance)
Definition: xbrz.cpp:1213
void nearestNeighborScale(const uint32_t *src, int srcWidth, int srcHeight, uint32_t *trg, int trgWidth, int trgHeight)
Definition: xbrz.hpp:104