While I was trying to write a small program to preview DjVu files I encountered a peculiar problem. This is a small function that renders a page of a DjVu document into QImage class of PyQt4.
import djvu.decode as DjVu from PyQt4.QtCore import QImage from PyQt4.QtGui import QPixmap, QApplication, QLabel def djvu2pixmap( filename, width, height ) : doc = DjVu.Context().new_document( DjVu.FileURI( filename ) ) doc.decoding_job.wait() pg = doc.pages[ 0 ] pg.decode( wait = True ) data = pg.thumbnail.render( ( width, height ), DjVu.PixelFormatRgbMask( 0xff0000, 0xff00, 0xff, bpp = 32 ) ) image = QIamge( data[ 1 ], data[ 0 ][ 0 ], data[ 0 ][ 1 ], QImage.Format_RGB32 ) image.save( "/tmp/image.png" ) return QPixmap.fromImage( image ) if __name__ == '__main__' : import sys app = QApplication( sys.argv ) lbl = QLabel() lbl.setPixmap( djvu2pixmap( "trial.djvu" ), 200, 300 ) lbl.show() lbl.resize( lbl.pixmap().size() ) exit( app.exec_() )
Say now I set the image width and height to
( 300, 500 ) the program crashes out with
SegmentationFault. I also realized that there is no problem with the image. It does get saved properly. I just cannot display it. Not only that, but I can open the saved image and display it without any problem. Im curious as to why this happens.