- TiffDocument *tiff_document = TIFF_DOCUMENT (document);
- int width, height;
- float x_res, y_res;
- gint rowstride, bytes;
- guchar *pixels = NULL;
- GdkPixbuf *pixbuf;
- GdkPixbuf *scaled_pixbuf;
- GdkPixbuf *rotated_pixbuf;
-
- g_return_val_if_fail (TIFF_IS_DOCUMENT (document), 0);
- g_return_val_if_fail (tiff_document->tiff != NULL, 0);
-
- push_handlers ();
- if (TIFFSetDirectory (tiff_document->tiff, rc->page) != 1)
- {
- pop_handlers ();
- return NULL;
- }
-
- if (!TIFFGetField (tiff_document->tiff, TIFFTAG_IMAGEWIDTH, &width))
- {
- pop_handlers ();
- return NULL;
- }
-
- if (! TIFFGetField (tiff_document->tiff, TIFFTAG_IMAGELENGTH, &height))
- {
- pop_handlers ();
- return NULL;
- }
-
- if (!TIFFGetField (tiff_document->tiff, TIFFTAG_XRESOLUTION, &x_res))
- {
- pop_handlers ();
- return NULL;
- }
-
- if (! TIFFGetField (tiff_document->tiff, TIFFTAG_YRESOLUTION, &y_res))
- {
- 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);
- pop_handlers ();
+ TiffDocument *tiff_document = TIFF_DOCUMENT (document);
+ int width, height;
+ float x_res, y_res;
+ gint rowstride, bytes;
+ guchar *pixels = NULL;
+ GdkPixbuf *pixbuf;
+ GdkPixbuf *scaled_pixbuf;
+ GdkPixbuf *rotated_pixbuf;
+
+ g_return_val_if_fail (TIFF_IS_DOCUMENT (document), NULL);
+ g_return_val_if_fail (tiff_document->tiff != NULL, NULL);
+
+ push_handlers ();
+ if (TIFFSetDirectory (tiff_document->tiff, rc->page) != 1) {
+ pop_handlers ();
+ return NULL;
+ }