]> www.fi.muni.cz Git - evince.git/blobdiff - tiff/tiff-document.c
modify the expose handling to get the shadows.
[evince.git] / tiff / tiff-document.c
index 5c8cc8d4bac0ea3c22e6d4de64206ba387b2467d..9605c16eacaf281ed04507ad87c7972a060e3192 100644 (file)
@@ -167,6 +167,8 @@ tiff_document_render_pixbuf (EvDocument  *document, int page, double scale)
 {
   TiffDocument *tiff_document = TIFF_DOCUMENT (document);
   int width, height;
+  gint rowstride, bytes;
+  guchar *pixels = NULL;
   GdkPixbuf *pixbuf;
   GdkPixbuf *scaled_pixbuf;
 
@@ -180,8 +182,41 @@ tiff_document_render_pixbuf (EvDocument  *document, int page, double scale)
       return NULL;
     }
 
-  TIFFGetField (tiff_document->tiff, TIFFTAG_IMAGEWIDTH, &width);
-  TIFFGetField (tiff_document->tiff, TIFFTAG_IMAGELENGTH, &height);
+  if (!TIFFGetField (tiff_document->tiff, TIFFTAG_IMAGEWIDTH, &width))
+    {
+      pop_handlers ();
+      return NULL;
+    }
+
+  if (! TIFFGetField (tiff_document->tiff, TIFFTAG_IMAGELENGTH, &height))
+    {
+      pop_handlers ();
+      return NULL;
+    }
+
+  pop_handlers ();
+
+  /* Sanity check the doc */
+  if (width <= 0 || height <= 0)
+    return NULL;                
+        
+  rowstride = width * 4;
+  if (rowstride / 4 != width)
+    /* overflow */
+    return NULL;                
+        
+  bytes = height * rowstride;
+  if (bytes / rowstride != height)
+    /* overflow */
+    return NULL;                
+
+  pixels = g_try_malloc (bytes);
+  if (!pixels)
+    return NULL;
+
+  pixbuf = gdk_pixbuf_new_from_data (pixels, GDK_COLORSPACE_RGB, TRUE, 8, 
+                                    width, height, rowstride,
+                                    (GdkPixbufDestroyNotify) g_free, NULL);
 
   pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, width, height);
   TIFFReadRGBAImageOriented (tiff_document->tiff, width, height, (uint32 *)gdk_pixbuf_get_pixels (pixbuf), ORIENTATION_TOPLEFT, 1);