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 701622 - [PATCH] Add JPEG image density metadata support
[PATCH] Add JPEG image density metadata support
Status: RESOLVED FIXED
Product: gdk-pixbuf
Classification: Platform
Component: general
git master
Other Linux
: Normal normal
: ---
Assigned To: gdk-pixbuf-maint
gdk-pixbuf-maint
Depends on:
Blocks:
 
 
Reported: 2013-06-05 05:32 UTC by Robert Ancell
Modified: 2014-10-22 14:12 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add JPEG image density metadata support (7.07 KB, patch)
2013-06-05 05:32 UTC, Robert Ancell
none Details | Review
Add JPEG image density metadata support (6.98 KB, patch)
2013-06-05 05:35 UTC, Robert Ancell
none Details | Review
Add JPEG image density metadata support (6.99 KB, patch)
2013-06-05 06:51 UTC, Robert Ancell
none Details | Review
Add JPEG image density metadata support (7.03 KB, patch)
2013-06-05 21:50 UTC, Robert Ancell
none Details | Review
Add JPEG image density metadata support (7.03 KB, patch)
2013-06-06 21:06 UTC, Robert Ancell
none Details | Review
Add JPEG image density metadata support (7.90 KB, patch)
2013-06-07 08:41 UTC, Robert Ancell
none Details | Review
Add JPEG image density metadata support (6.14 KB, patch)
2014-10-21 19:35 UTC, Robert Ancell
reviewed Details | Review
Add JPEG image density metadata support (6.37 KB, patch)
2014-10-22 13:58 UTC, Robert Ancell
none Details | Review
Add JPEG image density metadata support (7.08 KB, patch)
2014-10-22 14:02 UTC, Robert Ancell
accepted-commit_now Details | Review

Description Robert Ancell 2013-06-05 05:32:24 UTC
Add JPEG image density metadata support. Useful for tools like simple scan which know the density.
Comment 1 Robert Ancell 2013-06-05 05:32:47 UTC
Created attachment 246043 [details] [review]
Add JPEG image density metadata support
Comment 2 Robert Ancell 2013-06-05 05:35:01 UTC
Created attachment 246045 [details] [review]
Add JPEG image density metadata support

Fixed whitespace
Comment 3 Robert Ancell 2013-06-05 06:51:27 UTC
Created attachment 246046 [details] [review]
Add JPEG image density metadata support

Correctly set density information after structure is reset
Comment 4 Robert Ancell 2013-06-05 21:50:52 UTC
Created attachment 246119 [details] [review]
Add JPEG image density metadata support

Added bug link into comment (last revision, I promise :)
Comment 5 Robert Ancell 2013-06-06 21:06:15 UTC
Created attachment 246192 [details] [review]
Add JPEG image density metadata support

Corrected grammar in error thrown if density-unit not valid
Comment 6 Robert Ancell 2013-06-07 08:41:33 UTC
Created attachment 246229 [details] [review]
Add JPEG image density metadata support

Document density settings
Comment 7 Matthias Clasen 2013-06-07 10:41:59 UTC
Hmm, do we really have to deal with units here ?
I think
x_dpi=300
y_dpi=300
would be all that could ever be needed ?
Comment 8 Robert Ancell 2013-06-08 04:02:06 UTC
I just matched the JPEG format so it would always work. In terms of what I need for simple-scan, DPI is fine.

If we only support DPI it means on writing a JPEG we always set the units to dots-per-inch, and on reading we convert the units if they are dots-per-cm (with a slight loss in precision).

I'm happy to change the patch if that meets the gdk-pixbuf convention (ease of use over accuracy).
Comment 9 Viktor 2013-06-15 08:40:50 UTC
Hi Matthias!
There's related bug:
https://bugzilla.gnome.org/show_bug.cgi?id=466372
I'm voting for this issue too.
Comment 10 Bastien Nocera 2014-10-21 16:28:26 UTC
(In reply to comment #8)
> I just matched the JPEG format so it would always work. In terms of what I need
> for simple-scan, DPI is fine.
> 
> If we only support DPI it means on writing a JPEG we always set the units to
> dots-per-inch, and on reading we convert the units if they are dots-per-cm
> (with a slight loss in precision).
> 
> I'm happy to change the patch if that meets the gdk-pixbuf convention (ease of
> use over accuracy).

How big would the change of precision be? Do we usually (or ever) get odd numbers for the image resolution (say, not multiples of 300 for data coming from scanners)?
Comment 11 Robert Ancell 2014-10-21 19:35:58 UTC
Created attachment 289070 [details] [review]
Add JPEG image density metadata support

I don't have any data about what real world cases there are. In theory, a scanner might give you an image that is done at 800 dots per cm. This would be rounded to 315dpi. The maximum error would be 0.5dpi I guess.

Here's the patch updated to convert to/from dpi if you prefer that.
Comment 12 Bastien Nocera 2014-10-22 13:33:02 UTC
*** Bug 498721 has been marked as a duplicate of this bug. ***
Comment 13 Bastien Nocera 2014-10-22 13:48:55 UTC
Review of attachment 289070 [details] [review]:

You also need to update gdk_pixbuf_get_option() to mention those same new "read" options.

Nearly there!

::: gdk-pixbuf/io-jpeg.c
@@ +520,3 @@
 	gint   i;
 	char   otag_str[5];
+	char   *density_str;

I wouldn't even try to align them, or I would align letters with letters (not with the asterisk).

@@ +603,3 @@
 
+	switch (cinfo.density_unit)
+	{

"{" on the same line as the switch.

@@ +615,3 @@
+	case 2:
+		/* Dots per cm - convert into dpi */
+		density_str = g_strdup_printf ("%d", (int) round (cinfo.X_density / 2.54));

Can you make that a macro?

@@ +1300,3 @@
+                                       x_density = -1;
+
+                               if (x_density < 0 ||

I think we should fail if a density is passed in and comes out as zero, no?

@@ +1321,3 @@
+                                       y_density = -1;
+
+                               if (y_density < 0 ||

Ditto
Comment 14 Robert Ancell 2014-10-22 13:58:21 UTC
Created attachment 289127 [details] [review]
Add JPEG image density metadata support

Fix whitespace, disallow x-dpi=0 / y-dpi=0. Add macro for converting dots per cm to dpi
Comment 15 Robert Ancell 2014-10-22 14:02:23 UTC
Created attachment 289128 [details] [review]
Add JPEG image density metadata support

Add documentation to gdk_pixbuf_get_option
Comment 16 Bastien Nocera 2014-10-22 14:09:20 UTC
Review of attachment 289128 [details] [review]:

Looks good otherwise to commit to master.

::: gdk-pixbuf/gdk-pixbuf.c
@@ +899,3 @@
  * the "multipage" option string to "yes" when a multi-page TIFF is loaded.
+ * Since 2.32 the JPEG loader sets "x-dpi" and "y-dpi" if the file contains
+ * image density information.

"in dots-per-inches". Not that it's really required, but...
Comment 17 Robert Ancell 2014-10-22 14:12:15 UTC
Thanks Bastian!
Comment 18 Robert Ancell 2014-10-22 14:12:45 UTC
Bastien I mean...