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

Crop module gets orientation proxy support #17888

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jenshannoschwalm
Copy link
Collaborator

While developing an image in darkroom we might have set a cropping area, this commit implements functionality to keep the cropped area if we change orientation via the flip module.
Three parts in the codebase required additions without changing existing code so not expecting stability regressions.

  1. dt_develop_t got two additions in cropping proxy, struct dt_iop_module_t *flip_handler points to the crop module and is setup there. We can't use exposer as the proxy because that is dynamically set in pixelpipe code only if enabled and we want to change crop parameters even if currently disabled. void (*flip_callback) is the callback function changing crop parameters, defined in crop.

  2. Orientation module uses the flip_callback(self, orientation) requesting changes in crop.

  3. In crop we have _crop_handle_flip() as proxy flip_callback with proper logs about action.

    • It gets the data from self dt_iop_crop_params_t,
    • does the requested action,
    • sets the crop sliders and soft_min/max
    • adds a new crop history stack entry respecting the current crop->enabled status.

Finally worked on this, various pending issues:
Fixes #17631 #17498 #14788 #11614

@jenshannoschwalm jenshannoschwalm added bugfix pull request fixing a bug feature: enhancement current features to improve scope: image processing correcting pixels documentation-pending a documentation work is required release notes: pending labels Nov 25, 2024
@jenshannoschwalm
Copy link
Collaborator Author

Note: no support for the lighttable "actions on selections" button and not planned from my side.

@TurboGit TurboGit added this to the 5.2 milestone Nov 25, 2024
src/iop/crop.c Outdated Show resolved Hide resolved
src/iop/flip.c Outdated Show resolved Hide resolved
src/iop/crop.c Outdated Show resolved Hide resolved
@jenshannoschwalm jenshannoschwalm removed the bugfix pull request fixing a bug label Nov 26, 2024
We must call gui_changed() at the end of gui_update() to ensure a new history if parameters
changed, UI symptoms possible were subtly wrong slider soft min/max.

While checking some minor cleanup
- g->cropping should be _grab_region_t instead of int and be initialized as that
- deduplicate updating sliders in _update_sliders_and_limit()
src/iop/flip.c Outdated Show resolved Hide resolved
While developing an image in darkroom we might have set a cropping area, this commit
implements functionality to keep the cropped area if we change orientation via the
flip module.
Three parts in the codebase required additions without changing existing code.

1. `dt_develop_t` got two additions in cropping proxy,
   `struct dt_iop_module_t *flip_handler` points to the crop module and is setup there.
      We can't use `exposer` as the proxy because that is dynamically set in pixelpipe code
      only if enabled and we want to change crop parameters even if crop is disabled.
   `void (*flip_callback)` is the callback function changing crop parameters, defined in crop.

2. Orientation module uses the `flip_callback(self, orientation)` requesting changes in crop.

3. In crop we have `_crop_handle_flip()` as proxy `flip_callback` with proper logs about action.
   - It gets the data from self `dt_iop_crop_params_t`,
   - does the requested action,
   - updates gui from parameters
   - adds a new history stack entry (respecting the current `crop->enabled` status).
if(!p) return;

// we avoid action if default or fully symmetrical
const gboolean no_action = (p->cx == 1.f - p->ch) && (p->cy == 1.f - p->cw);
Copy link
Member

Choose a reason for hiding this comment

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

?

This is not testing for "full symmetry". ;-)

Also, some layouts that don't need adjustment under flipping do need to be rotated and vice versa. So if you want to do more than only avoid adjusting no-crops, you'll have to do a full before-after comparison, i.e.

const float ocx = p->cx, ocy = p->cy, ocw = p->cw, och = p->ch;
if(mode == ORIENTATION_FLIP_HORIZONTALLY)        {p->cx = 1.f-ocw; p->cw = 1.f-ocx;}
  else if(mode == ORIENTATION_FLIP_VERTICALLY)   {p->cy = 1.f-och; p->ch = 1.f-ocy;}
  else if(mode == ORIENTATION_ROTATE_CW_90_DEG)  {p->cx = 1.f-och; p->ch =     ocw; p->cw = 1.f-ocy; p->cy =     ocx;}
  else if(mode == ORIENTATION_ROTATE_CCW_90_DEG) {p->cx =     ocy; p->cy = 1.f-ocw; p->cw =     och; p->ch = 1.f-ocx;}

and skip the last two lines if all of p->cx vs ocx etc are sigma close enough (since these are calculated values, rather than constants like 0 or 1, you could get mismatches on 1/4 == 1 - 3/4 if someone types in 25% everywhere).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation-pending a documentation work is required feature: enhancement current features to improve release notes: pending scope: image processing correcting pixels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rotating cropped image moves cropped area
3 participants