After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 498721 - Add TIFF image density metadata support
Add TIFF image density metadata support
Status: RESOLVED FIXED
Product: gdk-pixbuf
Classification: Platform
Component: loaders
git master
Other Linux
: Normal enhancement
: ---
Assigned To: gdk-pixbuf-maint
gdk-pixbuf-maint
Depends on:
Blocks:
 
 
Reported: 2007-11-21 11:48 UTC by Josselin Mouette
Modified: 2014-10-30 20:33 UTC
See Also:
GNOME target: ---
GNOME version: 2.19/2.20


Attachments
Sample file produced by hylafax (5.71 KB, image/tiff)
2007-11-21 11:49 UTC, Josselin Mouette
  Details
EOG, 2.20.3 (43.67 KB, image/png)
2008-01-02 02:54 UTC, marcodefreitas
  Details
Evince, 2.20.2 (34.30 KB, image/png)
2008-01-02 02:55 UTC, marcodefreitas
  Details
Evince, 2.20.2; received.tif rotated 90°. (33.15 KB, image/png)
2008-01-02 23:28 UTC, marcodefreitas
  Details
Add TIFF image density metadata support (10.72 KB, patch)
2014-10-22 17:41 UTC, Robert Ancell
reviewed Details | Review
Add TIFF image density metadata support (10.41 KB, patch)
2014-10-22 18:06 UTC, Robert Ancell
none Details | Review
Add TIFF image density metadata support (10.22 KB, patch)
2014-10-23 04:40 UTC, Robert Ancell
none Details | Review
Add TIFF image density metadata support (12.21 KB, patch)
2014-10-30 03:06 UTC, Robert Ancell
none Details | Review
Add TIFF image density metadata support (12.07 KB, patch)
2014-10-30 03:09 UTC, Robert Ancell
accepted-commit_now Details | Review

Description Josselin Mouette 2007-11-21 11:48:09 UTC
Some pictures, like those produced by hylafax, have different resolutions for the x and y directions. If you want to see them with a correct aspect ratio, you need to scale them in one of the directions.

However, gdk-pixbuf only takes into account the number of pixels, which means the picture is displayed completely distorted in all applications using gdk-pixbuf directly, while e.g. the gimp displays them fine.
Comment 1 Josselin Mouette 2007-11-21 11:49:39 UTC
Created attachment 99429 [details]
Sample file produced by hylafax
Comment 2 marcodefreitas 2008-01-02 02:54:33 UTC
Created attachment 101967 [details]
EOG, 2.20.3
Comment 3 marcodefreitas 2008-01-02 02:55:09 UTC
Created attachment 101968 [details]
Evince, 2.20.2
Comment 4 Mathias Hasselmann (IRC: tbf) 2008-01-02 09:16:57 UTC
I fail to see how this is a gdk-pixbuf bug. 

What change do you propose? 

Would it be sufficient, if gdk-pixbuf would provide access to the physical resolution of each picture it loaded?

If you really need scaling: When should that scaling be applied? Directly after loading? Just when drawing? Wouldn't that be a incompatible change in gdk-pixbuf's behaviour?

