void DirectoryMangaVolume::prefetch() { int theoretical_min = prefetchMin(); int theoretical_max = prefetchMax(); theoretical_max = std::max(theoretical_min+1,theoretical_max); //qWarning() << theoretical_min << " " << theoretical_max; //clear out pages that aren't necessary anymore while(m_prefetched_pages.size() > 0 && m_prefetched_pages.cbegin()->first < theoretical_min) { //qWarning() << "front unprefetched: " << m_prefetched_pages.begin()->first; m_prefetched_pages.erase(m_prefetched_pages.begin()); } while(m_prefetched_pages.size() > 0 && m_prefetched_pages.crbegin()->first > theoretical_max) { //qWarning() << "back unprefetched: " << m_prefetched_pages.crbegin()->first; //qWarning() << m_prefetched_pages.crbegin()->second.getFilename(); m_prefetched_pages.erase(--(m_prefetched_pages.crbegin().base())); } //if empty fill it in if( m_prefetched_pages.size() == 0) { for(int i=theoretical_min; i < theoretical_max; ++i) { m_prefetched_pages[i] = MangaPage(m_page_names[i]); } } //else fill in the front and back if(theoretical_min < m_prefetched_pages.cbegin()->first) { int endPos = m_prefetched_pages.cbegin()->first; for(int i=theoretical_min; i < endPos; ++i) { //qWarning() << "font prefetched: " << i; m_prefetched_pages[i] = MangaPage(m_page_names[i]); } } if(theoretical_max > m_prefetched_pages.crbegin()->first) { int startPos = m_prefetched_pages.crbegin()->first+1; for(int i=startPos; i < theoretical_max; ++i) { //qWarning() << "back prefetched: " << i; m_prefetched_pages[i] = MangaPage(m_page_names[i]); } } }
std::shared_ptr<const QImage> DirectoryMangaVolume::getImage(uint page_num, QPointF) { if (page_num >= m_page_names.size()) { return std::shared_ptr<const QImage>(); } else if(m_prefetch_width <= 0) { return MangaPage(m_page_names[page_num]).getData(); } else { m_active_pages.insert(page_num); prefetch(); return m_prefetched_pages[page_num].getData(); } }
void DirectoryMangaVolume::prefetch() { int theoretical_min = prefetchMin(); int theoretical_max = prefetchMax(); theoretical_max = std::max(theoretical_min+1,theoretical_max); qWarning() << theoretical_min << " " << theoretical_max; if( m_prefetched_pages.size() == 0) { for(int i=theoretical_min; i < theoretical_max; ++i) { m_prefetched_pages[i] = MangaPage(m_page_names[i]); } } if(theoretical_min < m_prefetched_pages.cbegin()->first) { int endPos = m_prefetched_pages.cbegin()->first; for(int i=theoretical_min; i < endPos; ++i) { qWarning() << "font prefetched: " << i; m_prefetched_pages[i] = MangaPage(m_page_names[i]); } } else { while(m_prefetched_pages.cbegin()->first < theoretical_min) { qWarning() << "front unprefetched: " << m_prefetched_pages.begin()->first; m_prefetched_pages.erase(m_prefetched_pages.begin()); } } if(theoretical_max > m_prefetched_pages.crbegin()->first) { int startPos = m_prefetched_pages.crbegin()->first+1; for(int i=startPos; i < theoretical_max; ++i) { qWarning() << "back prefetched: " << i; m_prefetched_pages[i] = MangaPage(m_page_names[i]); } } else { while(m_prefetched_pages.crbegin()->first > theoretical_max) { qWarning() << "back unprefetched: " << m_prefetched_pages.crbegin()->first; qWarning() << m_prefetched_pages.crbegin()->second.getFilename(); m_prefetched_pages.erase(--(m_prefetched_pages.crbegin().base())); } } }