Hello every,
I have a problem that no matter my app is running on constant 30 or 60 fps, it has a slightly less frame rate when doing the following color filtering function applyFilter().
e.g. if I set the app to be 30fps, it will fall to 28 or 29 whenever it performs the applyFilter().
Likewise it has a frame rate of 58 or 59 when set to 60.
void ofApp::applyFilter() {
int w = imageBuffer.getWidth();
int h = imageBuffer.getHeight();
int channelCount = imageBuffer.getPixelsRef().getNumChannels();
for (int y = 0; y < h; y++) {
unsigned char * cursor = imageBuffer.getPixels() + ((w * channelCount) * y);
for (int x = 0; x < w - 1; x++) {
double tintPercentage = .25;
ofColor filterColor = ofColor::green;
// cout << "Before: " << cursor[0] << " " << cursor[1] << " " << cursor[2] << endl;
int a0 = cursor[0];
int a1 = cursor[1];
int a2 = cursor[2];
cursor[0] = cursor[0] + (tintPercentage * (filterColor.r - cursor[0]));
cursor[1] = cursor[1] + (tintPercentage * (filterColor.g - cursor[1]));
cursor[2] = cursor[2] + (tintPercentage * (filterColor.b - cursor[2]));
// cout << "After: " << cursor[0] << " " << cursor[1] << " " << cursor[2] << endl;
int b0 = cursor[0];
int b1 = cursor[1];
int b2 = cursor[2];
cursor += channelCount;
}
}
imageBuffer.update();
}
Bascially my app is to load an image sequence dynamically and do applyFilter() on each loaded image.
I've tried switched to release mode instead of debug for compiling the app. It helps the frame rate a bit but the problem is still there.
I think it is because I cannot make full use of my CPU resource (2 core 4 thread) since I do not know how to use ofThread. (I am just using ofxThreadedImageLoader to preload a bunch of images.)
Or is there any workaround to the problem?
Thanks!