Bug 154758 - Changing the resolution computes the new size incorrectly
Summary: Changing the resolution computes the new size incorrectly
Status: RESOLVED WORKSFORME
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
7.4.1.2 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Image-Compression-Dialog
  Show dependency treegraph
 
Reported: 2023-04-11 14:52 UTC by csongor
Modified: 2023-07-27 14:57 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments
This file has a 2×2 image which becomes 3×3 instead of 300×300, when Resolution is changed in the Compress dialog (83.92 KB, application/vnd.oasis.opendocument.text)
2023-04-28 10:26 UTC, csongor
Details

Note You need to log in before you can comment on or make changes to this bug.
Description csongor 2023-04-11 14:52:52 UTC
Description:
If I change the resolution of a 2×2 pixel image to 300×300, it changes to 3×3 instead of 300×300.

Steps to Reproduce:
1. Paste a small 2×2 pixel png image into the document. 
2. Change the resolution with Right click → Compress → Reduce image resolution to 300×300


Actual Results:
The image dimension will change to 3×3 and the rounding errors distort the image.


Expected Results:
The dimensions should be 300×300, not 3×3, which would not distort the image, just would increase the size to 150 times of the original.



Reproducible: Always


User Profile Reset: No

Additional Info:
Moreover, the label of the checkbox should be "Change image resolution to", not "Reduce resolution to" because the user can enter larger values as well, not just smaller ones.

Increasing the resolution is handy if you want to keep the pixelated nature of the picture. For example, if you want to paste an 8-bit pixel art and want to avoid the enforced blur effect Writer applies on enlarged images. Until Bug #56468 gets resolved, this is the best way to get sharp pixelated images.
Comment 1 Dieter 2023-04-23 15:56:31 UTC
I can't confirm with

Version: 7.6.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 006b35d50024b1932d84380b5d2fec1f7066bccd
CPU threads: 4; OS: Windows 10.0 Build 19045; UI render: Skia/Raster; VCL: win
Locale: en-US (de_DE); UI: en-GB
Calc: CL threaded

Could you please restest in SafeMode (Help -> Restart in SafeMode) and add screenshot of settings in Compress Image Dialog? Thank you.
=> NEEDINFO
Comment 2 csongor 2023-04-28 10:23:21 UTC
I upgraded my LibreOffice:

Version: 7.5.2.2 (X86_64) / LibreOffice Community
Build ID: 53bb9681a964705cf672590721dbc85eb4d0c3a2
CPU threads: 12; OS: Windows 10.0 Build 19045; UI render: Skia/Raster; VCL: win
Locale: en-AU (en_AU); UI: en-US
Calc: CL threaded

I use the same document as I did before and now I attach it to the bug as well. I still can see the problem. 

Please open sample.doc and change the resolution of the 2×2 image in the first paragraph to 300×300. If you save the odt and rename it to zip, you will find the new PNG file in the Pictures directory which is a 3×3 image. 

The original black-and-white checkboard image from

BW
WB

got changed to 

BBW
BBW
WWB.

I believe instead of this, it should be a 300×300 image like this:

BBB...BBBWWW...WWW
BBB...BBBWWW...WWW
BBB...BBBWWW...WWW
...
...
...
BBB...BBBWWW...WWW
BBB...BBBWWW...WWW
BBB...BBBWWW...WWW
WWW...WWWBBB...BBB
WWW...WWWBBB...BBB
WWW...WWWBBB...BBB

The 300×300 image wouldn't be distorted while the 3×3 is.
Comment 3 csongor 2023-04-28 10:26:14 UTC
Created attachment 186979 [details]
This file has a 2×2 image which becomes 3×3 instead of 300×300, when Resolution is changed in the Compress dialog
Comment 4 QA Administrators 2023-04-29 03:29:51 UTC Comment hidden (obsolete)
Comment 5 ysui2022 2023-07-20 04:48:14 UTC
I can't reproduce this. It doesn't allow me to set it to 300*300

Version: 7.5.4.2 (X86_64) / LibreOffice Community
Build ID: 36ccfdc35048b057fd9854c757a8b67ec53977b6
CPU threads: 8; OS: Windows 10.0 Build 22621; UI render: Skia/Vulkan; VCL: win
Locale: en-US (en_US); UI: en-US
Calc: CL threaded
Comment 6 Stéphane Guillou (stragu) 2023-07-21 10:10:53 UTC
What I see:

1. confirmed with ImageMagick that original extracted attachment contains a PNG file with Geometry: 2x2+0+0
2. In Writer, select Image1 (helpful to use the Navigator for that), context menu > compress > "reduce image resolution" ticked;

Issues:
a) Size fields are populated by 3×3 instead of 2×2
b) Couldn't set target size to 300×300 pixels because changing one field resets the other. This is a gtk3 regression in LO 6.1 and I have just reported it in bug 156411.

I changed to gen VCL to be able to change dimensions:

