use of org.ebookdroid.common.bitmaps.RawBitmap 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