Bug 153190 - Compressing tool calculates compression rate wrong on large images
Summary: Compressing tool calculates compression rate wrong on large images
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
7.1.0.0.alpha1+
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard: target:7.6.0 target:7.5.3.2 target:7....
Keywords: implementationError
Depends on:
Blocks: Image-Compression-Dialog
  Show dependency treegraph
 
Reported: 2023-01-24 20:08 UTC by CaCO3
Modified: 2023-05-03 10:17 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments
Screenshot (35.89 KB, image/png)
2023-01-24 20:09 UTC, CaCO3
Details

Note You need to log in before you can comment on or make changes to this bug.
Description CaCO3 2023-01-24 20:08:04 UTC
Description:
Uint16 Overflow on the compression rate calculation

Steps to Reproduce:
1. Load a large png image (eg. 70 MB) into impress
2. Call the compression tool
3. Let it calculate the compression rate

Actual Results:
Compression Rate: -18%

Expected Results:
Compression Rate: 98%


Reproducible: Always


User Profile Reset: No

Additional Info:
There is an UNIT16 overflow since the image is larger than 65535
Comment 1 CaCO3 2023-01-24 20:09:07 UTC
Created attachment 184880 [details]
Screenshot
Comment 2 Stéphane Guillou (stragu) 2023-01-25 11:13:00 UTC
Reproduced with:

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

Using default settings in Right click > Compress, clicking "Calculate New Size", the calculated reduction in size is wrong for a large PNG file of about 48 mb.

Large 47,196 kb file generated with ImageMacick:

   convert -size 5000x5000 xc:gray +noise gaussian large.png

New size will be 20,484 kb but reduction displayed as "-32% reduction".

Not-so-large 16,992 kb file generated with:

   convert -size 3000x3000 xc:gray +noise gaussian not_too_large.png

New size will be 7,376 kb, correct reduction displayed: "56% reduction".
Comment 3 Stéphane Guillou (stragu) 2023-04-20 09:25:33 UTC
Tests with images generated with commands in Comment 2:

- LO 7.1.0.3 (when percentages started being shown):
   - Large: 47,196 -> 439 kiB = 10% reduction (wrong)
   - Smaller: 16,992 -> 143 kiB = 99% reduction (correct)

- LO 7.2.7.2 to 7.3.7.2: 
   - Large: 47,196 -> 467 kiB = 10% reduction (wrong)
   - Smaller: 16,992 -> 151 kiB = 99% reduction (correct)

- LO 7.4.6.2
   - Large: 47,196 -> 19,637 = -30% reduction (wrong)
   - Smaller: 16,992 -> 7,071 = 58% reduction (correct)

- LO 7.5.3.1 to recent master build 7.6 alpha0+:
   - Large: 47,196 -> 20,485 = -32% reduction (wrong)
   - Smaller: 16,992 -> 7,376 = 56% reduction (correct)

So percentage has been wrong (in different ways) with large files since percentages started showing, so I assume since commit 46772b2dbbc269c2e83f00af2cd864fb64ccf425 that fixed bug 87963.
Daniel hasn't been active since that commit, so copying Noel as a reviewer in case you have ideas / pointers.

Master build:

Version: 7.6.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 61b41646c5a93ca24f2c9f143cdb0da2c9258989
CPU threads: 8; OS: Linux 5.15; UI render: default; VCL: gtk3
Locale: en-AU (en_AU.UTF-8); UI: en-US
Calc: threaded
Comment 4 Noel Grandin 2023-04-20 09:48:27 UTC
fix here: https://gerrit.libreoffice.org/c/core/+/150683
Comment 5 Stéphane Guillou (stragu) 2023-04-20 10:57:10 UTC
Oof that was quick, thanks Noel! :)
Comment 6 Commit Notification 2023-04-20 11:07:31 UTC
Noel Grandin committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/b167bc073b6b83110242bfbace107f6978e5bca7

tdf#153190 Compressing tool calculates compression rate wrong on large images

It will be available in 7.6.0.

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

Affected users are encouraged to test the fix and report feedback.
Comment 7 Commit Notification 2023-04-20 12:40:47 UTC
Noel Grandin committed a patch related to this issue.
It has been pushed to "libreoffice-7-5":

https://git.libreoffice.org/core/commit/086a546c2f30e918dad8793834559ae930d11e7a

tdf#153190 Compressing tool calculates compression rate wrong on large images

It will be available in 7.5.4.

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

Affected users are encouraged to test the fix and report feedback.
Comment 8 Commit Notification 2023-04-20 13:17:01 UTC
Noel Grandin committed a patch related to this issue.
It has been pushed to "libreoffice-7-4":

https://git.libreoffice.org/core/commit/6982e1f3c6fc90d0e6ff268a12b78e8e3ef049fa

tdf#153190 Compressing tool calculates compression rate wrong on large images

It will be available in 7.4.8.

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

Affected users are encouraged to test the fix and report feedback.
Comment 9 CaCO3 2023-04-23 14:13:52 UTC
Thanks for fixing it!

I tested it with 7.5.4.0.0+ (X86_64) and can confirm that it is working now as expected.
Comment 10 Commit Notification 2023-04-25 09:19:07 UTC
Noel Grandin committed a patch related to this issue.
It has been pushed to "libreoffice-7-5-3":

https://git.libreoffice.org/core/commit/fcda481a0758c9727d126404778cc16f4ef1bb13

tdf#153190 Compressing tool calculates compression rate wrong on large images

It will be available in 7.5.3.

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

Affected users are encouraged to test the fix and report feedback.
Comment 11 Commit Notification 2023-05-03 09:52:14 UTC
Noel Grandin committed a patch related to this issue.
It has been pushed to "libreoffice-7-4-7":

https://git.libreoffice.org/core/commit/81fef0001acb152bd21b0ec7ea6ac44ae0d287d0

tdf#153190 Compressing tool calculates compression rate wrong on large images

It will be available in 7.4.7.

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

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