Shouldn't just EOG be changed to correctly handle this case?
Comment 5 Josselin Mouette 2008-01-02 13:37:56 UTC
I think the first thing to do is indeed to provide access to the physical resolution. But it would also be nice to provide functions to generate a scaled pixbuf that would render correctly on screen given the physical resolution difference, avoiding to put this logic in each and every application.
Comment 6 marcodefreitas 2008-01-02 23:26:48 UTC
I agree.
I reported this bug as an EOG bug only. It works well on Evince.
But Evince has other bug. Try to load the `received.tiff' sample on EOG and rotate it. Wrong AR but It's OK.
When the same is done on Evince the sample is so buggy. I'll attach a sample.
Comment 7 marcodefreitas 2008-01-02 23:28:27 UTC
Created attachment 102023 [details]
Evince, 2.20.2; received.tif rotated 90°.
Comment 8 Bastien Nocera 2014-10-22 13:33:02 UTC
Bug 701622 has patches about adding resolution information to images, so I'll make this older bug a duplicate of that newer one.

(In reply to comment #5)
> I think the first thing to do is indeed to provide access to the physical
> resolution.

That would be done in the above bug.

> But it would also be nice to provide functions to generate a scaled
> pixbuf that would render correctly on screen given the physical resolution
> difference, avoiding to put this logic in each and every application.

It's purely a rendering problem. I don't think that GdkPixbuf would be doing someone any favours by scaling the image to have square pixels, especially when we can handle non-square ratios better in the front-end (totem has been handling non-square pixels for longer than this very old bug has existed ;)

*** This bug has been marked as a duplicate of bug 701622 ***
Comment 9 Bastien Nocera 2014-10-22 13:43:27 UTC
bug 701622 is about JPEGs, not TIFFs...
Comment 10 Robert Ancell 2014-10-22 17:41:04 UTC
Created attachment 289153 [details] [review]
Add TIFF image density metadata support
Comment 11 Bastien Nocera 2014-10-22 17:57:13 UTC
Review of attachment 289153 [details] [review]:

The gdk_pixbuf__tiff_image_save_to_callback() changes will likely clash with that from bug 578876 which contains support for many more metadata.

::: gdk-pixbuf/io-png.c
@@ -27,3 @@
 #include <string.h>
 #include <png.h>
-#include <math.h>

That change probably needs to be made in a separate commit.
Comment 12 Robert Ancell 2014-10-22 18:06:48 UTC
Created attachment 289162 [details] [review]
Add TIFF image density metadata support

Remove removal of duplicate math.h include
Comment 13 Robert Ancell 2014-10-22 18:07:40 UTC
Regarding bug 578876 - do you want me to do anything about that?
Comment 14 Bastien Nocera 2014-10-22 18:24:09 UTC
(In reply to comment #13)
> Regarding bug 578876 - do you want me to do anything about that?

It would be great if you had time to update the patch from bug 578876, so it can be landed before this one.
Comment 15 Bastien Nocera 2014-10-22 21:45:21 UTC
(In reply to comment #12)
> Created an attachment (id=289162) [details] [review]
> Add TIFF image density metadata support
> 
> Remove removal of duplicate math.h include

I meant the adding it somewhere else as well, seems to be a bug that it's not in the place where the math functions are used (where round() is).
Comment 16 Robert Ancell 2014-10-23 04:08:21 UTC
> > Remove removal of duplicate math.h include
> 
> I meant the adding it somewhere else as well, seems to be a bug that it's not
> in the place where the math functions are used (where round() is).

I added into gdk-pixbuf-private.h so it was no longer needed in io-png.h anymore (it was only used for the conversion macros which are now common).
Comment 17 Robert Ancell 2014-10-23 04:40:33 UTC
Created attachment 289187 [details] [review]
Add TIFF image density metadata support

Rebased on master. For some reason it the TIFF tests are now failing for me with "SKIP format not supported" but I can't work out what might be causing that.
Comment 18 Bastien Nocera 2014-10-23 10:07:29 UTC
First, you'll need to add "tiff" to test-common.c.

I would also add (in a separate commit) a:
g_assert_nonnull (pixbuf);
after the gdk_pixbuf_new_from_file() call, to make sure that the image got actually loaded, and did not fail without an error.

Once that's done, I get:
$ GDK_PIXBUF_MODULE_FILE=../gdk-pixbuf/loaders.cache ./pixbuf-dpi 
/pixbuf/dpi/png: OK
/pixbuf/dpi/jpeg: OK
/pixbuf/dpi/tiff:
**
ERROR:pixbuf-dpi.c:92:test_nonincremental: assertion failed: (strcmp (x_dpi, "300") == 0)

You should be using g_assert_cmpstr() which shows the value expected, and the value we got. Which shows:
ERROR:pixbuf-dpi.c:92:test_nonincremental: assertion failed (x_dpi == "300"): ("-2147483648" == "300")

Which shows where the problem might be.
Comment 19 Bastien Nocera 2014-10-23 10:32:36 UTC
Apparently it's a float, not a uint32. That fixes the test suite. Yay tests :)
Comment 20 Robert Ancell 2014-10-30 03:06:28 UTC
Created attachment 289622 [details] [review]
Add TIFF image density metadata support

Fixed up types used with TIFFGetField / TIFFSetField. Fixed tests.
Comment 21 Robert Ancell 2014-10-30 03:09:01 UTC
Created attachment 289623 [details] [review]
Add TIFF image density metadata support

Removed some temp debugging code
Comment 22 Bastien Nocera 2014-10-30 09:01:51 UTC
Review of attachment 289623 [details] [review]:

Looks good otherwise.

::: gdk-pixbuf/io-tiff.c
@@ +897,3 @@
+        if (x_dpi != NULL && y_dpi != NULL) {
+                char *endptr = NULL;
+                uint16 resolution_unit = RESUNIT_INCH;

Can't you directly use it in the SetField function below?
Comment 23 Robert Ancell 2014-10-30 20:29:32 UTC
This problem has been fixed in the development version. The fix will be available in the next major software release. Thank you for your bug report.
Comment 24 Robert Ancell 2014-10-30 20:33:51 UTC
> +                uint16 resolution_unit = RESUNIT_INCH;
> 
> Can't you directly use it in the SetField function below?

I think you can but I decided to be explicit in that is was a uint16, not a general integer.