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

Simpified resizing in export #368

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AlynxZhou
Copy link

This is based on those 2 rules:

  • Resizing by scaling factor or by max size are independent and select one will cover the other value, because user cannot see both in UI.
  • We don't do upscaling when exporting.

So the actual logic on determine final size is simple:

  1. If user set value <= 0, this means don't resize and use the original image size.
  2. If user set value > original image size, this also means don't resize and use the original image size.
  3. For max size, if user does not set the value according to image ratio, we will recalculate the value to keep image ratio and make sure the calculated size is smaller than user's max size.
  4. If by scaling factor, calculate max size according to scaling factor. If by max size, calculate scaling factor according to max size.
  5. Limit size by max size, and pass correct size and scaling factor to pixelpipe.

Fixes #362.

@AlynxZhou AlynxZhou force-pushed the fix-export branch 3 times, most recently from 5b5d3e7 to de508cc Compare September 26, 2024 07:03
@AlynxZhou
Copy link
Author

Fixed coding style, added missing round().

@AlynxZhou
Copy link
Author

There are mistakes when shrinking user's max size to image ratio, let me fix it.

@AlynxZhou
Copy link
Author

There are mistakes when shrinking user's max size to image ratio, let me fix it.

Fixed, the final output size will always be smaller than user's max size and has the same ratio with the original image.

@Jiyone
Copy link
Collaborator

Jiyone commented Sep 26, 2024

I tried and it works :) 👍🏻

// Keep image ratio even if user does not set max size by ratio.
// We make sure the calculated size will be smaller than user's max size.
if((double)max_width / max_height > image_ratio)
max_width = MIN(round(max_height * image_ratio), max_width);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor, but indentation is wrong here.

Copy link
Author

Choose a reason for hiding this comment

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

That's easy to fix, I want to know whether you think my logic is good for you haha

Copy link
Author

Choose a reason for hiding this comment

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

Do you think we need {} for this if else? I don't find wrong indentation levels.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, maybe it's just a display issue. No big deal.

max_height = MIN(max_height, pipe.processed_height);
// Keep image ratio even if user does not set max size by ratio.
// We make sure the calculated size will be smaller than user's max size.
if((double)max_width / max_height > image_ratio)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think that's enough.

If the target export ratio is different than the theoritical image ratio (after crop, perspective and all distortion modules), you should:

  1. pin the largest picture dimension to the max allowed under current constraints,
  2. define the narrowest picture dimension from the largest and the theoritical image ratio,
  3. update scaling factor using new dimensions.

This logic prevents rounding errors as much as possible when applying the ratio as floating point.

Here, you don't check which dimension is the largest and don't cover the case where max_with / max_height == image_ratio.

int width = 0;
int height = 0;
double _num, _denum;
dt_imageio_resizing_factor_get_and_parsing(&_num, &_denum);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This function is used to parse the user param only when defining export size as a sub-multiple of the original size (aka is_scaling is TRUE, that case is fairly recent and was hacked in-place). It shouldn't be used here in the general, unconditionnal case, especially since it reads a config key that's irrelevant when defining export size by pixel count (or mm/inches).

This is based on those 3 rules:

- Max size is not "max" size acutally but more like "requested" size.
- Resizing by scaling factor or by max size are independent and select
  one will cover the other value, because user cannot see both in UI.
- We don't do upscaling when exporting.

So the actual logic on determine final size is simple:

1. If user sets both dimensions <= 0 (setting scaling factor is also
   setting both dimensions), this means don't resize and use the
   original image size.
2. For max size, if user sets one dimension <= 0, this means calculate
   the other dimension via image ratio.
3. For max size, if user does not set dimensions according to image
   ratio, we match the longest dimension, and calculate the other
   dimension via image ratio.
4. If user sets value > original image size, this also means don't
   resize and use the original image size.
5. If by scaling factor, calculate max size according to scaling factor.
   If by max size, calculate scaling factor according to max size.
6. Limit size by max size, and pass correct size and scaling factor to
   pixelpipe.

Fixes <aurelienpierreeng#362>.
Copy link

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.

Bug: Export produce empty files of 0 byte
3 participants