From 13bb22ba8152397ad9708b34e2151b10036133db Mon Sep 17 00:00:00 2001 From: Arthur Moore Date: Wed, 17 Jun 2015 20:14:05 -0400 Subject: [PATCH] Further cleaned up filter system. wx now only knows and cares about filter_base and filter_factory. --- CMakeLists.txt | 28 +++-- src/filters/filter_factory.cpp | 116 ++++++++++++++++++ src/filters/filter_factory.hpp | 18 +++ src/filters/{ => filter_functions}/2xSaI.cpp | 7 +- .../{ => filter_functions}/2xSaImmx.asm | 0 src/filters/{ => filter_functions}/admame.cpp | 4 +- .../{ => filter_functions}/bilinear.cpp | 8 +- src/filters/filter_functions/filters.cpp | 14 +++ .../{ => filter_functions}/hq/asm/hq3x32.cpp | 0 .../{ => filter_functions}/hq/asm/hq3x_16.asm | 0 .../{ => filter_functions}/hq/asm/hq3x_32.asm | 0 .../{ => filter_functions}/hq/asm/hq4x_16.asm | 0 .../{ => filter_functions}/hq/asm/hq4x_32.asm | 0 .../{ => filter_functions}/hq/asm/macros.mac | 0 .../hq/c/hq3x_pattern.h | 0 .../hq/c/hq4x_pattern.h | 0 .../{ => filter_functions}/hq/c/hq_base.h | 0 .../hq/c/hq_implementation.cpp | 0 .../{ => filter_functions}/hq/c/hq_shared.h | 0 src/filters/{ => filter_functions}/hq2x.cpp | 6 +- src/filters/{ => filter_functions}/hq2x.h | 0 .../{ => filter_functions}/interframe.cpp | 7 +- src/filters/{ => filter_functions}/interp.h | 0 src/filters/{ => filter_functions}/lq2x.h | 0 .../{ => filter_functions}/new_interframe.cpp | 6 +- src/filters/{ => filter_functions}/pixel.cpp | 5 +- .../{ => filter_functions}/scanline.cpp | 5 +- src/filters/{ => filter_functions}/sdl.cpp | 5 +- .../{ => filter_functions}/simpleFilter.cpp | 5 +- .../{ => filter_functions}/xBRZ/Changelog.txt | 0 .../{ => filter_functions}/xBRZ/License.txt | 0 .../{ => filter_functions}/xBRZ/config.h | 0 .../{ => filter_functions}/xBRZ/xbrz.cpp | 0 .../{ => filter_functions}/xBRZ/xbrz.h | 0 src/filters/filter_helper.hpp | 54 ++++++++ src/filters/filters.cpp | 76 ------------ src/filters/filters.hpp | 92 +------------- src/filters/multifilter.cpp | 21 ++-- src/filters/multifilter.hpp | 26 +++- src/filters/new_interframe.hpp | 18 --- src/wx/panel.cpp | 8 +- src/wx/wxvbam.h | 2 - 42 files changed, 302 insertions(+), 229 deletions(-) create mode 100644 src/filters/filter_factory.cpp create mode 100644 src/filters/filter_factory.hpp rename src/filters/{ => filter_functions}/2xSaI.cpp (99%) rename src/filters/{ => filter_functions}/2xSaImmx.asm (100%) rename src/filters/{ => filter_functions}/admame.cpp (99%) rename src/filters/{ => filter_functions}/bilinear.cpp (97%) create mode 100644 src/filters/filter_functions/filters.cpp rename src/filters/{ => filter_functions}/hq/asm/hq3x32.cpp (100%) rename src/filters/{ => filter_functions}/hq/asm/hq3x_16.asm (100%) rename src/filters/{ => filter_functions}/hq/asm/hq3x_32.asm (100%) rename src/filters/{ => filter_functions}/hq/asm/hq4x_16.asm (100%) rename src/filters/{ => filter_functions}/hq/asm/hq4x_32.asm (100%) rename src/filters/{ => filter_functions}/hq/asm/macros.mac (100%) rename src/filters/{ => filter_functions}/hq/c/hq3x_pattern.h (100%) rename src/filters/{ => filter_functions}/hq/c/hq4x_pattern.h (100%) rename src/filters/{ => filter_functions}/hq/c/hq_base.h (100%) rename src/filters/{ => filter_functions}/hq/c/hq_implementation.cpp (100%) rename src/filters/{ => filter_functions}/hq/c/hq_shared.h (100%) rename src/filters/{ => filter_functions}/hq2x.cpp (98%) rename src/filters/{ => filter_functions}/hq2x.h (100%) rename src/filters/{ => filter_functions}/interframe.cpp (99%) rename src/filters/{ => filter_functions}/interp.h (100%) rename src/filters/{ => filter_functions}/lq2x.h (100%) rename src/filters/{ => filter_functions}/new_interframe.cpp (96%) rename src/filters/{ => filter_functions}/pixel.cpp (95%) rename src/filters/{ => filter_functions}/scanline.cpp (97%) rename src/filters/{ => filter_functions}/sdl.cpp (99%) rename src/filters/{ => filter_functions}/simpleFilter.cpp (98%) rename src/filters/{ => filter_functions}/xBRZ/Changelog.txt (100%) rename src/filters/{ => filter_functions}/xBRZ/License.txt (100%) rename src/filters/{ => filter_functions}/xBRZ/config.h (100%) rename src/filters/{ => filter_functions}/xBRZ/xbrz.cpp (100%) rename src/filters/{ => filter_functions}/xBRZ/xbrz.h (100%) create mode 100644 src/filters/filter_helper.hpp delete mode 100644 src/filters/filters.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d855eef..27a82f06 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -271,22 +271,24 @@ SET(SRC_SDL ) SET(SRC_FILTERS - src/filters/filters.cpp - src/filters/new_interframe.cpp - src/filters/2xSaI.cpp - src/filters/admame.cpp - src/filters/bilinear.cpp - src/filters/hq2x.cpp - src/filters/interframe.cpp - src/filters/pixel.cpp - src/filters/scanline.cpp - src/filters/simpleFilter.cpp - src/filters/sdl.cpp - src/filters/xBRZ/xbrz.cpp + src/filters/filter_factory.cpp + src/filters/multifilter.cpp + src/filters/filter_functions/filters.cpp + src/filters/filter_functions/new_interframe.cpp + src/filters/filter_functions/2xSaI.cpp + src/filters/filter_functions/admame.cpp + src/filters/filter_functions/bilinear.cpp + src/filters/filter_functions/hq2x.cpp + src/filters/filter_functions/interframe.cpp + src/filters/filter_functions/pixel.cpp + src/filters/filter_functions/scanline.cpp + src/filters/filter_functions/simpleFilter.cpp + src/filters/filter_functions/sdl.cpp + src/filters/filter_functions/xBRZ/xbrz.cpp ) SET(SRC_HQ_C - src/filters/hq/c/hq_implementation.cpp + src/filters/filter_functions/hq/c/hq_implementation.cpp ) SET(SRC_HQ_ASM diff --git a/src/filters/filter_factory.cpp b/src/filters/filter_factory.cpp new file mode 100644 index 00000000..cda6ac0d --- /dev/null +++ b/src/filters/filter_factory.cpp @@ -0,0 +1,116 @@ + +#include "filter_factory.hpp" +#include "filters.hpp" +#include "new_interframe.hpp" + +#include +typedef uint8_t u8; +typedef uint32_t u32; + + +// Function pointer type for a raw filter function +typedef void(*FilterFunc)(u8*, u32, u8*, u32, int, int); + +typedef std::pair namedfilter; + +//Actually make the fitlermap (since C++11 doesn't work right now) +const std::map makeFilterMap() +{ + std::map tempMap; + + tempMap.insert(namedfilter("Pixelate",Pixelate32)); + tempMap.insert(namedfilter("Scanlines",Scanlines32)); + tempMap.insert(namedfilter("TV Mode",ScanlinesTV32)); + + //These require Init_2xSaI(u32 BitFormat); + tempMap.insert(namedfilter("Simple 2x",Simple2x32)); + tempMap.insert(namedfilter("Simple 3x",Simple3x32)); + tempMap.insert(namedfilter("Simple 4x",Simple4x32)); + + tempMap.insert(namedfilter("Bilinear",Bilinear32)); + tempMap.insert(namedfilter("Bilinear Plus",BilinearPlus32)); + tempMap.insert(namedfilter("Advance MAME Scale2x",AdMame2x32)); + + //These require Init_2xSaI(u32 BitFormat); + tempMap.insert(namedfilter("2xSaI",_2xSaI32)); + tempMap.insert(namedfilter("Super 2xSaI",Super2xSaI32)); + tempMap.insert(namedfilter("Super Eagle",SuperEagle32)); + + //These require calling hq2x_init first and whenever bpp changes + tempMap.insert(namedfilter("HQ 2x",hq2x32)); + tempMap.insert(namedfilter("LQ 2x",lq2x32)); + + tempMap.insert(namedfilter("HQ 3x",hq3x32)); + tempMap.insert(namedfilter("HQ 4x",hq4x32)); + + //These require sdlStretchInit + tempMap.insert(namedfilter("sdlStretch1x",sdlStretch1x)); + tempMap.insert(namedfilter("sdlStretch2x",sdlStretch2x)); + tempMap.insert(namedfilter("sdlStretch3x",sdlStretch3x)); + tempMap.insert(namedfilter("sdlStretch4x",sdlStretch4x)); + + return tempMap; +} + +///A named map of all the (original) filters +const std::map filterMap = makeFilterMap(); + +///Returns the filter's scaling factor +///TODO: De hardcode this +static int GetFilterScale(std::string filterName) +{ + if(filterName == "HQ 4x" || filterName == "Simple 4x") + return 4; + if(filterName == "HQ 3x" || filterName == "Simple 3x") + return 3; + if(filterName == "None") + return 1; + return 2; +} + +filter_base * filter_factory::createFilter(std::string filterName,unsigned int width,unsigned int height) +{ + + // Initialize the filters + // This is the best place to do this, even if they aren't ever used + // \HACK: Shouldn't have to initialize anything + hq2x_init(32); + Init_2xSaI(32); + + //Search the raw filters first + std::map::const_iterator found = filterMap.find(filterName); + //If we found the filter: + if(found != filterMap.end()){ + return new raw_filter(filterName,found->second,GetFilterScale(filterName),width,height); + } + + if("XBR 2x" == filterName) + { + return new xbr(width,height,2); + } + if("XBR 3x" == filterName) + { + return new xbr(width,height,3); + } + if("XBR 4x" == filterName) + { + return new xbr(width,height,4); + } + if("XBR 5x" == filterName) + { + return new xbr(width,height,5); + } + if("Smart interframe blending" == filterName) + { + return new SmartIB(width,height); + } + if("Interframe motion blur" == filterName) + { + return new MotionBlurIB(width,height); + } + + //If nothing found, just return a default filter + return new filter_base(width,height); +} + + diff --git a/src/filters/filter_factory.hpp b/src/filters/filter_factory.hpp new file mode 100644 index 00000000..8c5af5d0 --- /dev/null +++ b/src/filters/filter_factory.hpp @@ -0,0 +1,18 @@ +///Use this to select/create the filter to use +#ifndef FILTER_FACTORY_HPP +#define FILTER_FACTORY_HPP + +#include +#include + +#include "filter_base.hpp" + +class filter_factory +{ +public: + ///Returns an instance of a filter of filterName + ///If the filter doesn't exist, it returns a dummy filter instead + static filter_base* createFilter(std::string filterName,unsigned int width,unsigned int height); +}; + +#endif //FILTER_FACTORY_HPP diff --git a/src/filters/2xSaI.cpp b/src/filters/filter_functions/2xSaI.cpp similarity index 99% rename from src/filters/2xSaI.cpp rename to src/filters/filter_functions/2xSaI.cpp index b58196e8..0b076a0f 100644 --- a/src/filters/2xSaI.cpp +++ b/src/filters/filter_functions/2xSaI.cpp @@ -1,5 +1,10 @@ -#include "../System.h" +#include +typedef uint8_t u8; +typedef uint16_t u16; +typedef uint32_t u32; + +extern int systemColorDepth; extern int RGB_LOW_BITS_MASK; extern "C" diff --git a/src/filters/2xSaImmx.asm b/src/filters/filter_functions/2xSaImmx.asm similarity index 100% rename from src/filters/2xSaImmx.asm rename to src/filters/filter_functions/2xSaImmx.asm diff --git a/src/filters/admame.cpp b/src/filters/filter_functions/admame.cpp similarity index 99% rename from src/filters/admame.cpp rename to src/filters/filter_functions/admame.cpp index e0359fbf..af00b1a8 100644 --- a/src/filters/admame.cpp +++ b/src/filters/filter_functions/admame.cpp @@ -35,7 +35,9 @@ * - the whole source code of the program is released with the binary. */ -#include "../System.h" +#include +typedef uint8_t u8; +typedef uint32_t u32; #ifdef MMX extern "C" bool cpu_mmx; diff --git a/src/filters/bilinear.cpp b/src/filters/filter_functions/bilinear.cpp similarity index 97% rename from src/filters/bilinear.cpp rename to src/filters/filter_functions/bilinear.cpp index 00fa2597..cb04f1b4 100644 --- a/src/filters/bilinear.cpp +++ b/src/filters/filter_functions/bilinear.cpp @@ -4,7 +4,13 @@ ** Written: 6/14/00 - JSF **/ -#include "../System.h" +#include +typedef uint8_t u8; +typedef uint32_t u32; + +extern int systemRedShift; +extern int systemGreenShift; +extern int systemBlueShift; #define RGB(r,g,b) ((r)>>3) << systemRedShift |\ ((g) >> 3) << systemGreenShift |\ diff --git a/src/filters/filter_functions/filters.cpp b/src/filters/filter_functions/filters.cpp new file mode 100644 index 00000000..a1fa8b30 --- /dev/null +++ b/src/filters/filter_functions/filters.cpp @@ -0,0 +1,14 @@ +#include "../filters.hpp" + +// Initialize color tables +#if wxBYTE_ORDER == wxLITTLE_ENDIAN + int systemRedShift = 3; + int systemGreenShift = 11; + int systemBlueShift = 19; + int RGB_LOW_BITS_MASK = 0x00010101; +#else + int systemRedShift = 27; + int systemGreenShift = 19; + int systemBlueShift = 11; + int RGB_LOW_BITS_MASK = 0x01010100; +#endif diff --git a/src/filters/hq/asm/hq3x32.cpp b/src/filters/filter_functions/hq/asm/hq3x32.cpp similarity index 100% rename from src/filters/hq/asm/hq3x32.cpp rename to src/filters/filter_functions/hq/asm/hq3x32.cpp diff --git a/src/filters/hq/asm/hq3x_16.asm b/src/filters/filter_functions/hq/asm/hq3x_16.asm similarity index 100% rename from src/filters/hq/asm/hq3x_16.asm rename to src/filters/filter_functions/hq/asm/hq3x_16.asm diff --git a/src/filters/hq/asm/hq3x_32.asm b/src/filters/filter_functions/hq/asm/hq3x_32.asm similarity index 100% rename from src/filters/hq/asm/hq3x_32.asm rename to src/filters/filter_functions/hq/asm/hq3x_32.asm diff --git a/src/filters/hq/asm/hq4x_16.asm b/src/filters/filter_functions/hq/asm/hq4x_16.asm similarity index 100% rename from src/filters/hq/asm/hq4x_16.asm rename to src/filters/filter_functions/hq/asm/hq4x_16.asm diff --git a/src/filters/hq/asm/hq4x_32.asm b/src/filters/filter_functions/hq/asm/hq4x_32.asm similarity index 100% rename from src/filters/hq/asm/hq4x_32.asm rename to src/filters/filter_functions/hq/asm/hq4x_32.asm diff --git a/src/filters/hq/asm/macros.mac b/src/filters/filter_functions/hq/asm/macros.mac similarity index 100% rename from src/filters/hq/asm/macros.mac rename to src/filters/filter_functions/hq/asm/macros.mac diff --git a/src/filters/hq/c/hq3x_pattern.h b/src/filters/filter_functions/hq/c/hq3x_pattern.h similarity index 100% rename from src/filters/hq/c/hq3x_pattern.h rename to src/filters/filter_functions/hq/c/hq3x_pattern.h diff --git a/src/filters/hq/c/hq4x_pattern.h b/src/filters/filter_functions/hq/c/hq4x_pattern.h similarity index 100% rename from src/filters/hq/c/hq4x_pattern.h rename to src/filters/filter_functions/hq/c/hq4x_pattern.h diff --git a/src/filters/hq/c/hq_base.h b/src/filters/filter_functions/hq/c/hq_base.h similarity index 100% rename from src/filters/hq/c/hq_base.h rename to src/filters/filter_functions/hq/c/hq_base.h diff --git a/src/filters/hq/c/hq_implementation.cpp b/src/filters/filter_functions/hq/c/hq_implementation.cpp similarity index 100% rename from src/filters/hq/c/hq_implementation.cpp rename to src/filters/filter_functions/hq/c/hq_implementation.cpp diff --git a/src/filters/hq/c/hq_shared.h b/src/filters/filter_functions/hq/c/hq_shared.h similarity index 100% rename from src/filters/hq/c/hq_shared.h rename to src/filters/filter_functions/hq/c/hq_shared.h diff --git a/src/filters/hq2x.cpp b/src/filters/filter_functions/hq2x.cpp similarity index 98% rename from src/filters/hq2x.cpp rename to src/filters/filter_functions/hq2x.cpp index e6ccfe3c..4a458d59 100644 --- a/src/filters/hq2x.cpp +++ b/src/filters/filter_functions/hq2x.cpp @@ -27,7 +27,11 @@ * file, but you are not obligated to do so. If you do not wish to * do so, delete this exception statement from your version. */ -#include "../System.h" +#include +typedef uint8_t u8; +typedef uint16_t u16; +typedef uint32_t u32; + #include "interp.h" /***************************************************************************/ diff --git a/src/filters/hq2x.h b/src/filters/filter_functions/hq2x.h similarity index 100% rename from src/filters/hq2x.h rename to src/filters/filter_functions/hq2x.h diff --git a/src/filters/interframe.cpp b/src/filters/filter_functions/interframe.cpp similarity index 99% rename from src/filters/interframe.cpp rename to src/filters/filter_functions/interframe.cpp index b57beb48..c6ed0a4d 100644 --- a/src/filters/interframe.cpp +++ b/src/filters/filter_functions/interframe.cpp @@ -1,8 +1,11 @@ -#include "../System.h" #include #include -#include "interframe.hpp" +#include +typedef uint8_t u8; +typedef uint32_t u32; + +#include "../interframe.hpp" #ifdef MMX extern "C" bool cpu_mmx; diff --git a/src/filters/interp.h b/src/filters/filter_functions/interp.h similarity index 100% rename from src/filters/interp.h rename to src/filters/filter_functions/interp.h diff --git a/src/filters/lq2x.h b/src/filters/filter_functions/lq2x.h similarity index 100% rename from src/filters/lq2x.h rename to src/filters/filter_functions/lq2x.h diff --git a/src/filters/new_interframe.cpp b/src/filters/filter_functions/new_interframe.cpp similarity index 96% rename from src/filters/new_interframe.cpp rename to src/filters/filter_functions/new_interframe.cpp index a3e6c0df..aa1b25fb 100644 --- a/src/filters/new_interframe.cpp +++ b/src/filters/filter_functions/new_interframe.cpp @@ -2,12 +2,14 @@ // Kawaks' Mr. K for the code // Incorporated into vba by Anthony Di Franco // Converted to C++ by Arthur Moore -#include "../System.h" #include #include #include -#include "new_interframe.hpp" +#include +typedef uint32_t u32; + +#include "../new_interframe.hpp" SmartIB::SmartIB(unsigned int _width,unsigned int _height): filter_base(_width,_height) { diff --git a/src/filters/pixel.cpp b/src/filters/filter_functions/pixel.cpp similarity index 95% rename from src/filters/pixel.cpp rename to src/filters/filter_functions/pixel.cpp index e1fb97f3..06e79114 100644 --- a/src/filters/pixel.cpp +++ b/src/filters/filter_functions/pixel.cpp @@ -1,4 +1,7 @@ -#include "../System.h" + +#include +typedef uint8_t u8; +typedef uint32_t u32; extern int RGB_LOW_BITS_MASK; diff --git a/src/filters/scanline.cpp b/src/filters/filter_functions/scanline.cpp similarity index 97% rename from src/filters/scanline.cpp rename to src/filters/filter_functions/scanline.cpp index 4df45739..460e6ffb 100644 --- a/src/filters/scanline.cpp +++ b/src/filters/filter_functions/scanline.cpp @@ -1,4 +1,7 @@ -#include "../System.h" + +#include +typedef uint8_t u8; +typedef uint32_t u32; extern int RGB_LOW_BITS_MASK; diff --git a/src/filters/sdl.cpp b/src/filters/filter_functions/sdl.cpp similarity index 99% rename from src/filters/sdl.cpp rename to src/filters/filter_functions/sdl.cpp index 64bf98b6..aed2f6d8 100644 --- a/src/filters/sdl.cpp +++ b/src/filters/filter_functions/sdl.cpp @@ -1,5 +1,8 @@ -#include "../System.h" +#include +typedef uint8_t u8; +typedef uint16_t u16; +typedef uint32_t u32; // // Optimized stretchers implementation diff --git a/src/filters/simpleFilter.cpp b/src/filters/filter_functions/simpleFilter.cpp similarity index 98% rename from src/filters/simpleFilter.cpp rename to src/filters/filter_functions/simpleFilter.cpp index ebc0efdb..c78bb44d 100644 --- a/src/filters/simpleFilter.cpp +++ b/src/filters/filter_functions/simpleFilter.cpp @@ -1,4 +1,7 @@ -#include "../System.h" + +#include +typedef uint8_t u8; +typedef uint32_t u32; void Simple2x32(u8 *srcPtr, u32 srcPitch, u8 *dstPtr, u32 dstPitch, int width, int height) diff --git a/src/filters/xBRZ/Changelog.txt b/src/filters/filter_functions/xBRZ/Changelog.txt similarity index 100% rename from src/filters/xBRZ/Changelog.txt rename to src/filters/filter_functions/xBRZ/Changelog.txt diff --git a/src/filters/xBRZ/License.txt b/src/filters/filter_functions/xBRZ/License.txt similarity index 100% rename from src/filters/xBRZ/License.txt rename to src/filters/filter_functions/xBRZ/License.txt diff --git a/src/filters/xBRZ/config.h b/src/filters/filter_functions/xBRZ/config.h similarity index 100% rename from src/filters/xBRZ/config.h rename to src/filters/filter_functions/xBRZ/config.h diff --git a/src/filters/xBRZ/xbrz.cpp b/src/filters/filter_functions/xBRZ/xbrz.cpp similarity index 100% rename from src/filters/xBRZ/xbrz.cpp rename to src/filters/filter_functions/xBRZ/xbrz.cpp diff --git a/src/filters/xBRZ/xbrz.h b/src/filters/filter_functions/xBRZ/xbrz.h similarity index 100% rename from src/filters/xBRZ/xbrz.h rename to src/filters/filter_functions/xBRZ/xbrz.h diff --git a/src/filters/filter_helper.hpp b/src/filters/filter_helper.hpp new file mode 100644 index 00000000..726e2447 --- /dev/null +++ b/src/filters/filter_helper.hpp @@ -0,0 +1,54 @@ +///A few useful helper functions + +#ifndef FILTER_HELPER_HPP +#define FILTER_HELPER_HPP + + +/** + * Convert a 32 bit image to a 24 bit one + * + * This centralizes a decent bit of code. + * NOTE: This takes width and height, and ASSUMES they are accurate!!!!! + * + * \param[in] src A pointer to the input 32 bit RGB Pixel Array + * \param[in] dst A pointer to the output 24 bit RGB Pixel Array + * \param[in] width The image width (in pixels) + * \param[in] height The height width (in pixels) + */ +inline void convert32To24(u32* src,u8* dst,unsigned int width, unsigned int height) +{ + //Need src as a single byte pointer for this to work + u8 * u8src = (u8*)src; + + for(unsigned int y = 0; y < height ; y++) + { + for(unsigned int x = 0; x < width; x++) + { + //For each pixel copy r,g,b one byte at a time + for(unsigned int i = 0; i<3; i++) + { + *dst++ = *u8src++; + } + //Skip the alpha channel + u8src++; + } + } +} + +/** + * Get a pointer to the first pixel of a row inside an image + * + * NOTE: If width or vertical_offset is too large, this function WILL produce an invalid pointer + * + * \param[in] image_pointer A pointer to the start of an image + * \param[in] width The image's width + * \param[in] vertical_offset How many rows from the start of the image + * \param[in] scale How much larger the output image will be + * \return A pointer to the first pixel in the chosen row + */ +inline u32 * GetVerticalOffset(u32 * image_pointer,unsigned int width,unsigned int vertical_offset,unsigned int scale=1) +{ + return image_pointer + (width * vertical_offset*scale*scale); +} + +#endif //FILTER_HELPER_HPP diff --git a/src/filters/filters.cpp b/src/filters/filters.cpp deleted file mode 100644 index c08718ca..00000000 --- a/src/filters/filters.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include "filters.hpp" - -//Actually make the fitlermap (since C++11 doesn't work right now) -const std::map makeFilterMap() -{ - std::map tempMap; - - tempMap.insert(namedfilter("Pixelate",Pixelate32)); - tempMap.insert(namedfilter("Scanlines",Scanlines32)); - tempMap.insert(namedfilter("TV Mode",ScanlinesTV32)); - - //These require Init_2xSaI(u32 BitFormat); - tempMap.insert(namedfilter("Simple 2x",Simple2x32)); - tempMap.insert(namedfilter("Simple 3x",Simple3x32)); - tempMap.insert(namedfilter("Simple 4x",Simple4x32)); - - tempMap.insert(namedfilter("Bilinear",Bilinear32)); - tempMap.insert(namedfilter("Bilinear Plus",BilinearPlus32)); - tempMap.insert(namedfilter("Advance MAME Scale2x",AdMame2x32)); - - //These require Init_2xSaI(u32 BitFormat); - tempMap.insert(namedfilter("2xSaI",_2xSaI32)); - tempMap.insert(namedfilter("Super 2xSaI",Super2xSaI32)); - tempMap.insert(namedfilter("Super Eagle",SuperEagle32)); - - //These require calling hq2x_init first and whenever bpp changes - tempMap.insert(namedfilter("HQ 2x",hq2x32)); - tempMap.insert(namedfilter("LQ 2x",lq2x32)); - - tempMap.insert(namedfilter("HQ 3x",hq3x32)); - tempMap.insert(namedfilter("HQ 4x",hq4x32)); - - //These require sdlStretchInit - tempMap.insert(namedfilter("sdlStretch1x",sdlStretch1x)); - tempMap.insert(namedfilter("sdlStretch2x",sdlStretch2x)); - tempMap.insert(namedfilter("sdlStretch3x",sdlStretch3x)); - tempMap.insert(namedfilter("sdlStretch4x",sdlStretch4x)); - - return tempMap; -} - -const std::map filter_factory::filterMap = makeFilterMap(); - -//Convert a 32 bit image to a 24 bit one -void convert32To24(u32* src,u8* dst,unsigned int width, unsigned int height) -{ - //Need src as a single byte pointer for this to work - u8 * u8src = (u8*)src; - - for(unsigned int y = 0; y < height ; y++) - { - for(unsigned int x = 0; x < width; x++) - { - //For each pixel copy r,g,b one byte at a time - for(unsigned int i = 0; i<3; i++) - { - *dst++ = *u8src++; - } - //Skip the alpha channel - u8src++; - } - } -} - -// Intialize color tables -#if wxBYTE_ORDER == wxLITTLE_ENDIAN - int systemRedShift = 3; - int systemGreenShift = 11; - int systemBlueShift = 19; - int RGB_LOW_BITS_MASK = 0x00010101; -#else - int systemRedShift = 27; - int systemGreenShift = 19; - int systemBlueShift = 11; - int RGB_LOW_BITS_MASK = 0x01010100; -#endif diff --git a/src/filters/filters.hpp b/src/filters/filters.hpp index 4526d815..7dce8254 100644 --- a/src/filters/filters.hpp +++ b/src/filters/filters.hpp @@ -2,15 +2,15 @@ #ifndef FILTERS_FILTERS_HPP #define FILTERS_FILTERS_HPP -#include #include #include -#include -#include //For memcpy -#include "../common/Types.h" +#include +typedef uint8_t u8; +typedef uint32_t u32; + #include "filter_base.hpp" -#include "xBRZ/xbrz.h" +#include "filter_functions/xBRZ/xbrz.h" //sdl // Function pointer type for a filter function @@ -39,7 +39,6 @@ public: horiz_bytes(_width * 4), horiz_bytes_out(_width * 4 * _scale) { this->setScale(_scale); -// std::cerr << name << std::endl; } std::string getName() {return name;} bool exists() {return true;} @@ -74,59 +73,6 @@ public: } }; -typedef std::pair namedfilter; - -class filter_factory -{ -private: - //A named map of all the (original) filters - static const std::map filterMap; -public: - ///Returns an instance of a filter of filterName - ///If the filter doesn't exist, it returns a dummy filter instead - static filter_base * createFilter(std::string filterName,unsigned int width,unsigned int height) - { - std::map::const_iterator found = filterMap.find(filterName); - //If we found the filter: - if(found != filterMap.end()){ - return new raw_filter(filterName,found->second,GetFilterScale(filterName),width,height); - } - - if("XBR 2x" == filterName) - { - return new xbr(width,height,2); - } - if("XBR 3x" == filterName) - { - return new xbr(width,height,3); - } - if("XBR 4x" == filterName) - { - return new xbr(width,height,4); - } - if("XBR 5x" == filterName) - { - return new xbr(width,height,5); - } - - //If nothing found, just return a default filter - return new filter_base(width,height); - } - - ///Returns the filter's scaling factor - ///TODO: De hardcode this - static int GetFilterScale(std::string filterName) - { - if(filterName == "HQ 4x" || filterName == "Simple 4x") - return 4; - if(filterName == "HQ 3x" || filterName == "Simple 3x") - return 3; - if(filterName == "None") - return 1; - return 2; - } -}; - //These are the available filters //wx @@ -218,33 +164,5 @@ extern void sdlStretch2x(u8*,u32,u8*,u32,int,int); extern void sdlStretch3x(u8*,u32,u8*,u32,int,int); extern void sdlStretch4x(u8*,u32,u8*,u32,int,int); -/** - * Convert a 32 bit image to a 24 bit one - * - * This centralizes a decent bit of code. - * NOTE: This takes width and height, and ASSUMES they are accurate!!!!! - * - * \param[in] src A pointer to the input 32 bit RGB Pixel Array - * \param[in] dst A pointer to the output 24 bit RGB Pixel Array - * \param[in] width The image width (in pixels) - * \param[in] height The height width (in pixels) - */ -void convert32To24(u32* src,u8* dst,unsigned int width, unsigned int height); - -/** - * Get a pointer to the first pixel of a row inside an image - * - * NOTE: If width or vertical_offset is too large, this function WILL produce an invalid pointer - * - * \param[in] image_pointer A pointer to the start of an image - * \param[in] width The image's width - * \param[in] vertical_offset How many rows from the start of the image - * \param[in] scale How much larger the output image will be - * \return A pointer to the first pixel in the chosen row - */ -inline u32 * GetVerticalOffset(u32 * image_pointer,unsigned int width,unsigned int vertical_offset,unsigned int scale=1) -{ - return image_pointer + (width * vertical_offset*scale*scale); -} #endif //FILTERS_FILTERS_HPP diff --git a/src/filters/multifilter.cpp b/src/filters/multifilter.cpp index 620b9a02..a97def68 100644 --- a/src/filters/multifilter.cpp +++ b/src/filters/multifilter.cpp @@ -6,18 +6,19 @@ ***********************************************************************/ #include "multifilter.hpp" #include "filter_base.hpp" +#include "filter_factory.hpp" /*********************************************************************** * Method: multifilter::multifilter * Params: std::vector filters, unsigned int X, unsigned int, Y * Effects: ***********************************************************************/ -multifilter::multifilter(std::vector filters, unsigned int X, unsigned int, Y): +multifilter::multifilter(std::vector filters, unsigned int X, unsigned int Y): filterNames(filters),numFilters(filters.size()),inX(X),inY(Y) { //Do the first one separate filter_base * aFilter = filter_factory::createFilter(filters[0],X,Y); - filterPtrs.append(aFilter); + filterPtrs.push_back(aFilter); for(unsigned int i=1;i filters, unsigned int X, unsig Y=aFilter->getOutHeight(); //Create, and append the new filter aFilter = filter_factory::createFilter(filters[i],X,Y); - filterPtrs.append(aFilter); + filterPtrs.push_back(aFilter); //Create and append the buffers u32* aBuffer = new u32[X*Y]; - filterBuffers.append(aBuffer); + filterBuffers.push_back(aBuffer); } } @@ -39,7 +40,7 @@ multifilter::multifilter(std::vector filters, unsigned int X, unsig * Params: * Effects: ***********************************************************************/ -multifilter::getOutX() +unsigned int multifilter::getOutX() { filterPtrs.back()->getOutWidth(); } @@ -50,7 +51,7 @@ multifilter::getOutX() * Params: * Effects: ***********************************************************************/ -multifilter::getOutY() +unsigned int multifilter::getOutY() { filterPtrs.back()->getOutHeight(); } @@ -61,7 +62,7 @@ multifilter::getOutY() * Params: u32 *image * Effects: ***********************************************************************/ -multifilter::setInImage(u32 *image) +void multifilter::setInImage(u32 *image) { inImage=image; } @@ -72,7 +73,7 @@ multifilter::setInImage(u32 *image) * Params: u32 *image * Effects: ***********************************************************************/ -multifilter::setOutImage(u32 *image) +void multifilter::setOutImage(u32 *image) { outImage=image; } @@ -83,7 +84,7 @@ multifilter::setOutImage(u32 *image) * Params: * Effects: ***********************************************************************/ -multifilter::run() +void multifilter::run() { //Do the first one separate filterPtrs[0]->run(inImage,filterBuffers[0]); @@ -94,5 +95,3 @@ multifilter::run() //Do the last one separate filterPtrs.back()->run(filterBuffers.back(),outImage); } - - diff --git a/src/filters/multifilter.hpp b/src/filters/multifilter.hpp index 46184148..d0000af2 100644 --- a/src/filters/multifilter.hpp +++ b/src/filters/multifilter.hpp @@ -1,4 +1,15 @@ +#ifndef MULTIFILTER_HPP +#define MULTIFILTER_HPP + +#include +#include + +#include +typedef uint32_t u32; + +class filter_base; + class multifilter { private: @@ -19,12 +30,12 @@ private: ///Output image buffer u32* outImage; public: - multifilter(std::vector filters,unsigned int X,unsigned int, Y); - getOutX(); - getOutY(); - setInImage(u32* image); - setOutImage(u32* image); - run(); + multifilter(std::vector filters,unsigned int X,unsigned int Y); + unsigned int getOutX(); + unsigned int getOutY(); + void setInImage(u32* image); + void setOutImage(u32* image); + void run(); }; /* @@ -36,3 +47,6 @@ public: * myFilters.setOutImage(outImage); * myFilters.run(); */ + + +#endif //MULTIFILTER_HPP diff --git a/src/filters/new_interframe.hpp b/src/filters/new_interframe.hpp index 505a6fe9..15e546ba 100644 --- a/src/filters/new_interframe.hpp +++ b/src/filters/new_interframe.hpp @@ -40,22 +40,4 @@ public: bool exists() {return true;} }; -///Use this to select/create the filter to use -class interframe_factory -{ -public: - static filter_base * createIFB(std::string filterName,unsigned int width,unsigned int height) - { - if(filterName == "Smart interframe blending") - { - return new SmartIB(width,height); - } - else if(filterName == "Interframe motion blur") - { - return new MotionBlurIB(width,height); - } - return new filter_base(width,height); - } -}; - #endif //NEW_INTERFRAME_HPP diff --git a/src/wx/panel.cpp b/src/wx/panel.cpp index b897ddf7..4f312e32 100644 --- a/src/wx/panel.cpp +++ b/src/wx/panel.cpp @@ -6,7 +6,9 @@ #include "../common/Patch.h" #include #include "../sdl/text.h" -#include "../filters/filters.hpp" +#include "../filters/filter_helper.hpp" +#include "../filters/filter_factory.hpp" + int emulating; @@ -24,8 +26,6 @@ GameArea::GameArea() // all renderers prefer 32-bit // well, "simple" prefers 24-bit, but that's not available for filters systemColorDepth = 32; - hq2x_init(32); - Init_2xSaI(32); } void GameArea::LoadGame(const wxString &name) @@ -1099,7 +1099,7 @@ DrawingPanel::DrawingPanel(int _width, int _height) : threads[i].band_lower = band_height * i; threads[i].dst = reinterpret_cast(&todraw); threads[i].mainFilter=filter_factory::createFilter(ToString(gopts.filter),width,band_height); - threads[i].iFilter=interframe_factory::createIFB(ToString(gopts.ifb),width,band_height); + threads[i].iFilter=filter_factory::createFilter(ToString(gopts.ifb),width,band_height); threads[i].done = &filt_done; threads[i].lock.Lock(); threads[i].Create(); diff --git a/src/wx/wxvbam.h b/src/wx/wxvbam.h index aee28b2f..692f04cf 100644 --- a/src/wx/wxvbam.h +++ b/src/wx/wxvbam.h @@ -27,8 +27,6 @@ #include "../gb/gbCheats.h" #include "../gba/Cheats.h" -#include "../filters/new_interframe.hpp" - template void CheckPointer(T pointer) {