[KimDaBa] Patch to handle very large images correctly in the viewer

Robert L Krawitz rlk at alum.mit.edu
Sat Nov 27 12:49:34 CET 2004


The version of Qt I have (3.3.3 using SUSE RPM's in SUSE 9.1) seems to
set an upper limit on image size of 4096x4096 by default.  I have
images larger than that.  This caused img->create() to fail
(silently), which caused a null pointer dereference shortly
thereafter.  This patch does two things:

1) Check the return from img->create().

2) Check the maximum image size against the size of the image we want
   to display, and increase the max image size as needed.

--- util.cpp~   2004-11-26 18:59:52.000000000 -0500
+++ util.cpp    2004-11-27 12:28:54.799315125 -0500
@@ -487,14 +487,30 @@
 
    //QImage img;
 
+#ifdef QT_HAVE_MAX_IMAGE_SIZE
+   // If we have an image larger than maxImageSize() the call to img->create()
+   // will fail.
+   static QSize max_size = QImage::maxImageSize();
+   if (max_size.width() < (int) cinfo.output_width) {
+     max_size.setWidth(cinfo.output_width);
+     QImage::setMaxImageSize(max_size);
+   }
+   if (max_size.height() < (int) cinfo.output_height) {
+     max_size.setHeight(cinfo.output_height);
+     QImage::setMaxImageSize(max_size);
+   }
+#endif
+
    switch(cinfo.output_components) {
    case 3:
    case 4:
-      img->create( cinfo.output_width, cinfo.output_height, 32 );
+      if (!img->create( cinfo.output_width, cinfo.output_height, 32 ))
+       return false;
       break;
    case 1: // B&W image
-      img->create( cinfo.output_width, cinfo.output_height,
-                     8, 256 );
+      if (!img->create( cinfo.output_width, cinfo.output_height,
+                       8, 256 ))
+       return false;
       for (int i=0; i<256; i++)
             img->setColor(i, qRgb(i,i,i));
       break;
--- imageloader.cpp~    2004-08-23 11:52:27.000000000 -0400
+++ imageloader.cpp     2004-11-27 12:39:21.733234699 -0500
@@ -52,6 +52,18 @@
         LoadInfo li = ImageManager::instance()->next();
 
         if ( !li.isNull() ) {
+#ifdef QT_HAVE_MAX_IMAGE_SIZE
+         //
+         static QSize max_size = QImage::maxImageSize();
+         if (max_size.width() < (int) li.width()) {
+           max_size.setWidth(li.width());
+           QImage::setMaxImageSize(max_size);
+         }
+         if (max_size.height() < (int) li.height()) {
+           max_size.setHeight(li.height());
+           QImage::setMaxImageSize(max_size);
+         }
+#endif
             QImage img;
             bool imageLoaded = false;
 

-- 
Robert Krawitz                                     <rlk at alum.mit.edu>

Tall Clubs International  --  http://www.tall.org/ or 1-888-IM-TALL-2
Member of the League for Programming Freedom -- mail lpf at uunet.uu.net
Project lead for Gimp Print   --    http://gimp-print.sourceforge.net

"Linux doesn't dictate how I work, I dictate how Linux works."
--Eric Crampton



More information about the KimDaBa mailing list