I’m developing a slideshow of sorts that bring images from a database of thousands of images. I wrote some methods but I need the image load to be threaded and smooth using my video card GPU. This WImage class allows me to load some images in a few layers from a list of images (mempic) that are loaded in the main loop, but every time it loads a new batch of files the whole thing lags a bit. Any ideas in how to achieve a smoother load in the these WImage layers? Thanks so much for any hint!
WImage.cpp
//
// wImage.cpp
// ofImages
//
//
#include "Wimage.h"
Wimage::Wimage() {
}
void Wimage::setup() {
int wWidth = ofGetWidth(); // get window size
int wHeight = ofGetHeight();
extern float segmentol;
extern float seghoriz;
extern bool bSame;
size = ofRandom(0.3, 1);
if (!bSame) {
newImage();
}
else { sameImage(); }
resize(size);
x = wWidth / 2 - w / 2;
y = wHeight / 2 - h / 2;
w = pic.getWidth();
h = pic.getHeight();
ratio = w / h;
fadespeed = ofRandom(1, 4);
showtime = 120;
alpha = ofRandom(120, 235); // alpha
// fadespeed=3;
t = 100; //ofRandom(100,500);
segmento = int(ofRandom(0, 4));
segmentol++; if (segmentol > 3) segmentol = 0;
segmentolineal = segmentol;
segmentohoriz = int(ofRandom(-8, 8));
w6 = wWidth / 6;
y6 = 0;
seghoriz++; if (seghoriz > 5) seghoriz = 0;
x6 = seghoriz * w6;
seghorizlineal = seghoriz;
// hsegmento = h/4*(ofRandom(1,2));
hsegmento = h / 4;
// hsegmento = ofGetHeight()/4;
//if (segmento == 3) hsegmento = h/4;
// recorte y zoom
sx = ofRandom(0, w / 2);
sy = ofRandom(0, h / 2);
sw = ofRandom(w6 / 4, w6 * 2);
sh = sw * 1.7777;
resize(size);
alphai = 0;
}
void Wimage::update() {
}
void Wimage::fade() {
//extern float fadespeed;
if (fadeout == 0) {
alphai = alphai + fadespeed;
if (alphai > alpha) {
alphai = alpha; fadeout = 1;
}
}
if (fadeout == 1) {
showtime--;
if (showtime <= 0) { fadeout = 2; }
}
if (fadeout == 2) {
alphai = alphai - fadespeed;
if (alphai < 0) {
alphai = 0; fadeout = 0; setup();
}
}
}
void Wimage::draw() {
// drawfade();
}
void Wimage::resize(float percent) {
size = percent;
w = w * size;
h = w / ratio;
x = ofGetWidth() / 2 - w / 2;
y = ofGetHeight() / 2 - h / 2;
}
void Wimage::drawfade() {
fade();
ofSetColor(255, 255, 255, alphai);
pic.draw(x, y, w, h);
}
void Wimage::drawnofade() {
ofSetColor(255, 255, 255, alpha);
pic.draw(x, y, w, h);
}
void Wimage::newImage() {
extern size_t ix;
extern vector<ofImage> mempic;
pic.loadData(mempic[ix]);
ix++;
if (ix >= mempic.size()) ix = 0;
}