Bug 83734 - EDITING: Cropped image gets distorted when Compress Graphic is used
Summary: EDITING: Cropped image gets distorted when Compress Graphic is used
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: graphics stack (show other bugs)
(earliest affected) release
Hardware: All All
: high major
Assignee: Not Assigned
Keywords: bibisected, bisected
: 96726 113116 117126 131174 141435 146044 152163 158729 (view as bug list)
Depends on: 99286
Blocks: 34133 Image-Compression 107875 Image-Crop Image-DPI
  Show dependency treegraph
Reported: 2014-09-10 20:02 UTC by Stephan van den Akker
Modified: 2024-02-02 09:37 UTC (History)
22 users (show)

See Also:
Crash report or crash signature:

Sample document with a cropped image (18.19 KB, application/vnd.oasis.opendocument.text)
2014-09-10 20:02 UTC, Stephan van den Akker
Distorted compressed image LO (x64) (41.18 KB, image/jpeg)
2016-10-20 09:00 UTC, Thomas Lendo
Test file with different images (cropped and not) (5.81 MB, application/vnd.oasis.opendocument.text)
2017-02-15 11:01 UTC, Thomas Lendo
Impress .odp with a cropped image (22.65 KB, application/vnd.oasis.opendocument.presentation)
2018-04-21 15:14 UTC, Luke

Note You need to log in before you can comment on or make changes to this bug.
Description Stephan van den Akker 2014-09-10 20:02:53 UTC
Created attachment 106084 [details]
Sample document with a cropped image

How to reproduce:

1 Load the sample document with the cropped image (only green half visible)
2 Right-Click the image, choose Compress Graphic...
3 Choose OK (default settings will do)

Expected result: Cropped part (red) still invisible

Actual result: Part of the cropped right half (red) of the image becomes visible

Bug observed in:

LibreOffice on openSuSE 12.3 (64-bit)

LibreOffice on openSuSE factory (32-bit)

LibreOfficeDev on openSuSE 12.3 (64-bit)
Build ID: 53425404ae70bf365073cce2f5d576b769446c97
Comment 1 Jean-Baptiste Faure 2014-09-14 15:54:27 UTC
Thank you for this bug report.
Reproducible for me with version built at home under Ubuntu 14.04 x86-64.

Best regards. JBF
Comment 2 hopung 2015-09-15 16:08:34 UTC
Here, too. 

Version on Ubuntu 15.04. (Actually have seen on any version of Ubuntu + any version of LO that I have used for the last 3 years.)

I found that when multiple images are inserted in writer/impress, it becomes quite slow. I would say it is slower than what I would expect from MS office, or Mac applications with similar systems.
I guess Libreoffce tries to give more control to users not just performing arbitrary compression. That I like, but I think that approach is not complete until all image information are safely kept over this and that modifications to images.

I always appreciate your work, LO team. 

Comment 3 Stephan van den Akker 2015-09-18 13:03:02 UTC Comment hidden (obsolete)
Comment 4 QA Administrators 2016-09-20 10:32:14 UTC Comment hidden (obsolete)
Comment 5 Stephan van den Akker 2016-09-20 13:08:18 UTC Comment hidden (obsolete)
Comment 6 Thomas Lendo 2016-10-20 08:55:29 UTC
I conform the problem with compressed JPEG pictures in 2 variations:

* The compressed picture disappears completely.

* The compressed picture will be very small but the picture frame remain the same so that the compressed picture has the same height and witdh as before but the most space is white and the original picture is a small picture in the white picture.

But not all JPEG pictures are affected.

Version: (x64)
Build-ID: f99d75f39f1c57ebdd7ffc5f42867c12031db97a
CPU-Threads: 8; BS-Version: Windows 6.19; UI-Render: Standard; 
Gebietsschema: de-AT (de_DE)
Comment 7 Thomas Lendo 2016-10-20 09:00:00 UTC Comment hidden (obsolete)
Comment 8 Thomas Lendo 2016-12-27 07:21:34 UTC
Isn't such bug a regression that should be fixed in a new version like 5.3? The bug makes a feature available in a right-click menu unusable.
Comment 9 Thomas Lendo 2017-02-15 11:01:44 UTC
Created attachment 131240 [details]
Test file with different images (cropped and not)

Tested it with the current version and found out that the bug still exists. I created a test file with 3 different images and all cropped and not cropped. Résumé:

Only cropped JPEG photographs that were NOT manipulated with image manipulation programs like GIMP are affected (see page 2, manipulated JPEG images see page 1).

