void ofxThreadedImage::updateTextureIfNeeded(){ if (pendingTexture){ setUseTexture(true); tex.allocate(getPixelsRef()); update(); pendingTexture = false; } }
void ofxThreadedImage::threadedFunction(){ #ifdef TARGET_OSX pthread_setname_np("ofxThreadedImage"); #endif if( lock() ){ switch (whatToDo) { case SAVE: ofSaveImage(getPixelsRef(), fileName, quality); break; case LOAD:{ alpha = 0.0f; //float t1 = ofGetElapsedTimef(); loadImageBlocking(fileName); //ofLog() << "time to load: " << ofGetElapsedTimef() - t1; }break; case LOAD_HTTP: alpha = 0; ofxSimpleHttp http; http.setTimeOut(timeOut); ofxSimpleHttpResponse response = http.fetchURLtoDiskBlocking(url, IMG_DOWNLOAD_FOLDER_NAME); if (response.ok){ setUseTexture(false); bool loaded = loadImage(response.absolutePath); if (loaded){ resizeIfNeeded(); imageLoaded = true; }else{ ofLog(OF_LOG_ERROR, "loadHttpImageBlocking() failed to load from disk (%d) > %s\n", response.status, url.c_str() ); } }else{ ofLog(OF_LOG_ERROR, "loadHttpImageBlocking() failed to download (%d) > %s\n", response.status, url.c_str() ); } break; } unlock(); } else { ofLogError("ofxThreadedImage::threadedFunction Can't %s %s, thread is already running", whatToDo == SAVE ? "Save" : "Load", fileName.c_str() ); } stopThread(); #if defined(TARGET_OSX) || defined(TARGET_LINUX) /*I'm not 100% sure of linux*/ pthread_detach( pthread_self() ); //this is a workaround for this issue https://github.com/openframeworks/openFrameworks/issues/2506 #endif }
void ofxThreadedImage::updateTextureIfNeeded(){ if (pendingTexture){ if (!problemLoading){ setUseTexture(true); tex.setCompression(compression); tex.allocate(getPixelsRef()); //tex.setTextureMinMagFilter(GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR); ofImage::update(); readyToDraw = true; pendingTexture = false; } pendingNotification = true; //texture is loaded, notify owner! } }
//-------------------------------------------------------------------------------- void ofxCvImage::updateTexture(){ if( bUseTexture ) { if( bTextureDirty ) { if(tex.getWidth() != width || tex.getHeight() != height) { //ROI was changed // reallocating texture - this could be faster with ROI support tex.clear(); tex.allocate( width, height, glchannels ); } tex.loadData( getPixelsRef() ); bTextureDirty = false; } } }
void ofxThreadedImage::threadedFunction(){ if( lock() ){ switch (whatToDo) { case SAVE: ofSaveImage(getPixelsRef(), fileName, quality); break; case LOAD: alpha = 0.0f; loadImageBlocking(fileName); break; case LOAD_HTTP: alpha = 0; ofxSimpleHttp http; http.setTimeOut(timeOut); ofxSimpleHttpResponse response = http.fetchURLBlocking(url); if (response.status == 200){ ofDirectory dir; dir.open(ofToDataPath(IMG_DOWNLOAD_FOLDER_NAME, false)); if ( !dir.exists() ){ dir.create(); } string filePath = ofToDataPath( (string)IMG_DOWNLOAD_FOLDER_NAME + "/" + response.fileName, false ); FILE * file = fopen( filePath.c_str(), "wb"); fwrite (response.responseBody.c_str() , 1 , response.responseBody.length() , file ); fclose( file); setUseTexture(false); bool loaded = loadImage((string)IMG_DOWNLOAD_FOLDER_NAME + "/" + response.fileName); if (loaded){ imageLoaded = true; }else{ ofLog(OF_LOG_ERROR, "loadHttpImageBlocking() failed to load from disk (%d) > %s\n", response.status, url.c_str() ); } }else{ ofLog(OF_LOG_ERROR, "loadHttpImageBlocking() failed to download (%d) > %s\n", response.status, url.c_str() ); } break; } unlock(); } else { printf("ofxThreadedImage::threadedFunction Can't %s %s, thread is already running", whatToDo == SAVE ? "Save" : "Load", fileName.c_str() ); } stopThread(); }
void ofxThreadedImage::draw(float _x, float _y, bool fadeInOnDelayedLoad){ ofxThreadedImage::draw(_x, _y, getPixelsRef().getWidth(), getPixelsRef().getHeight(), fadeInOnDelayedLoad ); }
//-------------------------------------------------------------------------------- unsigned char* ofxCvImage::getPixels(){ return getPixelsRef().getPixels(); }
VideoFrame * VideoGrabber::getNextVideoFrame(){ //newFrameEvent.init("PlayModes.VideoGrabber.newFrame"); VideoFrame * frame = new VideoFrame(getPixelsRef()); return frame; }