DOSBox-X
|
00001 // **************************************************************************** 00002 // * This file is part of the xBRZ project. It is distributed under * 00003 // * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 * 00004 // * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * 00005 // * * 00006 // * Additionally and as a special exception, the author gives permission * 00007 // * to link the code of this program with the following libraries * 00008 // * (or with modified versions that use the same licenses), and distribute * 00009 // * linked combinations including the two: MAME, FreeFileSync, Snes9x, ePSXe * 00010 // * You must obey the GNU General Public License in all respects for all of * 00011 // * the code used other than MAME, FreeFileSync, Snes9x, ePSXe. * 00012 // * If you modify this file, you may extend this exception to your version * 00013 // * of the file, but you are not obligated to do so. If you do not wish to * 00014 // * do so, delete this exception statement from your version. * 00015 // **************************************************************************** 00016 00017 #ifndef XBRZ_HEADER_3847894708239054 00018 #define XBRZ_HEADER_3847894708239054 00019 00020 #include <cstddef> //size_t 00021 #include <cstdint> //uint32_t 00022 #include <limits> 00023 #include "xbrz_config.h" 00024 00025 namespace xbrz 00026 { 00027 /* 00028 ------------------------------------------------------------------------- 00029 | xBRZ: "Scale by rules" - high quality image upscaling filter by Zenju | 00030 ------------------------------------------------------------------------- 00031 using a modified approach of xBR: 00032 http://board.byuu.org/viewtopic.php?f=10&t=2248 00033 - new rule set preserving small image features 00034 - highly optimized for performance 00035 - support alpha channel 00036 - support multithreading 00037 - support 64-bit architectures 00038 - support processing image slices 00039 - support scaling up to 6xBRZ 00040 */ 00041 00042 enum class ColorFormat //from high bits -> low bits, 8 bit per channel 00043 { 00044 RGB, //8 bit for each red, green, blue, upper 8 bits unused 00045 ARGB, //including alpha channel, BGRA byte order on little-endian machines 00046 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 00047 }; 00048 00049 const int SCALE_FACTOR_MAX = 6; 00050 00051 /* 00052 -> map source (srcWidth * srcHeight) to target (scale * width x scale * height) image, optionally processing a half-open slice of rows [yFirst, yLast) only 00053 -> support for source/target pitch in bytes! 00054 -> 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: 00055 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) 00056 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 00057 in the target image data if you are using multiple threads for processing each enlarged slice! 00058 00059 THREAD-SAFETY: - parts of the same image may be scaled by multiple threads as long as the [yFirst, yLast) ranges do not overlap! 00060 - 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 00061 */ 00062 void scale(size_t factor, //valid range: 2 - SCALE_FACTOR_MAX 00063 const uint32_t* src, uint32_t* trg, int srcWidth, int srcHeight, 00064 ColorFormat colFmt, 00065 const ScalerCfg& cfg = ScalerCfg(), 00066 int yFirst = 0, int yLast = (std::numeric_limits<int>::max)()); //slice of source image 00067 00068 void bilinearScale(const uint32_t* src, int srcWidth, int srcHeight, 00069 uint32_t* trg, int trgWidth, int trgHeight); 00070 00071 void nearestNeighborScale(const uint32_t* src, int srcWidth, int srcHeight, 00072 uint32_t* trg, int trgWidth, int trgHeight); 00073 00074 00075 //parameter tuning 00076 bool equalColorTest(uint32_t col1, uint32_t col2, ColorFormat colFmt, double luminanceWeight, double equalColorTolerance); 00077 } 00078 00079 #endif