Search in sources :

Example 1 with CodecPageInfo

use of org.ebookdroid.core.codec.CodecPageInfo in project LibreraReader by foobnix.

the class DjvuDocument method getPageInfo.

@Override
public CodecPageInfo getPageInfo(final int pageNumber) {
    final CodecPageInfo info = new CodecPageInfo();
    final int res = getPageInfo(documentHandle, pageNumber, context.getContextHandle(), info);
    if (res == -1) {
        return null;
    } else {
        return info;
    }
}
Also used : CodecPageInfo(org.ebookdroid.core.codec.CodecPageInfo)

Example 2 with CodecPageInfo

use of org.ebookdroid.core.codec.CodecPageInfo in project LibreraReader by foobnix.

the class MuPdfDocument method getPageInfo.

@Override
public CodecPageInfo getPageInfo(final int pageNumber) {
    final CodecPageInfo info = new CodecPageInfo();
    try {
        TempHolder.lock.lock();
        final int res = getPageInfo(documentHandle, pageNumber + 1, info);
        if (res == -1) {
            return null;
        } else {
            // Check rotation
            info.rotation = (360 + info.rotation) % 360;
            return info;
        }
    } finally {
        TempHolder.lock.unlock();
    }
}
Also used : CodecPageInfo(org.ebookdroid.core.codec.CodecPageInfo)

Example 3 with CodecPageInfo

use of org.ebookdroid.core.codec.CodecPageInfo in project LibreraReader by foobnix.

the class DocumentModel method retrievePagesInfo.

private CodecPageInfo[] retrievePagesInfo(final IActivityController base, final BookSettings bs, final IProgressIndicator task) {
    int pagesCount = base.getDecodeService().getPageCount();
    final PageCacheFile pagesFile = CacheManager.getPageFile(bs.fileName, pagesCount);
    try {
        if (pagesCount > 0) {
            FileMeta meta = AppDB.get().load(bs.fileName);
            if (meta != null) {
                meta.setPages(pagesCount);
                AppDB.get().update(meta);
            }
        }
    } catch (Exception e) {
        LOG.e(e);
    }
    if (decodeService.isPageSizeCacheable() && pagesFile.exists()) {
        final CodecPageInfo[] infos = pagesFile.load();
        if (infos != null && infos.length == decodeService.getPageCount()) {
            return infos;
        }
    }
    final CodecPageInfo[] infos = new CodecPageInfo[decodeService.getPageCount()];
    final CodecPageInfo unified = decodeService.getUnifiedPageInfo();
    for (int i = 0; i < infos.length; i++) {
        if (TempHolder.get().loadingCancelled) {
            return null;
        }
        infos[i] = unified != null ? unified : decodeService.getPageInfo(i);
    }
    if (decodeService.isPageSizeCacheable()) {
        pagesFile.save(infos);
    }
    return infos;
}
Also used : PageCacheFile(org.ebookdroid.common.cache.PageCacheFile) CodecPageInfo(org.ebookdroid.core.codec.CodecPageInfo) FileMeta(com.foobnix.dao2.FileMeta)

Example 4 with CodecPageInfo

use of org.ebookdroid.core.codec.CodecPageInfo in project LibreraReader by foobnix.

the class PageCacheFile method load.

public CodecPageInfo[] load() {
    try {
        final DataInputStream in = new DataInputStream(new FileInputStream(this));
        try {
            final int pages = in.readInt();
            final CodecPageInfo[] infos = new CodecPageInfo[pages];
            for (int i = 0; i < infos.length; i++) {
                infos[i] = new CodecPageInfo(in.readInt(), in.readInt());
                if (infos[i].width == -1 || infos[i].height == -1) {
                    return null;
                }
            }
            return infos;
        } catch (final EOFException ex) {
            ex.printStackTrace();
        } catch (final IOException ex) {
            ex.printStackTrace();
        } finally {
            try {
                in.close();
            } catch (final IOException ex) {
            }
        }
    } catch (final FileNotFoundException ex) {
        ex.printStackTrace();
    }
    return null;
}
Also used : CodecPageInfo(org.ebookdroid.core.codec.CodecPageInfo) EOFException(java.io.EOFException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream)

Example 5 with CodecPageInfo

use of org.ebookdroid.core.codec.CodecPageInfo in project LibreraReader by foobnix.

the class ImageExtractor method proccessOtherPage.

