Skip to Content.
Sympa Menu

idok-commit - [idok-commit] idok commit r56 - trunk/java/ch/idok/qtgui

idok-commit AT lists.psi.ch

Subject: Commit emails of the iDok project

List archive

[idok-commit] idok commit r56 - trunk/java/ch/idok/qtgui


Chronological Thread 
  • From: "Apache" <apache AT savannah.psi.ch>
  • To: idok-commit AT lists.psi.ch
  • Subject: [idok-commit] idok commit r56 - trunk/java/ch/idok/qtgui
  • Date: Thu, 27 Mar 2008 11:56:56 +0100
  • List-archive: <https://lists.web.psi.ch/pipermail/idok-commit/>
  • List-id: Commit emails of the iDok project <idok-commit.lists.psi.ch>

Author: huebner AT PSI.CH
Date: Thu Mar 27 11:56:55 2008
New Revision: 56

Log:
QImage objects generated from PDF files now get stored in an Array for
quicker loading of already viewed pages.

Modified:
trunk/java/ch/idok/qtgui/PreviewWidget.java

Modified: trunk/java/ch/idok/qtgui/PreviewWidget.java
==============================================================================
--- trunk/java/ch/idok/qtgui/PreviewWidget.java (original)
+++ trunk/java/ch/idok/qtgui/PreviewWidget.java Thu Mar 27 11:56:55 2008
@@ -45,6 +45,7 @@
import com.trolltech.qt.core.QFile;
import com.trolltech.qt.core.QIODevice;
import com.trolltech.qt.core.QTextStream;
+import com.trolltech.qt.core.QTime;
import com.trolltech.qt.core.Qt;
import com.trolltech.qt.core.Qt.FocusPolicy;
import com.trolltech.qt.gui.QCursor;
@@ -110,6 +111,7 @@


private PDFFile pdfFile_ = null;
+ private QImage[] pictureArray;

private static QCursor BUSYCURSOR = new
QCursor(Qt.CursorShape.BusyCursor);

