After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 791274 - Animate updates to the crop rectangle due to preset changes
Animate updates to the crop rectangle due to preset changes
Status: RESOLVED FIXED
Product: gnome-photos
Classification: Applications
Component: general
unspecified
Other All
: Normal enhancement
: ---
Assigned To: GNOME photos maintainer(s)
GNOME photos maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2017-12-05 16:41 UTC by Debarshi Ray
Modified: 2018-01-11 09:22 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add PhotosToolCropHelper (6.49 KB, patch)
2017-12-28 09:16 UTC, Umang Jain
committed Details | Review
tool-crop: Animate changes to orientation of crop rectangle (4.68 KB, patch)
2017-12-28 09:18 UTC, Umang Jain
none Details | Review
tool-crop: Separate callbacks for orientation toggle buttons (3.94 KB, patch)
2018-01-05 01:06 UTC, Umang Jain
committed Details | Review
tool-crop: Animate crop rectangle when preset is changed (6.88 KB, patch)
2018-01-05 01:08 UTC, Umang Jain
none Details | Review
tool-crop: Animate crop rectangle when preset is changed (6.64 KB, patch)
2018-01-05 10:45 UTC, Umang Jain
committed Details | Review
tool-crop: Don't update the orientation twice when toggled (4.32 KB, patch)
2018-01-11 09:19 UTC, Debarshi Ray
committed Details | Review
tool-crop: Decouple surface creation and zoomed bbox calculation (3.56 KB, patch)
2018-01-11 09:20 UTC, Debarshi Ray
committed Details | Review
tool-crop: Decouple crop rectangle updates from drawing (6.67 KB, patch)
2018-01-11 09:21 UTC, Debarshi Ray
committed Details | Review
Add PhotosToolCropHelper (11.52 KB, patch)
2018-01-11 09:21 UTC, Debarshi Ray
committed Details | Review
tool-crop: Animate updates to the crop rectangle due to preset changes (13.03 KB, patch)
2018-01-11 09:22 UTC, Debarshi Ray
committed Details | Review

Description Debarshi Ray 2017-12-05 16:41:02 UTC
In bug 781134, we added support for changing the orientation of the crop rectangle. It will be a nice improvement if the change is animated as opposed to jumping from landscape to portrait or vice versa.

EggAnimation will help us here.
Comment 1 Umang Jain 2017-12-28 09:16:24 UTC
Created attachment 366039 [details] [review]
Add PhotosToolCropHelper
Comment 2 Umang Jain 2017-12-28 09:18:30 UTC
Created attachment 366040 [details] [review]
tool-crop: Animate changes to orientation of crop rectangle
Comment 3 Debarshi Ray 2018-01-02 14:43:46 UTC
Review of attachment 366040 [details] [review]:

This looks really nice!

One overall comment: I think that we should differentiate between the co-ordinates that are actually used to draw the crop rectangle (eg., in photos_tool_crop_surface_draw), and the ones that are passed to gegl:crop (through g_action_activate).

