Firstly, I am very new to function pointers and their horrible syntax so play nice.
I am writing a method to filter all pixels in my bitmap based on a function that I pass in. I have written the method to dereference it and call it in the pixel buffer but I also need a wrapper method in my bitmap class that takes the function pointer and passes it on. How do I do it? What is the syntax? I'm a little stumped.
Here is my code with all the irrelevant bits stripped out and files combined (read all variables initialized filled etc.).
struct sColour
{
unsigned char r, g, b, a;
};
class cPixelBuffer
{
private:
sColour* _pixels;
int _width;
int _height;
int _buffersize;
public:
void FilterAll(sColour (*FilterFunc)(sColour));
};
void cPixelBuffer::FilterAll(sColour (*FilterFunc)(sColour))
{
// fast fast fast hacky FAST
for (int i = 0; i < _buffersize; i++)
{
_pixels[i] = (*FilterFunc)(_pixels[i]);
}
}
class cBitmap
{
private:
cPixelBuffer* _pixels;
public:
inline void cBitmap::Filter(sColour (*FilterFunc)(sColour))
{
//HERE!!
}
};