@@ -230,17 +232,22 @@
} else if (ext.equals("pdf")) {
// fileName_ contains the local copy of the PDF file
try {
+ QTime time = new QTime();
+ int displayTime = 0;
+ time.start();
File file = new File(fileName_);
RandomAccessFile raf = new RandomAccessFile(file, "r");
FileChannel channel = raf.getChannel();
ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY,
0, channel.size());
pdfFile_ = new PDFFile(buf);
numPages_ = pdfFile_.getNumPages();
-
+ pictureArray = new QImage[numPages_];
pdfPageSpinBox_.setRange(1, numPages_);
previewPdfFile(1);
pdfPageSpinBox_.show();
pdfPageSpinBox_.setValue(1);
+ displayTime = time.elapsed();
+ System.out.println("Display time: "+ displayTime+ " ms");
} catch (Exception e) {
QMessageBox.warning(null, tr("iDok Warning"),
tr("General PDF decoding problem:") +
e.getMessage());
@@ -252,10 +259,10 @@
| ext.equals("ppt")| ext.equals("jpg")| ext.equals("gif")
| ext.equals("tif")) {
try {
-// QTime time = new QTime();
-// int convertTime = 0;
-// int displayTime = 0;
-// time.start();
+ QTime time = new QTime();
+ int convertTime = 0;
+ int displayTime = 0;
+ time.start();
File file = new File(fileName_);
RandomAccessFile randomInputAccessFile = new
RandomAccessFile(file, "r");
byte[] byteInputArray = new
byte[(int)randomInputAccessFile.length()];
@@ -263,18 +270,19 @@
InputStream inStream = new
ByteArrayInputStream(byteInputArray);
ByteArrayOutputStream outStream = new
ByteArrayOutputStream();
Convert.convert(inStream,ext,outStream);
-// convertTime = time.restart();
-// System.out.println("Conversion time: "+
convertTime + " ms");
+ convertTime = time.restart();
+ System.out.println("Conversion time: "+ convertTime
+ " ms");
ByteBuffer outBuffer =
ByteBuffer.wrap(outStream.toByteArray());
pdfFile_ = new PDFFile(outBuffer);
numPages_ = pdfFile_.getNumPages();
+ pictureArray = new QImage[numPages_];
pdfPageSpinBox_.setRange(1, numPages_);
previewPdfFile(1);
pdfPageSpinBox_.show();
pdfPageSpinBox_.setValue(1);
-// displayTime = time.elapsed();
-// System.out.println("Display time: "+ displayTime+
" ms");
-// System.out.println("Conversion+Display= "+
(convertTime+displayTime) + " ms");
+ displayTime = time.elapsed();
+ System.out.println("Display time: "+ displayTime+ "
ms");
+ System.out.println("Conversion+Display= "+
(convertTime+displayTime) + " ms");
} catch (Exception e) {
QMessageBox.warning(null, tr("iDok Warning"),
tr("General PDF decoding problem:") +
e.getMessage());
@@ -332,27 +340,44 @@
private void previewPdfFile(int page) {
setCursor(BUSYCURSOR);
try {
- PDFPage pdfPage = pdfFile_.getPage(page);
- Rectangle rect = new
Rectangle(0,0,(int)pdfPage.getBBox().getWidth(),(int)pdfPage.getBBox().getHeight());

- int width = rect.width;
- int height =rect.height;
- BufferedImage image = (BufferedImage)pdfPage.getImage(
- width, height, //width & height
- rect, // clip rect
- null, // null for the ImageObserver
- true, // fill background with white
- true // block until drawing is done
- );
-
- if (image != null) {
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- ImageIO.write(image, "png", out);
- byte[] buf = out.toByteArray();
- QPixmap pixMap = new QPixmap(width,height);
- pixMap.loadFromData(buf);
- imageView_.setImage(pixMap.toImage());
+ QTime time = new QTime();
+ time.start();
+ if(pictureArray[page-1] == null){
+ PDFPage pdfPage = pdfFile_.getPage(page);
+ System.out.println("Loading Page #"+page);
+ System.out.println("New page time(generate page): "+
time.restart() + " ms");
+ Rectangle rect = new
Rectangle(0,0,(int)pdfPage.getBBox().getWidth(),(int)pdfPage.getBBox().getHeight());

+ int width = rect.width;
+ int height =rect.height;
+ BufferedImage image = (BufferedImage)pdfPage.getImage(
+ width, height, //width & height
+ rect, // clip rect
+ null, // null for the ImageObserver
+ true, // fill background with white
+ true // block until drawing is done
+ );
+ System.out.println("New page time(generate image): "+
time.restart() + " ms");
+ if (image != null) {
+ ByteArrayOutputStream out = new
ByteArrayOutputStream();
+ ImageIO.write(image, "png", out);
+ System.out.println("New page time(convert image to
stream): "+ time.restart() + " ms");
+ byte[] buf = out.toByteArray();
+ System.out.println("New page time(convert stream to
byte[]): "+ time.restart() + " ms");
+ QPixmap pixMap = new QPixmap(width,height);
+ pixMap.loadFromData(buf);
+ System.out.println("New page time(convert byte[] tp
pixmap): "+ time.restart() + " ms");
+ pictureArray[page-1] = pixMap.toImage();
+ System.out.println("New page time(Convert pixmap to
Image): "+ time.restart() + " ms");
+ imageView_.setImage(pictureArray[page-1]);
+ System.out.println("New page time(Set imageView): "+
time.restart() + " ms");
+ enableImageView();
+ }
+ }else{
+ imageView_.setImage(pictureArray[page-1]);
enableImageView();
}
+ System.out.println("New page time(enabeImageView): "+
time.restart() + " ms");
+ System.out.println("");
} catch (Exception e) {
QMessageBox.warning(null, tr("iDok Warning"),
tr("PDF file could not be decoded:") + e.getMessage());



  • [idok-commit] idok commit r56 - trunk/java/ch/idok/qtgui, Apache, 03/27/2008

Archive powered by MHonArc 2.6.19.

Top of Page