void OverlayEffect::readEffectData() { if (workOverlay!="") { if (workOverlay!=readOverlay) { img.load(workOverlay.c_str()); printf("overlay size %dx%d\n", img.width(), img.height()); readOverlay = workOverlay; } } }
void Image::load( const std::string &filename ) { using namespace std; size_t pos = filename.find_last_of('.'); if ( pos == string::npos ) { std::string mess("Image::load: Can't load image "); mess.append(filename); throw new Exception(mess); } const string ext = filename.substr(pos+1); ImageLoader *imgLoader = ImageLoader::getImageLoader(ext); imgData = imgLoader->load(filename); }
void ImageGridDataProvider::loadMoreImages() { int count = 0; int s = this->m_imageFilePaths.size(); qDebug() << "[ImageGridDataProvider::loadMoreImages] m_loadedItems: " << m_loadedItems << ", s: " << s << ", m_loadingCount: " << m_loadingCount; // Make sure the model never loads more images than it should at the same time or more than it should if(m_loadingCount == 0 && m_loadedItems < s){ ImageLoader *loader = NULL; while( count < ImageGridDataProvider::MAX_ITENS && s > (count + m_loadedItems) ){ // don't forget to set the Parent Object or else is memory leak! loader = new ImageLoader( m_imageFilePaths.at(m_loadedItems + count), this); bool ok = connect(loader, SIGNAL(imageChanged()), this, SLOT(onImageChanged())); Q_UNUSED(ok); Q_ASSERT_X(ok,"[ImageGridDataProvider::loadMoreImages]", "connect imageChanged failed"); m_dataModel->append( loader ); loader->load(); // Don't start loading images while ImageLoader instances are created on this while loop or else we have a race condition! // m_loadedItems is incremented on onImageChanged and it's possible that an image is finished loading before the while is done. ++count; ++m_loadingCount; Q_ASSERT_X(m_loadingCount <= ImageGridDataProvider::MAX_ITENS,"[ImageGridDataProvider::loadMoreImages]", "loading count max exceed!"); } // Start loading the images only after the loop is done! This a very simple way of preventing the race condition. /*for(int i = 0; i < count; i++){ loader = m_dataModel->value(m_loadedItems + i); loader->load(); }*/ loader = NULL; } else{ qDebug() << "[ImageGridDataProvider::loadMoreImages] maximum loading reached! Must wait until all images finish loading or must add new images to load."; } }