Converted interframe_filter to a generic filter base class.

I can now convert normal filters to use this same base class :)
This commit is contained in:
Arthur Moore 2015-03-12 23:58:59 -04:00
parent 2183928eee
commit 3ba74db8c0
4 changed files with 60 additions and 50 deletions

View File

@ -0,0 +1,35 @@
///Base class for all filters
#ifndef FILTER_BASE_HPP
#define FILTER_BASE_HPP
#include "../common/Types.h"
#include <string>
#include <cstring> //For memcpy
///Base class for all filters
class filter_base
{
private:
//Need to give the filter a width,height at initialization
filter_base();
///The filter's width
unsigned int width;
///The filter's height
unsigned int height;
public:
filter_base(unsigned int _width,unsigned int _height): width(_width),height(_height) {}
virtual ~filter_base() {}
unsigned int getWidth() {return width;}
unsigned int getHeight() {return height;}
virtual std::string getName() {return "Dummy Filter";}
virtual int getScale() {return 1;}
virtual bool exists() {return false;}
///Take data from srcPtr, and return the new data via dstPtr
virtual void run(u32 *srcPtr,u32 *dstPtr)
{
//If the filter doesn't exist, then we still need to get the data to the output buffer
std::memcpy(dstPtr,srcPtr, getWidth()*getHeight()*4);
}
};
#endif //FILTER_BASE_HPP

View File

@ -9,7 +9,7 @@
#include "new_interframe.hpp"
SmartIB::SmartIB(unsigned int _width,unsigned int _height): interframe_filter(_width,_height)
SmartIB::SmartIB(unsigned int _width,unsigned int _height): filter_base(_width,_height)
{
frm1 = (u32 *)calloc(_width*_height,4);
// 1 frame ago
@ -32,9 +32,8 @@ SmartIB::~SmartIB()
frm1 = frm2 = frm3 = NULL;
}
void SmartIB::run(u32 *srcPtr)
void SmartIB::run(u32 *srcPtr,u32 *dstPtr)
{
u32 *src0 = srcPtr;
u32 *src1 = frm1;
u32 *src2 = frm2;
u32 *src3 = frm3;
@ -43,8 +42,8 @@ void SmartIB::run(u32 *srcPtr)
for (unsigned int i = 0; i < getWidth()*getHeight(); i++)
{
u32 color = src0[i];
src0[i] =
u32 color = srcPtr[i];
dstPtr[i] =
(src1[i] != src2[i]) &&
(src3[i] != color) &&
((color == src2[i]) || (src1[i] == src3[i]))
@ -61,7 +60,7 @@ void SmartIB::run(u32 *srcPtr)
}
MotionBlurIB::MotionBlurIB(unsigned int _width,unsigned int _height): interframe_filter(_width,_height)
MotionBlurIB::MotionBlurIB(unsigned int _width,unsigned int _height): filter_base(_width,_height)
{
//Buffer to hold last frame
frm1 = (u32 *)calloc(_width*_height,4);
@ -74,17 +73,16 @@ MotionBlurIB::~MotionBlurIB()
frm1=NULL;
}
void MotionBlurIB::run(u32 *srcPtr)
void MotionBlurIB::run(u32 *srcPtr,u32 *dstPtr)
{
u32 *src0 = srcPtr;
u32 *src1 = frm1;
u32 colorMask = 0xfefefe;
for (unsigned int i = 0; i < getWidth()*getHeight(); i++)
{
u32 color = src0[i];
src0[i] = (((color & colorMask) >> 1) +
u32 color = srcPtr[i];
dstPtr[i] = (((color & colorMask) >> 1) +
((src1[i] & colorMask) >> 1));
src1[i] = color;
}

View File

@ -5,41 +5,13 @@
#include "../common/Types.h"
#include <string>
class interframe_filter
{
private:
///The filter's width
unsigned int width;
///The filter's height
unsigned int height;
///The internal scale
// int myScale;
///Don't need to calculate these every time (based off width)
// unsigned int horiz_bytes;
// unsigned int horiz_bytes_out;
//Children need this pre-calculated data, but it's NOT public
// protected:
// unsigned int get_horiz_bytes() {return horiz_bytes;}
// unsigned int get_horiz_bytes_out() {return horiz_bytes_out;}
public:
interframe_filter(unsigned int _width=0,unsigned int _height=0): width(_width),height(_height) {}
virtual ~interframe_filter() {}
virtual std::string getName() {return "Dummy Filter";}
virtual int getScale() {return 0;}
unsigned int getWidth() {return width;}
unsigned int getHeight() {return height;}
///New smarter Interframe function
virtual void run(u32 *srcPtr) {}
virtual bool exists() {return false;}
};
#include "filter_base.hpp"
// Interframe blending filters (These are the 32 bit versions)
// definitely not thread safe by default
// added band_lower param to provide offset into accum buffers
class SmartIB : public interframe_filter
class SmartIB : public filter_base
{
private:
u32 *frm1;
@ -50,11 +22,11 @@ public:
SmartIB(unsigned int _width,unsigned int _height);
~SmartIB();
std::string getName() {return "SmartIB";}
void run(u32 *srcPtr);
void run(u32 *srcPtr,u32 *dstPtr);
bool exists() {return true;}
};
class MotionBlurIB : public interframe_filter
class MotionBlurIB : public filter_base
{
private:
u32 *frm1;
@ -64,7 +36,7 @@ public:
MotionBlurIB(unsigned int _width,unsigned int _height);
~MotionBlurIB();
std::string getName() {return "MotionBlurIB";}
void run(u32 *srcPtr);
void run(u32 *srcPtr,u32 *dstPtr);
bool exists() {return true;}
};
@ -78,7 +50,7 @@ enum ifbfunc {
class interframe_factory
{
public:
static interframe_filter * createIFB(ifbfunc filter_select,unsigned int width,unsigned int height)
static filter_base * createIFB(ifbfunc filter_select,unsigned int width,unsigned int height)
{
switch(filter_select)
{
@ -89,7 +61,7 @@ public:
return new MotionBlurIB(width,height);
break;
default:
return new interframe_filter();
return new filter_base(width,height);
break;
}
}
@ -109,4 +81,3 @@ public:
};
#endif //NEW_INTERFRAME_HPP

View File

@ -1006,8 +1006,14 @@ void DrawingPanel::PaintEv(wxPaintEvent &ev)
// interface, I will allow them to be threaded at user's discretion.
class FilterThread : public wxThread
{
private:
// largest buffer required is 32-bit * (max width + 1) * (max height + 2) * (4x4) scaling factor
u32 buffer[257 * 226 * 16];
public:
FilterThread() : wxThread(wxTHREAD_JOINABLE), lock(), sig(lock) {}
FilterThread() : wxThread(wxTHREAD_JOINABLE), lock(), sig(lock) {
//Clear the buffer
memset (buffer,0x00,257 * 4 * 16 * 226);
}
//Cleanup on exit
~FilterThread()
@ -1028,7 +1034,7 @@ public:
unsigned int width, height, scale;
u32 *dst;
filter * mainFilter;
interframe_filter * iFilter;
filter_base * iFilter;
// set this param every round
// if NULL, end thread
@ -1059,11 +1065,11 @@ public:
src += width * band_lower;
//Run the interframe blending filter
iFilter->run(src);
iFilter->run(src,buffer);
// naturally, any of these with accumulation buffers like those of
// the IFB filters will screw up royally as well
mainFilter->run(src, dst, height);
mainFilter->run(buffer, dst, height);
done->Post();
}