From 5ac7231bd357b88678418b4eec896e90c63b4384 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Campos Date: Sun, 08 Apr 2007 16:49:49 +0000 Subject: Use default resolution when it's not provided by document. Fixes bug 2007-03-08 Carlos Garcia Campos * backend/tiff/tiff-document.c: (tiff_document_get_resolution), (tiff_document_get_page_size), (tiff_document_render_pixbuf): Use default resolution when it's not provided by document. Fixes bug #408762. svn path=/trunk/; revision=2399 --- diff --git a/ChangeLog b/ChangeLog index 65fa177..6418772 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2007-03-08 Carlos Garcia Campos + * backend/tiff/tiff-document.c: (tiff_document_get_resolution), + (tiff_document_get_page_size), (tiff_document_render_pixbuf): + + Use default resolution when it's not provided by document. Fixes bug + #408762. + +2007-03-08 Carlos Garcia Campos + * configure.ac: * thumbnailer/Makefile.am: * thumbnailer/evince-thumbnailer.c: (evince_thumbnail_pngenc_get): diff --git a/backend/tiff/tiff-document.c b/backend/tiff/tiff-document.c index 9348ed4..7425947 100644 --- a/backend/tiff/tiff-document.c +++ b/backend/tiff/tiff-document.c @@ -150,6 +150,28 @@ tiff_document_get_n_pages (EvDocument *document) } static void +tiff_document_get_resolution (TiffDocument *tiff_document, + gfloat *x_res, + gfloat *y_res) +{ + gfloat x = 72.0, y = 72.0; + gushort unit; + + if (TIFFGetField (tiff_document->tiff, TIFFTAG_XRESOLUTION, &x) && + TIFFGetField (tiff_document->tiff, TIFFTAG_YRESOLUTION, &y)) { + if (TIFFGetFieldDefaulted (tiff_document->tiff, TIFFTAG_RESOLUTIONUNIT, &unit)) { + if (unit == RESUNIT_CENTIMETER) { + x *= 2.54; + y *= 2.54; + } + } + } + + *x_res = x; + *y_res = y; +} + +static void tiff_document_get_page_size (EvDocument *document, int page, double *width, @@ -170,8 +192,7 @@ tiff_document_get_page_size (EvDocument *document, TIFFGetField (tiff_document->tiff, TIFFTAG_IMAGEWIDTH, &w); TIFFGetField (tiff_document->tiff, TIFFTAG_IMAGELENGTH, &h); - TIFFGetField (tiff_document->tiff, TIFFTAG_XRESOLUTION, &x_res); - TIFFGetField (tiff_document->tiff, TIFFTAG_YRESOLUTION, &y_res); + tiff_document_get_resolution (tiff_document, &x_res, &y_res); h = h * (x_res / y_res); *width = w; @@ -212,22 +233,14 @@ tiff_document_render_pixbuf (EvDocument *document, 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; - } - + tiff_document_get_resolution (tiff_document, &x_res, &y_res); + pop_handlers (); /* Sanity check the doc */ if (width <= 0 || height <= 0) return NULL; - + rowstride = width * 4; if (rowstride / 4 != width) /* overflow */ @@ -247,12 +260,14 @@ tiff_document_render_pixbuf (EvDocument *document, (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); + TIFFReadRGBAImageOriented (tiff_document->tiff, width, height, + (uint32 *)gdk_pixbuf_get_pixels (pixbuf), + ORIENTATION_TOPLEFT, 1); pop_handlers (); scaled_pixbuf = gdk_pixbuf_scale_simple (pixbuf, width * rc->scale, - height * rc->scale * (x_res/y_res), + height * rc->scale * (x_res / y_res), GDK_INTERP_BILINEAR); g_object_unref (pixbuf); -- cgit v0.9.1