public Bitmap proccessOtherPage(PageUrl pageUrl, FileMeta meta) {
    int page = pageUrl.getPage();
    String path = pageUrl.getPath();
    boolean isNeedDisableMagicInPDFDjvu = false;
    LOG.d("Page Number", pageUrl.getPage());
    if (pageUrl.getPage() == COVER_PAGE || pageUrl.getPage() == COVER_PAGE_NO_EFFECT || pageUrl.getPage() == COVER_PAGE_WITH_EFFECT) {
        isNeedDisableMagicInPDFDjvu = true;
    }
    if (page < 0) {
        page = 0;
    }
    if (pageUrl.isCrop()) {
    // isNeedDisableMagicInPDFDjvu = true;
    }
    CodecDocument codeCache = null;
    if (isNeedDisableMagicInPDFDjvu) {
        codeCache = singleCodecContext(path, "", pageUrl.getWidth(), pageUrl.getHeight());
        if (meta != null && codeCache != null && FileMetaCore.isNeedToExtractPDFMeta(path)) {
            String bookAuthor = codeCache.getBookAuthor();
            if (TxtUtils.isNotEmpty(bookAuthor)) {
                meta.setAuthor(bookAuthor);
            }
            String bookTitle = codeCache.getBookTitle();
            if (TxtUtils.isNotEmpty(bookTitle)) {
                meta.setTitle(bookTitle);
            }
            LOG.d("PDF getBookAuthor", bookAuthor, bookTitle);
        }
    } else {
        codeCache = getNewCodecContext(path, "", pageUrl.getWidth(), pageUrl.getHeight());
    }
    if (codeCache == null) {
        LOG.d("TEST", "codecDocument == null" + path);
        return null;
    }
    if (isNeedDisableMagicInPDFDjvu && meta != null) {
        meta.setPages(codeCache.getPageCount());
    }
    final CodecPageInfo pageInfo = codeCache.getPageInfo(page);
    Bitmap bitmap = null;
    RectF rectF = new RectF(0, 0, 1f, 1f);
    final float k = (float) pageInfo.height / pageInfo.width;
    int width = pageUrl.getWidth();
    int height = (int) (width * k);
    LOG.d("Bitmap", width, height);
    LOG.d("Bitmap pageInfo.height", pageInfo.width, pageInfo.height);
    BitmapRef bitmapRef = null;
    CodecPage pageCodec = codeCache.getPage(page);
    if (pageUrl.getNumber() == 0) {
        rectF = new RectF(0, 0, 1f, 1f);
        if (isNeedDisableMagicInPDFDjvu) {
            bitmapRef = pageCodec.renderBitmapSimple(width, height, rectF);
        } else {
            bitmapRef = pageCodec.renderBitmap(width, height, rectF);
        }
        bitmap = bitmapRef.getBitmap();
        if (pageUrl.isCrop()) {
            if (BookType.DJVU.is(pageUrl.getPath())) {
                Bitmap sample = pageCodec.renderBitmapSimple(PageCropper.MAX_WIDTH, PageCropper.MAX_HEIGHT, rectF).getBitmap();
                bitmap = cropBitmap(bitmap, sample);
                sample.recycle();
                sample = null;
            } else {
                bitmap = cropBitmap(bitmap, bitmap);
            }
        }
    } else if (pageUrl.getNumber() == 1) {
        float right = (float) pageUrl.getCutp() / 100;
        rectF = new RectF(0, 0, right, 1f);
        bitmapRef = pageCodec.renderBitmap((int) (width * right), height, rectF);
        bitmap = bitmapRef.getBitmap();
        if (pageUrl.isCrop()) {
            bitmap = cropBitmap(bitmap, bitmap);
        }
    } else if (pageUrl.getNumber() == 2) {
        float right = (float) pageUrl.getCutp() / 100;
        rectF = new RectF(right, 0, 1f, 1f);
        bitmapRef = pageCodec.renderBitmap((int) (width * (1 - right)), height, rectF);
        bitmap = bitmapRef.getBitmap();
        if (pageUrl.isCrop()) {
            bitmap = cropBitmap(bitmap, bitmap);
        }
    }
    if (pageUrl.isInvert()) {
        final RawBitmap bmp = new RawBitmap(bitmap, new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()));
        bmp.invert();
        bitmap.recycle();
        bitmap = bmp.toBitmap().getBitmap();
    }
    if (pageUrl.getRotate() > 0) {
        final Matrix matrix = new Matrix();
        matrix.postRotate(pageUrl.getRotate());
        final Bitmap bitmap1 = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
        bitmap.recycle();
        bitmap = bitmap1;
    }
    if (pageUrl.isDoText() && !pageCodec.isRecycled()) {
        PageImageState.get().pagesText.put(pageUrl.getPage(), pageCodec.getText());
        PageImageState.get().pagesLinks.put(pageUrl.getPage(), pageCodec.getPageLinks());
    }
    if (!pageCodec.isRecycled()) {
        pageCodec.recycle();
    }
    if (isNeedDisableMagicInPDFDjvu) {
        codeCache.recycle();
    }
    if (!isNeedDisableMagicInPDFDjvu && MagicHelper.isNeedBookBackgroundImage()) {
        bitmap = MagicHelper.updateWithBackground(bitmap);
    }
    return bitmap;
}
Also used : Rect(android.graphics.Rect) CodecPage(org.ebookdroid.core.codec.CodecPage) RectF(android.graphics.RectF) RawBitmap(org.ebookdroid.common.bitmaps.RawBitmap) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) CodecPageInfo(org.ebookdroid.core.codec.CodecPageInfo) RawBitmap(org.ebookdroid.common.bitmaps.RawBitmap) BitmapRef(org.ebookdroid.common.bitmaps.BitmapRef) CodecDocument(org.ebookdroid.core.codec.CodecDocument)

Aggregations

CodecPageInfo (org.ebookdroid.core.codec.CodecPageInfo)7 Bitmap (android.graphics.Bitmap)1 Matrix (android.graphics.Matrix)1 Rect (android.graphics.Rect)1 RectF (android.graphics.RectF)1 FileMeta (com.foobnix.dao2.FileMeta)1 DataInputStream (java.io.DataInputStream)1 EOFException (java.io.EOFException)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 BitmapRef (org.ebookdroid.common.bitmaps.BitmapRef)1 RawBitmap (org.ebookdroid.common.bitmaps.RawBitmap)1 PageCacheFile (org.ebookdroid.common.cache.PageCacheFile)1 BookSettings (org.ebookdroid.common.settings.books.BookSettings)1 Page (org.ebookdroid.core.Page)1 PageIndex (org.ebookdroid.core.PageIndex)1 CodecDocument (org.ebookdroid.core.codec.CodecDocument)1 CodecPage (org.ebookdroid.core.codec.CodecPage)1