Bug 85761 - Exporting jpeg format from DRAW, resolution does not follow options setting
Summary: Exporting jpeg format from DRAW, resolution does not follow options setting
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Draw (show other bugs)
Version:
(earliest affected)
4.2.6.3 release
Hardware: x86-64 (AMD64) Windows (All)
: medium normal
Assignee: Chris Sherlock
QA Contact:
URL:
Whiteboard: target:5.2.0 target:5.1.2 target:5.0.6
Keywords:
: 97481 (view as bug list)
Depends on:
Blocks:
 
Reported: 2014-11-02 16:14 UTC by Gary
Modified: 2016-10-25 19:07 UTC (History)
5 users (show)

See Also:
Crash report or crash signature:


Attachments
File to be exported (112.68 KB, application/vnd.oasis.opendocument.graphics)
2015-12-09 14:59 UTC, Regina Henschel
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Gary 2014-11-02 16:14:18 UTC
In the draw app, Select File -> export
select jpeg file type
when the options window open, the default resolution is 96dpi, but the user can change that setting.
Change the resolution to 300 or 600 and export.
The exported file always has 96dpi regardless of the user setting in the options window.
Comment 1 Buovjaga 2014-11-15 13:58:31 UTC

*** This bug has been marked as a duplicate of bug 37678 ***
Comment 2 Regina Henschel 2015-12-09 14:58:14 UTC
It is not duplicate to bug 37678. Bug 37678 is about the behavior of the fields in the dialog.

To reproduce this bug do this:
Open the attached file. It has 10cm width and 14cm height.
File > Export
Select file type jpeg.
In the export dialog make the following settings in this order:
   Set Quality to 100
   Set Resolution to 300 pixel/inch
   Set width to 10cm.
Save

This setting should result (besides rounding errors) in
width: (10 / 2.54) * 300 =  1181 Pixel
height: (14 / 2.54) * 300 = 1654 Pixel
Indeed, the exported image has the size (w x h): 1183 x 1656.

But when you look at the stored dpi, as reported by a picture viewer like IrfanView, then you can see the value 96 dpi. The effect is, that other application will calculate a wrong width for this image. You can correct the value to 300 dpi in IrfanView and all is OK.

LO 4.2 had not written any dpi into the file, so there it was wrong too.

Expected behavior: The resolution, which was used for generating the pixels for export, should be written into the file. Jpeg allows such information.

BTW: The export to png does not have this problem, in png-export the dpi value is correctly written.
Comment 3 Regina Henschel 2015-12-09 14:59:56 UTC
Created attachment 121172 [details]
File to be exported
Comment 4 Regina Henschel 2016-02-02 22:26:34 UTC
*** Bug 97481 has been marked as a duplicate of this bug. ***
Comment 5 MM 2016-02-11 19:09:15 UTC
(In reply to Regina Henschel from comment #2)

> But when you look at the stored dpi, as reported by a picture viewer like
> IrfanView, then you can see the value 96 dpi. The effect is, that other
> application will calculate a wrong width for this image. You can correct the
> value to 300 dpi in IrfanView and all is OK.
> 

Well, that might seems to be a result of the patch from bug 65695.
Instead of taking the dpi from the resolution setting (which is 96 by default anyway [correct my if i'm wrong]), it seems hardcoded to 96.

--> tdf#65695 write density 96 DPI to JPEG files at compression 

https://cgit.freedesktop.org/libreoffice/core/commit/?id=d0d8e0a2a7244814f783f16c6c8b342fe6d16e79
Comment 6 Chris Sherlock 2016-02-12 09:03:56 UTC
Unless I'm much mistaken, the Graphics class has no way of getting either the physical size of the graphics image in mm/inches, or alternatively has no way of returning the pixels per inch from which you could extrapolate the physical size...

http://opengrok.libreoffice.org/xref/core/include/vcl/graph.hxx#109

This seems like a bit of a shortcoming in this class? Is that something we should consider adding?
Comment 7 Chris Sherlock 2016-02-13 07:25:29 UTC
OK, about to submit a proposed patch to gerrit.
Comment 8 Chris Sherlock 2016-02-13 07:33:52 UTC
Asking for a review on Gerrit:

https://gerrit.libreoffice.org/22339
Comment 9 Chris Sherlock 2016-02-13 07:52:00 UTC
So it appears in comment 6 I was mistaken. To get the PPI of an instance of Graphics, you need to get the actual physical size of the image via GetPrefSize, then you need to work out what the logical units are, and from here you can divide the pixel size by the logical size, once that logical size is converted to inches.
Comment 10 Commit Notification 2016-02-14 20:52:31 UTC
Chris Sherlock committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=f8355221ae62b89a706f2d04b63eda658f3ccfa5

tdf#85761 vcl: JPEG export does not save PPI values correctly

It will be available in 5.2.0.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 11 Yan Pas 2016-02-14 21:47:03 UTC
What about 5.1.1 and 5.0.6?
Comment 12 Chris Sherlock 2016-02-16 23:56:25 UTC
I've got a 5-1 fix loaded up waiting to be reviewed here:

https://gerrit.libreoffice.org/#/c/22380/

Bare with me, I've never done a back ported fix before :-) I'm pretty sure it wouldn't be too hard to get a fix into 5.0.6, I guess I need guidance on what the normal course of events is wrt to back porting fixes.
Comment 13 Commit Notification 2016-02-17 20:13:48 UTC
Chris Sherlock committed a patch related to this issue.
It has been pushed to "libreoffice-5-1":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=a93f7792af5a8ce53ef1dc57380624476e14f933&h=libreoffice-5-1

tdf#85761 vcl: JPEG export does not save PPI values correctly

It will be available in 5.1.2.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 14 Chris Sherlock 2016-02-18 05:10:56 UTC
I've submitted a gerrit patch for 5.0:

https://gerrit.libreoffice.org/c/#/22454/
Comment 15 Chris Sherlock 2016-02-18 05:11:18 UTC
I've submitted a gerrit patch for 5.0:

https://gerrit.libreoffice.org/#/c/22454/
Comment 16 Commit Notification 2016-02-24 11:22:14 UTC
Chris Sherlock committed a patch related to this issue.
It has been pushed to "libreoffice-5-0":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=a8c2e437a38fcb0cda9f3e8569f32185597f893f&h=libreoffice-5-0

tdf#85761 vcl: JPEG export does not save PPI values correctly

It will be available in 5.0.6.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.