| 154 | } |
| 155 | |
| 156 | void ContinuousPageProvider::requestRange(int firstPage, int lastPage) |
| 157 | { |
| 158 | if (!render || numPagesValue <= 0) { |
| 159 | return; |
| 160 | } |
| 161 | |
| 162 | firstPage = qBound(0, firstPage, numPagesValue - 1); |
| 163 | lastPage = qBound(0, lastPage, numPagesValue - 1); |
| 164 | if (lastPage < firstPage) { |
| 165 | return; |
| 166 | } |
| 167 | |
| 168 | requestedFirst = firstPage; |
| 169 | requestedLast = lastPage; |
| 170 | |
| 171 | const int keepMin = std::max(0, firstPage - kEvictMargin); |
| 172 | const int keepMax = std::min(numPagesValue - 1, lastPage + kEvictMargin); |
| 173 | |
| 174 | // Evict cached pages outside the kept window. |
| 175 | for (auto it = cache.begin(); it != cache.end();) { |
| 176 | if (it.key() < keepMin || it.key() > keepMax) { |
| 177 | it = cache.erase(it); |
| 178 | } else { |
| 179 | ++it; |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | // Schedule decode for requested pages whose raw bytes are loaded and that |
| 184 | // are not already decoded or in flight. |
| 185 | for (int i = firstPage; i <= lastPage; ++i) { |
| 186 | if (rawDataReady.contains(i) && !cache.contains(i) && !pending.contains(i)) { |
| 187 | scheduleDecode(i); |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | const QImage *ContinuousPageProvider::image(int pageIndex) const |
| 193 | { |
no test coverage detected