Only cropped PNG images that are cropped with "JPEG quality" (and not with "PNG compression") are affected (see page 3).

Build ID: 7074905676c47b82bbcfbea1aeefc84afe1c50e1
CPU Threads: 8; OS Version: Windows 6.2; UI Render: default; Layout Engine: new; 
Locale: de-DE (de_DE); Calc: CL
Comment 10 Thomas Lendo 2017-03-04 19:12:49 UTC Comment hidden (obsolete)
Comment 11 Alvaro 2017-06-08 20:46:26 UTC
i confirm the bug on libreoffice under windows 10.
If you first make a compression of the image and then crop it there is no problem.
Comment 12 Thomas Lendo 2017-08-31 20:10:16 UTC
It seems that fixing of Bug 99286 "Cropped image disappear after compress" fixed the main problem of attachment 131240 [details] but that doesn't touch the problem described by the bug opener and shown in attachment 106084 [details]. In attachment 131240 [details] I still also see this problem of "horizontally shrinking" of the cropped image so that former cropped part of the image is seen after compressing it.

Build-ID: ea7cb86e6eeb2bf3a5af73a8f7777ac570321527
CPU-Threads: 4; Betriebssystem:Linux 4.10; UI-Render: Standard; VCL: gtk2; 
Gebietsschema: de-DE (de_DE.UTF-8); Calc: group
Comment 13 ace_dent 2017-10-24 01:07:31 UTC
*** Bug 96726 has been marked as a duplicate of this bug. ***
Comment 14 ace_dent 2017-10-24 01:09:23 UTC
*** Bug 113116 has been marked as a duplicate of this bug. ***
Comment 15 Sasha 2017-10-24 05:30:47 UTC
The bug 99286 DID NOT solve this bug. See the bug 113116 and the last comments in the discussion of the bug 99286 for test-cases that the bug is still present in and
(BTW, the bug 113116 was marked as CONFIRMED before being marked as duplicate; so this one should be CONFIRMED too; although I'm not sure if it was correct to mark as duplicate, because this one is about and that one was said to be a "regression introduced in the 5.0 cycle".)
Comment 16 aflux 2017-11-08 14:29:02 UTC Comment hidden (obsolete)
Comment 17 Thomas Lendo 2017-11-08 18:36:57 UTC
(In reply to aflux from comment #16)
> The same happens on Impress (LO when applying compress after crop;
> the other way round works ok.
> Should I open a specific bug for Impress? The two might be related to the
> same upstream problem
Please test with a current 5.4 LibreOffice and create a new bug for Impress if it's also affected. Add this bug to "See also" and please add the same blocking bugs to the new bug. Thanks!
Comment 18 Luke 2018-04-21 15:14:15 UTC
Created attachment 141524 [details]
Impress .odp with a cropped image

I highly doubt this is a separate bug as the steps to reproduce and the results are identical in Writer and Impress. Still reproducible in Version: (x64)
Build ID: d4a01820ae094ef2d4ec2196334120600b1c9621
Comment 19 QA Administrators 2019-11-01 03:36:56 UTC Comment hidden (obsolete)
Comment 20 Stephan van den Akker 2019-11-01 09:44:28 UTC Comment hidden (obsolete)
Comment 21 Stephan van den Akker 2019-11-01 13:23:22 UTC
Reproduced in:

Build ID: 202a49a5831fbfcf057350ef949c13e75b3b7446
CPU threads: 8; OS: Linux 5.3; UI render: default; VCL: kf5; 
Locale: en-GB (en_GB.UTF-8); UI-Language: en-GB
Calc: threaded
Comment 22 Timur 2019-12-04 11:17:54 UTC
Repro LO 6.5+. I set as Major, due to duplicates and uncertainty.
I don't know how Compress could be regression, I think introduced in LO 4.1.
Comment 23 Xisco Faulí 2019-12-12 09:46:07 UTC
not a regression. The enhancement was added in https://cgit.freedesktop.org/libreoffice/core/commit/?id=44faceac60f9046e4827290a85f790a46ed1e227

@Quikee, I thought you might be interested in this issue...
Comment 24 Luke 2019-12-12 22:19:06 UTC
*** Bug 117126 has been marked as a duplicate of this bug. ***
Comment 25 Justin L 2020-03-02 11:36:48 UTC
I am not a graphics guy at all.
But I think the problem is that SdrGrafCropItem is in 100mm, which is a fairly useless number unless you know the DPI that it is connected with. And the DPI changes constantly in this example - from the initial image's 300-DPI to the compressed images preferred 72-DPI (despite the variable specifying 300).

Ultimately, I suspect the biggest problem is that SetPreferredSize is not done with the compression-DPI.

The second problem is that we have no idea of the view-size of the image, only the view-size of the cropped part. And the cropped parameters are also based on some DPI - likely based on the GetPreferredSize scale.

Specifically, for attachment 106084 [details] from comment 0: In the initial graphic, it reports an original size of 6.77cm x 3.39cm @ dpi 300, but when compressing (still to DPI 300 - the default), then the image properties report a much larger distance (in mm) at DPI 72.  However, the scaling knows nothing about this DPI coordinate change from 300 to 72, and so it scales and crops with distances appropriate for 300DPI instead of 72DPI.
Comment 26 Justin L 2020-03-03 13:20:26 UTC
attachment 131240 [details] from comment #9 is a really good testcase - creating some very diverse situations. Picture 1 is a tiny image with a huge DPI (according to the properties) and a huge scale factor.  The filesize actually increasess when compressed.

Picture 2 is a very large image scaled way down. It is very hard to separate the cropping from the scaling...

Pictures 2 and 3 are in MapPixel mode. And additional example of finding a picture in MapUnit::MapInch would be good.
Comment 27 Justin L 2020-03-03 19:24:00 UTC
(In reply to Justin L from comment #26)
> Picture 2 is a very large image scaled way down. It is very hard to separate
> the cropping from the scaling...
This is the one that really throws me off. What determines how to treat the crop? The coordinates of the crop don't seem to be related to either the pixelsize, the prefsize, or the viewsize.

CompressGraphicsDialog CTOR viewSize[7558x11058] crop[-40233x0@(40233,0)] PrefSize[3120x2340] PizelSize[3120x2340] PPI[(72.0006,72)] PrefMode[MapMode(10,((1/1),(1/1))@(0,0))]

I'm done with this nonsense.
Comment 28 Timur 2020-03-06 19:17:44 UTC
*** Bug 131174 has been marked as a duplicate of this bug. ***
Comment 29 dainius.mazuika 2020-10-05 05:19:06 UTC
The same occurring in v7.0.1.2 (2020-10-05), Win 10 x64. Kind of important bug.
Comment 30 Claudio Negri 2020-10-19 09:43:51 UTC
Same problem for me.

Version: (x64)
Build ID: 8349ace3c3162073abd90d81fd06dcfb6b36b994
CPU threads: 8; OS: Windows 10.0 Build 19041; UI render: Skia/Raster; VCL: win
Locale: it-IT (it_IT); Interfaccia utente: it-IT
Calc: CL
Comment 31 Zanorphy 2020-11-14 08:17:52 UTC Comment hidden (spam)
Comment 32 Justin L 2021-12-09 06:24:35 UTC
*** Bug 146044 has been marked as a duplicate of this bug. ***
Comment 33 Stéphane Guillou (stragu) 2022-11-23 20:36:37 UTC
*** Bug 152163 has been marked as a duplicate of this bug. ***
Comment 34 Stéphane Guillou (stragu) 2022-11-23 20:43:54 UTC
Still reproduced with:

Version: (X86_64) / LibreOffice Community
Build ID: d1dd9b9733511ff451e264169537c08fa14c574f
CPU threads: 8; OS: Linux 5.15; UI render: default; VCL: gtk3
Locale: en-AU (en_AU.UTF-8); UI: en-US
Calc: threaded

With attachment 131240 [details], the cropped JPG and PNG pictures on pages 2 and 3 have their scaling modified when compressing with the JPG quality option.
Comment 35 Stéphane Guillou (stragu) 2022-11-23 20:47:00 UTC
*** Bug 141435 has been marked as a duplicate of this bug. ***
Comment 36 Telesto 2023-12-20 15:24:44 UTC
*** Bug 158729 has been marked as a duplicate of this bug. ***
Comment 37 Xavier R 2024-02-02 09:37:02 UTC
Same problem for me.
Very problematic bug!

Version: (X86_64) / LibreOffice Community
Build ID: cdeefe45c17511d326101eed8008ac4092f278a9
CPU threads: 12; OS: Windows 10.0 Build 22631; UI render: Skia/Raster; VCL: win
Locale: fr-FR (fr_FR); UI: fr-FR
Calc: CL threaded