The former is meant for drawing the intermediate stages of the animation. However, if g_action_activate is invoked in the middle of an ongoing animation (it's unlikely, but still), then we shouldn't be using the intermediate rectangles to crop the image. The image should always be cropped with the "final" co-ordinates.

You'll see a similar distinction in ImageView. See photos_image_view_set_best_fit and photos_image_view_set_zoom. The best-fit and zoom values exposed through ImageView's public API are always the "final" values. The intermediate values used to drive the animation (ie. the *_visible values) are kept private and only used for drawing.

::: src/photos-tool-crop.c
@@ +861,3 @@
+  /* We might decide to animate every crop preset change in future.
+   * But for now, stick to only orientation changes.
+   */

That's a good idea! We can do it in this patch itself. :)
Comment 4 Umang Jain 2018-01-05 01:06:32 UTC
Created attachment 366343 [details] [review]
tool-crop: Separate callbacks for orientation toggle buttons

Change in orientation fires the same callback twice, which starts and
stops the animation immediately. Separating the callbacks helps to
simplify that problem in following commits.
Comment 5 Umang Jain 2018-01-05 01:08:01 UTC
Created attachment 366344 [details] [review]
tool-crop: Animate crop rectangle when preset is changed
Comment 6 Umang Jain 2018-01-05 10:45:35 UTC
Created attachment 366369 [details] [review]
tool-crop: Animate crop rectangle when preset is changed

Fixed a small visual glitch
Comment 7 Debarshi Ray 2018-01-10 13:07:07 UTC
Review of attachment 366039 [details] [review]:

::: src/photos-tool-crop-helper.c
@@ +101,3 @@
+                                                        "aspect_ratio",
+                                                        "Crop aspect ratio",
+                                                        -G_MAXDOUBLE,

Nitpick: aspect ratio values can never be negative. Zero is probably a better minimum, even though it's unlikely to ever actually be zero.
Comment 8 Debarshi Ray 2018-01-11 08:48:50 UTC
(In reply to Debarshi Ray from comment #7)
> Review of attachment 366039 [details] [review] [review]:
> 
> ::: src/photos-tool-crop-helper.c
> @@ +101,3 @@
> +                                                        "aspect_ratio",
> +                                                        "Crop aspect ratio",
> +                                                        -G_MAXDOUBLE,
> 
> Nitpick: aspect ratio values can never be negative. Zero is probably a
> better minimum, even though it's unlikely to ever actually be zero.

Oops! I forgot that the absence of an aspect ratio constraint is represented by -1.0.
Comment 9 Debarshi Ray 2018-01-11 09:17:36 UTC
Review of attachment 366369 [details] [review]:

::: src/photos-tool-crop.c
@@ +328,3 @@
 
+  self->crop_height = sqrt (old_area / self->crop_aspect_ratio_visible);
+  self->crop_width = sqrt (old_area * self->crop_aspect_ratio_visible);

It's not enough to only have a *_visible counterpart of self->crop_aspect_ratio. We need to do the same for the size and position of the crop rectangle.

What we really want is to differentiate between the co-ordinates that are actually used to draw the crop rectangle (eg., in photos_tool_crop_surface_draw), and the ones that are passed to gegl:crop (through g_action_activate).

While the aspect ratio constraint, if any, influences changes to the crop rectangle, it is not the value that's ultimately used for drawing or cropping the image. With this patch, while the final and intermediate aspect ratio values remain separate, the size and position of the crop rectangle don't. So, if g_action_activate is invoked in the middle of an ongoing animation (it's unlikely, but still), then we would end up using the intermediate rectangles to crop the image, and not the final co-ordinates.

Once you follow this train of thought to its logical conclusion, you'll realize that we can also directly animate the (x, y, width, height) of the crop rectangle instead of the aspect ratio. That would require us to animate four properties instead of one, which implies a bit more boiler plate in ToolCropHelper, but we can avoid some arithmetic on each frame because we already know what the  final values of (x, y, width, height) should be, and we won't need a *_visible counterpart of self->crop_aspect_ratio any more.

@@ +933,3 @@
+
+  if (self->active_changed_animation != NULL)
+    egg_animation_stop (self->active_changed_animation);

We should also stop the animation when:

(a) The size of the underlying ImageView changes. This can happen if the window is resized in the middle of an animation.

(b) Deactivating the tool.

(c) If someone tries to resize or move the crop rectangle in the middle of an animation.

All these cases are unlikely unless someone is using EGG_ANIMATION_SLOW_DOWN_FACTOR, but would be good to address to avoid weird corner cases.

@@ +942,3 @@
 photos_tool_crop_landscape_button_toggled (PhotosToolCrop *self)
 {
+  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->landscape_button)))

Nitpick: Just this part, that avoids updating the constraint twice, could also be part of the patch where you split the callbacks because it is a good thing on its own.
Comment 10 Debarshi Ray 2018-01-11 09:19:45 UTC
Created attachment 366638 [details] [review]
tool-crop: Don't update the orientation twice when toggled

I took the liberty to make the above adjustments and pushed to master.
Comment 11 Debarshi Ray 2018-01-11 09:20:21 UTC
Created attachment 366639 [details] [review]
tool-crop: Decouple surface creation and zoomed bbox calculation
Comment 12 Debarshi Ray 2018-01-11 09:21:00 UTC
Created attachment 366640 [details] [review]
tool-crop: Decouple crop rectangle updates from drawing
Comment 13 Debarshi Ray 2018-01-11 09:21:37 UTC
Created attachment 366641 [details] [review]
Add PhotosToolCropHelper
Comment 14 Debarshi Ray 2018-01-11 09:22:14 UTC
Created attachment 366642 [details] [review]
tool-crop: Animate updates to the crop rectangle due to preset changes
Comment 15 Debarshi Ray 2018-01-11 09:22:30 UTC
Thanks for working on this!