aboutsummaryrefslogtreecommitdiff
path: root/fiv-jpegcrop.c
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2022-02-19 23:03:49 +0100
committerPřemysl Eric Janouch <p@janouch.name>2022-02-19 23:04:12 +0100
commit2a73e463151f4105fe60730c9163af305c30ca87 (patch)
tree847687c7208fb1a90b60d651c67b5609685c1259 /fiv-jpegcrop.c
parenta68a73cf5c3cf652c1d30c5948cb7040e60d5f5e (diff)
downloadfiv-2a73e463151f4105fe60730c9163af305c30ca87.tar.gz
fiv-2a73e463151f4105fe60730c9163af305c30ca87.tar.xz
fiv-2a73e463151f4105fe60730c9163af305c30ca87.zip
fiv-jpegcrop: avoid negatively sized crop regions
Diffstat (limited to 'fiv-jpegcrop.c')
-rw-r--r--fiv-jpegcrop.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/fiv-jpegcrop.c b/fiv-jpegcrop.c
index 4cf9d64..4bbcd97 100644
--- a/fiv-jpegcrop.c
+++ b/fiv-jpegcrop.c
@@ -214,13 +214,14 @@ on_mouse(guint state, guint button, gdouble x, gdouble y)
switch (button) {
case GDK_BUTTON_PRIMARY:
- g.left = MAX(0, (int) (x - 1)) / g.mcu_width * g.mcu_width;
- g.top = MAX(0, (int) (y - 1)) / g.mcu_height * g.mcu_height;
+ g.left = CLAMP((int) (x - 1), 0, g.right) / g.mcu_width * g.mcu_width;
+ g.top = CLAMP((int) (y - 1), 0, g.bottom) / g.mcu_height * g.mcu_height;
update();
return TRUE;
case GDK_BUTTON_SECONDARY:
- g.right = MIN(x, g.width); // Inclusive of pointer position.
- g.bottom = MIN(y, g.height); // Inclusive of pointer position.
+ // Inclusive of pointer position.
+ g.right = CLAMP(x, g.left, g.width);
+ g.bottom = CLAMP(y, g.top, g.height);
update();
return TRUE;
default: