Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zooming pin in and out does so at different rates #2341

Closed
Semnodime opened this issue Jan 29, 2022 · 10 comments
Closed

Zooming pin in and out does so at different rates #2341

Semnodime opened this issue Jan 29, 2022 · 10 comments
Assignees
Labels
Bug It's a bug Good first issue Issues labeled as such are a good way to get use to the codebase. Ask for help if needed.

Comments

@Semnodime
Copy link

Flameshot Version

v0.10.2 (c4081c6)

Installation Type

AppImage

Operating System type and version

Linux Mint 20.1 Cinnamon

Description

Scrolling in and out in a pin does so at different rates.
Scrolling to make it smaller is faster.

Only happens when the pin has been zoomed quite large already.

Steps to reproduce

  1. Take Screenshot
  2. Pin it
  3. Scroll to make it really big
  4. Scroll to make it a bit smaller again
  5. See error: Sudden jump to be way smaller

Screenshots or screen recordings

None

System Information

s.a.

@Semnodime Semnodime added the Unconfirmed Bug The bug is not confirmed by anyone else. label Jan 29, 2022
@Semnodime Semnodime changed the title Zooming Pin in and out does so at different rates Zooming pin in and out does so at different rates Jan 29, 2022
@borgmanJeremy
Copy link
Contributor

Ha! Good find.

@mmahmoudian
Copy link
Member

mmahmoudian commented Jan 30, 2022

While experimenting with this, I realized you don't need to make the pin very large to get the effect. any pin size would do. To make this extremely reproducible, I wrote the following bash to scroll up and down 5 steps at a time for 10 rounds:

#!/usr/bin/env bash

round = 1

sleep 3s

for i in {1..10}
do
    echo ${i}

    xdotool click --repeat 5 --delay 20 5
    xdotool click --repeat 5 --delay 20 4

    sleep 1s
done

In ideal world the size of the pin image should stay the same after scrolling up and down equal number of times and steps. So I created a large checkerboard pattern using https://eleif.net/checker.html and pinned one area and ran my code:

Peek.2022-01-30.14-53.mp4

Flameshot v11.0.0 (1cc5a26)
Compiled with Qt 5.15.2
linux: 5.15.16-1-MANJARO
manjaro: unknown

@mmahmoudian mmahmoudian added Bug It's a bug and removed Unconfirmed Bug The bug is not confirmed by anyone else. labels Jan 30, 2022
@borgmanJeremy
Copy link
Contributor

@mmahmoudian do you have any fractional scaling?

@mmahmoudian
Copy link
Member

@mmahmoudian do you have any fractional scaling?

No, all monitors are 100%

@borgmanJeremy
Copy link
Contributor

So this is caused by rounding errors in the integer math. When the size is changed we add 15 to the width and the height. Then we ask Qt "please find resize the existing image to the new size while preserving the original aspect ratio". This is a destructive operation in the sense that it is nonlinear. So when you run it in reverse you end up with a different size even if you just increment once and decrement once.

Once solution is to simply add or subtract by a multiple of the GCD, but i dont think this will be nice for very oblong images.

The other solution I can think of is to store the original pixmap and original size. Then each mouse event will increment and decrement a counter. The counter will apply to the original pixmap each time. This will keep the operation linear.

@borgmanJeremy borgmanJeremy added the Good first issue Issues labeled as such are a good way to get use to the codebase. Ask for help if needed. label Jan 30, 2022
@Semnodime
Copy link
Author

@borgmanJeremy I harmonize with the solution of storing a counter: incrementing and decrementing it can easily be made an exact and thus fully reversible operation.


As a second remark:
While not having looked into the code, the current difference appears to be quite large to be related to rounding errors only and thus reminds me of a common error when dealing with fractional units:
IMHO, it is not too unlikely, that reversing an zoom-in operation (like adding 15% to 100 --> 115) has been implemented simply by subtracting the previous fraction (remove 15% from 115 --> 97.75), irrespective of the new (and larger) reference.
Zooming in and out once will lead to an image that is actually 3.75% smaller than the original. Doing so repeatedly, and the image will obviously shrink approaching zero area.

@borgmanJeremy
Copy link
Contributor

@Semnodime My first guess was that it was related to adding and removing percentages, but its actually not using percentages.

void PinWidget::wheelEvent(QWheelEvent* e)

I'll get to this in a few days if no one else does. I want to leave it open for new contributors for a few days since it should be straightforward.

@AndreaMarangoni
Copy link
Contributor

I'll take a look at this if you don't mind @borgmanJeremy

@borgmanJeremy
Copy link
Contributor

@AndreaMarangoni sure, thanks!

@AndreaMarangoni
Copy link
Contributor

AndreaMarangoni commented Feb 6, 2022

PR #2378
@Semnodime if you could test my PR that would be great!

On the other hand, on Linux, I have noticed that the zooming in/out of the pinned screenshot sometimes jumps position on the screen. It looks like the position of the mouse cursor has something to do with this behaviour, but not sure yet. If I can reproduce it I will raise a ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug It's a bug Good first issue Issues labeled as such are a good way to get use to the codebase. Ask for help if needed.
Projects
None yet
Development

No branches or pull requests

4 participants