8000 Calculate scale for width and height separately when exporting by asmartin · Pull Request #18784 · darktable-org/darktable · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Calculate scale for width and height separately when exporting #18784

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

Closed
wants to merge 1 commit into from

Conversation

asmartin
Copy link

As described in #18781, it's possible that the exact decimal value of the width scale and height scale can differ, for example:

  • width: 0.957844849089549
  • height: 0.957871396895787

By just taking the min() of these two values and using it for both dimensions, we can arrive at the incorrect scaled value for one of them. Instead, calculate the exact scale value for each dimension separately so we do not lose this precision.

…ure exactly correct value is used for each
@jenshannoschwalm
Copy link
Collaborator
  1. just tested your code, seems good to me too but we will get some export differences :-)

  2. Also see Better calculation of cropped UI output dimension #18785 - i couldn't get any wrong export size with that one

Copy link
Member
@TurboGit TurboGit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is wrong, if you export with max size 2048x2048 you'll get a corrupt image having a size of 2048x2048 which is wrong. The output is:

Note that in darktable when you set export size to 2048 x 2048 (for example) it means that the larger side will get 2048 and the other will be scaled to keep the aspect ratio of the original image.

@darktable-org darktable-org deleted a comment May 10, 2025
@jenshannoschwalm
Copy link
Collaborator

Indeed it fails for setting dimensions.

Please check again if the issue is really persisting after latest commits and re-setting the "crops" in gui. -d pipe -d imageio for me all report "correct" sizes - reported size == size-of-file.

This all has a long story, 4f84542 as a reference to start from.

@asmartin
Copy link
Author

Unfortunately I can still reproduce it even after pulling from master. I reset the crop module back to defaults, then selected 16x9 again and re-cropped the image. After doing so, I exported it at 3840x2160 but it still cut off a single pixel:

[dt_imageio_export] export imgid 1, 6014x3382 --> 3840x2159 (scale=0.6385, maxscale=1.0000). upscale=no, hq=no

This PR is wrong, if you export with max size 2048x2048 you'll get a corrupt image having a size of 2048x2048 which is wrong.

Should this separate scale for each dimension only be calculated if the max size is greater than the specified output dimensions? Or what would you recommend?

@jenshannoschwalm
Copy link
Collaborator

I really think you are looking at the wrong code part.

For me the problem is: What dimension/ratio do we get while cropping? You cropped to 6014x3382 which can't be downscaled to a precise 16/9 ratio. So we loose one line here.

How to solve this? To me it seems we can either

  1. make sure we crop to dimensions being exact multiples of the ratio coeffs.
  2. report an in-exact dimension
  3. Add a button to the crop module crop to exact dimension
    I think both can be done technically, option (1) would then break builds. I would propose (2)
    @TurboGit any favourite?

@TurboGit
Copy link
Member

@jenshannoschwalm : Option 2 is what we have today? But you propose to display a log message, that's it?

I'm not for option 3. Let's not add another button. Maybe 1 is the best, no? I mean at least you get the dimension you asked and even if not 100% 16/9 (or whatever) that's close enough.

Frankly I don't have strong opinion and cannot decide just now what the best between 1 or 2. Let's have some more time to think about this.

@jenshannoschwalm
Copy link
Collaborator

Option 2 is what we have today?

Nope. Yes - we now report the correct crop dimension since late commit.

Lets assume a ratio of 16/9 and we now crop to 6014x3382 which is "accepted" but as both - width and height - are not exact multiples of 16 / 9 all later scaling while exporting will possible lead to a line/row missing.

What i would propose is, report the crop dimension (in expose hook) maybe in different colors, lets say in green for an exact match, otherwise as we have it now.

@asmartin
Copy link
Author

While 1) would break builds, this feels like a bug (you asked for 16:9 but didn't actually get 16:9) so it seems okay to fix the bug going forward

@TurboGit
Copy link
Member

I'm not sure that to qualify this as a bug is OK. You asked for 16:9 sure, but the dimension of the image is not 16:9 and for one line of pixel who really cares? Now maybe we can be smarter indeed and do 1 at cropping time. This at least won't break old edits but it will ensure that new ones will get proper dimensions given the specified ratio.

@jenshannoschwalm : Would doing 1 as described here will keep old edits? If so maybe the best option.

@jenshannoschwalm
Copy link
Collaborator
  1. I implemented option (2) to see how/if that works. It's technically ok and reports bad/good clip dimensions but the UI is a bit tricky as you have to try and change until you get a perfect dimension match.
  2. We can do option (1) - it would require a version bump having a flag new-edit which is set if some UI change happens. There is yet one downside. If we automatically crop to a perfect dimension match depending on the selected ratio we will very likely loose some lines/rows. So if fully zoomed in the visualized crop border won't be exact any more.

How to proceed?

@TurboGit

  1. i could do a not-to-be-merged PR with option (2) to test and evaluate. Leaving out the UI experience it would mean: we don't break edits and have all functionality as we have now.
  2. If you would prefer me to implement option (1) i will have a free time-slot next weekend

@TurboGit
Copy link
Member

I still think 2 is better, but yes please can you create a draft PR to evaluate 1. TIA.

@jenshannoschwalm
Copy link
Collaborator

@TurboGit i got it working :-) This means

  1. When we set a ratio in crop module like 10:8 the exported image will always have dimensions being multiples of of 10 resp 8. Landscapes will have n*10 x n*8, Portraits n*8 x n*10 ...
  2. The export dimension is shown in the crop UI while changing crops or dragging the "area".
  3. The new "restrict to match" is only done after at least on crop parameter has changed to keep old edits.

There are a few questions remaining before doing the PR

  1. If we set the ratio to 16:10 as one example, should we crop to multiples of 16 x 10 or 8 x 5 ?
  2. Would we want to give a hint in the crop UI for a "perfect match" while changing the size or is the export dimension sufficient?

@TurboGit
Copy link
Member

@jenshannoschwalm : I would say:

  1. 8 x 5
  2. No sure, it sounds like the export dimension is sufficient to me for now and we could revisit that after testing.

@asmartin
Copy link
Author

@jenshannoschwalm I tested out your PR and it appears to fix the issue for me; thank you!

@asmartin asmartin closed this May 17, 2025
@asmartin asmartin deleted the 18781 branch May 17, 2025 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0