3. Change dimensions to 300×300, using no interpolation

Issue:
c) Changes the resolution to 30,000 DPI. I can't have 300×300 and 300 DPI.

4. Extract file to inspect resulting PNG

Result:
The file has Geometry: 300x300+0+0

csongor, how did you manage to have 300×300 with 300 DPI in the dialog?

(In reply to csongor from comment #0)
> Moreover, the label of the checkbox should be "Change image resolution to",
> not "Reduce resolution to" because the user can enter larger values as well,
> not just smaller ones.

This is bug 132657.
Comment 7 csongor 2023-07-21 15:31:06 UTC
(In reply to Stéphane Guillou (stragu) from comment #6)

> csongor, how did you manage to have 300×300 with 300 DPI in the dialog?

Well, it surprised me again how weird this behavior is but I was able to reproduce it. 

It seems LO keeps the settings of Width and Height of this dialog throughout a LO restart.

Here is what I am doing:

- click the attachment of this bug 
- click the Open button of the dialog to open the file
- double click on Images/Image1 in the Navigator
- press Shift+F10 to simulate Right-click on the tiny image
- either (press "m") or (select "Compress..." and press Enter). 

Now in my case, the dialog shows 100, 100, 300 and None in the Width, Height, Resolution, Interpolation fields, respectively. I believe the Resolution reflects the actual DPI info of the image but the other three settings remained here from the previous time I used this dialog. Therefore, you also will see 300 in the Resolution field but some random values in the other three. 

- Change Width and Height to 300. It will change the Resolution field as well but don't worry about it. Set Interpolation to None and click OK. 

- Close the document without saving it. Now the document changes are gone but the changes in the dialog are kept.
- Open the file again from the web.
- Go to the Compress Image dialog. It now shows 300, 300, 300, None. The Resolution is 300 because it is the resolution of the image in the file and the other three values remained here from the previous usage. This is what my original screenshot showed in the attachment.

- Don't change anyhthing just press OK. I would expect to set Height and Width to 300 (because this was in the dialog) or not changing anything (because we didn't modify anything) but the Actual Dimension changes to 3x3 instead. The Width and Height show 300 becasue it is the value we used the last time. But the actual image size is 3x3, not 300x300.

So, in a nutshell, the problem is that the Width and Height fields are not populated with the current dimensions. Instead, the most recently used values are shown. I believe if they would be pre-filled properly, there would be much less confusion. 

There is some other issue as well because if the dialog opens with 300, 300, 300 and I change resolution to 200 and back to 300 then the dimensions change from 300 to 2 and 3, not 200 and 300. So, the link between the fields doesn't work correctly either.

I hope this helped.
Comment 8 QA Administrators 2023-07-22 03:18:13 UTC Comment hidden (obsolete)
Comment 9 Dieter 2023-07-25 14:31:16 UTC
My steps:
1. Open attachment 186979 [details]
2. Open navigator in sidebar and double click on "Image1"
3. Shift+F10 to open context menu
4. Select Compress
5. Dialog shows Heigt 3 | Width 3 | Resolution 300 | Interpolation Lanczos
6. Change Width and Height to 300. Set Interpolation to None and click OK
7. Close the document without saving
8. Open attachment 186979 [details] again
9. Go to the Compress Image dialog. It shows Height 3 | Width 3 | Resolution 300 | Interpolation None

So in sum: Can't confirm the problem and don't see a bug here.

Version: 7.6.0.1 (X86_64) / LibreOffice Community
Build ID: 776eaf34564cbf3f034a0ba1fd1d5c32ff9ccf1c
CPU threads: 4; OS: Windows 10.0 Build 19045; UI render: Skia/Raster; VCL: win
Locale: de-DE (de_DE); UI: en-GB
Calc: CL threaded
Comment 10 csongor 2023-07-27 14:05:51 UTC
Thank (In reply to Dieter from comment #9)

> So in sum: Can't confirm the problem and don't see a bug here.
> 
> Version: 7.6.0.1 (X86_64) / LibreOffice Community
> Build ID: 776eaf34564cbf3f034a0ba1fd1d5c32ff9ccf1c
> CPU threads: 4; OS: Windows 10.0 Build 19045; UI render: Skia/Raster; VCL:
> win
> Locale: de-DE (de_DE); UI: en-GB
> Calc: CL threaded

Thank you, Dieter, probably because you are using a pre-release new version that already fixed the bug. 

I installed LO 7.6.0.1 and it seems to be working fine, they have fixed it. Thank you.
Comment 11 Dieter 2023-07-27 14:36:59 UTC
(In reply to csongor from comment #10)
> I installed LO 7.6.0.1 and it seems to be working fine, they have fixed it.
> Thank you.

=> RESOLVED WORKSFORME
Comment 12 Stéphane Guillou (stragu) 2023-07-27 14:57:29 UTC
Thank you both!