Search in sources :

Example 1 with CodecPageHolder

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();
        }
    }
}
Also used : RectF(android.graphics.RectF) Rect(android.graphics.Rect) CodecPage(org.ebookdroid.core.codec.CodecPage) CodecPageHolder(org.ebookdroid.core.codec.CodecPageHolder) BitmapRef(org.ebookdroid.common.bitmaps.BitmapRef)

Example 2 with CodecPageHolder

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;
}
Also used : CodecPageHolder(org.ebookdroid.core.codec.CodecPageHolder) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap)

Aggregations

CodecPageHolder (org.ebookdroid.core.codec.CodecPageHolder)2 Rect (android.graphics.Rect)1 RectF (android.graphics.RectF)1 IdentityHashMap (java.util.IdentityHashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 BitmapRef (org.ebookdroid.common.bitmaps.BitmapRef)1 CodecPage (org.ebookdroid.core.codec.CodecPage)1