use of org.ebookdroid.core.codec.CodecPageHolder in project LibreraReader by foobnix.
the class DecodeServiceBase method performDecode.
void performDecode(final DecodeTask task) {
if (executor.isTaskDead(task)) {
return;
}
CodecPageHolder holder = null;
CodecPage vuPage = null;
Rect r = null;
RectF croppedPageBounds = null;
// TempHolder.lock.lock();
try {
holder = getPageHolder(task.id, task.pageNumber);
vuPage = holder.getPage(task.id);
if (executor.isTaskDead(task)) {
return;
}
croppedPageBounds = checkCropping(task, vuPage);
if (executor.isTaskDead(task)) {
return;
}
r = getScaledSize(task.node, task.viewState.zoom, croppedPageBounds, vuPage);
final RectF actualSliceBounds = task.node.croppedBounds != null ? task.node.croppedBounds : task.node.pageSliceBounds;
// TempHolder.lock.lock();
final BitmapRef bitmap = vuPage.renderBitmap(r.width(), r.height(), actualSliceBounds);
if (executor.isTaskDead(task)) {
BitmapManager.release(bitmap);
return;
}
// TempHolder.lock.lock();
if (task.node.page.links == null) {
task.node.page.links = vuPage.getPageLinks();
if (LengthUtils.isNotEmpty(task.node.page.links)) {
}
}
if (task.node.page.annotations == null) {
task.node.page.annotations = vuPage.getAnnotations();
}
if (task.node.page.texts == null) {
task.node.page.texts = vuPage.getText();
}
// TempHolder.lock.unlock();
finishDecoding(task, vuPage, bitmap, r, croppedPageBounds);
// test
// vuPage.recycle();
} catch (final OutOfMemoryError ex) {
for (int i = 0; i <= AppSettings.getInstance().pagesInMemory; i++) {
getPages().put(Integer.MAX_VALUE - i, null);
}
getPages().clear();
if (vuPage != null) {
vuPage.recycle();
}
BitmapManager.clear("DecodeService OutOfMemoryError: ");
abortDecoding(task, null, null);
} catch (final Throwable th) {
th.printStackTrace();
abortDecoding(task, vuPage, null);
} finally {
// TempHolder.lock.unlock();
if (holder != null) {
holder.unlock();
}
}
}
use of org.ebookdroid.core.codec.CodecPageHolder in project LibreraReader by foobnix.
the class DecodeServiceBase method getPageHolder.
private synchronized CodecPageHolder getPageHolder(final long taskId, final int pageIndex) {
for (final Iterator<Map.Entry<Integer, CodecPageHolder>> i = getPages().entrySet().iterator(); i.hasNext(); ) {
final Map.Entry<Integer, CodecPageHolder> entry = i.next();
final int index = entry.getKey();
final CodecPageHolder ref = entry.getValue();
if (ref.isInvalid(-1)) {
i.remove();
}
}
CodecPageHolder holder = getPages().get(pageIndex);
if (holder == null) {
holder = new CodecPageHolder(codecDocument, pageIndex);
getPages().put(pageIndex, holder);
}
// Preventing problem inside the MuPDF
if (!codecContext.isParallelPageAccessAvailable()) {
// holder.getPage(taskId);
// TODO TEST!!!
}
return holder;
}
Aggregations