From 0efd3e40992129dae80d7f9a4b8fe740a4f2e6e3 Mon Sep 17 00:00:00 2001 From: Arthur Moore Date: Tue, 10 Mar 2015 01:28:12 -0400 Subject: [PATCH] Simplified the filter system even further --- src/filters/filters.hpp | 64 +++++++++++++++++++++++++++++++++++++---- src/wx/panel.cpp | 35 +++++++++++----------- 2 files changed, 78 insertions(+), 21 deletions(-) diff --git a/src/filters/filters.hpp b/src/filters/filters.hpp index 80ba1d1c..bea5afc2 100644 --- a/src/filters/filters.hpp +++ b/src/filters/filters.hpp @@ -5,7 +5,7 @@ #include #include #include -// #include +#include #include "interframe.hpp" #include "../common/Types.h" @@ -77,9 +77,15 @@ private: FilterFunc myFilter; ///The internal scale int myScale; + ///The filter's width + unsigned int width; + ///Don't need to calculate these every time (based off width) + unsigned int horiz_bytes; + unsigned int horiz_bytes_out; public: filter(std::string myName): - name(myName), myFilter(filters::GetFilter(myName)), myScale(filters::GetFilterScale(myName)) + name(myName), myFilter(filters::GetFilter(myName)), myScale(filters::GetFilterScale(myName)), + width(0), horiz_bytes(0), horiz_bytes_out(0) { // std::cerr << name << std::endl; } @@ -87,22 +93,70 @@ public: { return name; } + ///Set the number of pixels per horizontal row + /// + ///Always use this after initialization if using the new run function. + void setWidth(unsigned int _width) + { + width = _width; + + //32 bit filter, so 8 bytes per pixel + // The +1 is for a 1 pixel border that the emulator spits out + horiz_bytes = (width+1) * 4; + //Unfortunately, the filter keeps the border on the scaled output, but DOES NOT scale it + horiz_bytes_out = width * 4 * myScale + 4; + + } + unsigned int getWidth() + { + return width; + } int getScale() { return myScale; } - void run(u8 *srcPtr, u32 srcPitch, u8 *deltaPtr, u8 *dstPtr, u32 dstPitch, int width, int height) + /** + * New Version: Run the filter + * + * This one is smart. + * It knows it's a 32 bit filter, and the input width will not change from when it is initialized. + * + * \param[in] srcPtr A pointer to a 16/32 bit RGB Pixel Array + */ + void run(u8 *srcPtr, u8 *deltaPtr, u8 *dstPtr, int height) { -// std::cerr << name <<": srcPitch: "<getScale(); + myFilter->setWidth(width); + + std::cerr << "width: " << width << " Height: " << height << std::endl; #define out_16 (systemColorDepth == 16) systemColorDepth = 32; @@ -1073,18 +1076,18 @@ public: // threadno == -1 means just do a dummy round on the border line int band_lower = band_height * threadno; - //The number of bytes per pixel, as determined by the systemColorDepth - int bytes_per_pixel = systemColorDepth/8; + //The number of bytes for each 32 bit pixel + int bytes_per_pixel = 4; - int inrb = systemColorDepth == 16 ? 2 : systemColorDepth == 24 ? 0 : 1; - int instride = (width + inrb) * bytes_per_pixel; + //This is the number of bytes per single horizontal line + // The +1 is for a 1 pixel border + int horiz_bytes = (width + 1) * bytes_per_pixel; + //Unfortunately, the filter keeps the border on the scaled output, but DOES NOT scale it + int horiz_bytes_out = width * bytes_per_pixel * scale + bytes_per_pixel; - int outrb = systemColorDepth == 24 ? 0 : 4; - int outstride = width * bytes_per_pixel * scale + outrb; - - delta += instride * band_lower; + delta += horiz_bytes * band_lower; // + 1 for stupid top border - dst += outstride * (band_lower + 1) * scale; + dst += horiz_bytes_out * (band_lower + 1) * scale; while(nthreads == 1 || sig.Wait() == wxCOND_NO_ERROR) { if(!src /* && nthreads > 1 */ ) { @@ -1092,7 +1095,7 @@ public: return 0; } // + 1 for stupid top border - src += instride; + src += horiz_bytes; // interframe blending filter // definitely not thread safe by default // added band_lower param to provide offset into accum buffers @@ -1100,16 +1103,16 @@ public: switch(gopts.ifb) { case IFB_SMART: if(systemColorDepth == 16) - SmartIB(src, instride, width, band_lower, band_height); + SmartIB(src, horiz_bytes, width, band_lower, band_height); else - SmartIB32(src, instride, width, band_lower, band_height); + SmartIB32(src, horiz_bytes, width, band_lower, band_height); break; case IFB_MOTION_BLUR: // FIXME: if(renderer == d3d/gl && filter == NONE) break; if(systemColorDepth == 16) - MotionBlurIB(src, instride, width, band_lower, band_height); + MotionBlurIB(src, horiz_bytes, width, band_lower, band_height); else - MotionBlurIB32(src, instride, width, band_lower, band_height); + MotionBlurIB32(src, horiz_bytes, width, band_lower, band_height); break; } } @@ -1126,11 +1129,11 @@ public: continue; } - src += instride * band_lower; + src += horiz_bytes * band_lower; // naturally, any of these with accumulation buffers like those of // the IFB filters will screw up royally as well - mainFilter->run(src, instride, delta, dst, outstride, width, band_height); + mainFilter->run(src, delta, dst, band_height); if(nthreads == 1) return 0;