Hi everyone,
I am using the addon ofxThreadedImageLoader for a project on Android. I have to load pictures without loading time.
To do this, i load a small thumb, with a simple ofImage::loadImage(), and in an other thread, i load the full picture.
Then, when the full image is loaded, i display this one , instead of the thumb.
There is one thing i don’t get: How can i do if i want to cancel the loading in the other thread (i delete the ofImage in my main thread, but the other thread is still loading the image (wich is NULL now).
Here’s a part of my code, i use it to load photosphere (like street view), and the full image can very big.
Photo360::Photo360(string path)
{
img = new ofImage();
thread = ThreadLoader::getInstance();
thread->getThread()->loadFromDisk(*img, path);
}
void Photo360::displayMain(int x, int y, float width, float height, ofTexture& preview)
{
if (!img->getTextureReference().isAllocated() || img->width == 0)
tex = preview; // The full is not loaded, so we use the thumb
else
tex = img->getTextureReference();
fbo.begin();
cam.begin();
ofClear(0x00);
ofPushMatrix();
glEnable(GL_DEPTH_TEST);
ofRotate(180, 1, 0, 0);
ofRotateX(phi);
ofRotateY(theta);
if (turne)
{
#ifdef WIN32
theta = ofMap(ofGetElapsedTimef() - startTime, 0.0, 40.0, 0.0, 360.0);
#else
theta = ofMapDouble(ofGetElapsedTimef() - startTime, 0.0, 40.0, 0.0, 360.0);
#endif
if (theta >= 360)
startTime = ofGetElapsedTimef();
}
tex.bind();
ofDrawSphere(0, 0, boundingBox.height);
tex.unbind();
ofPopMatrix();
glDisable(GL_DEPTH_TEST);
fbo.end();
cam.end();
fbo.draw(x, y);
}
Photo360::~Photo360() // In the case where the user whant to exit this part of the application, delete the full image
{
thread->getThread()->lock();
delete ofImage(); // Segfault when the image is not fully loaded
thread->getThread()->unlock();
}
Thanks for your help, and sorry for my very poor english (first year french student)