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;
}
}
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();
}
}
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;
}
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;
}
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;
}
Aggregations