Auto Crop removes part of the image

Bug #1191390 reported by Nichole Ober
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Pinta
Fix Released
Medium
Unassigned

Bug Description

Using the Auto Crop tool under image removes too much of the image. This is very noticeable when using the tool when there's nothing to crop. Instead of leaving the canvas alone, the left, bottom, and right pixels will get cut off by 1 pixel. If the tool is used repeatedly, the image will eventually shrink to nothing. The program will also completely crash if the canvas gets re sized too small, showing a box with no text or buttons, then terminating completely.

The best way to test this is to open any image and hold the key combo for auto crop (ctrl + alt + x).

The code for autocrop can be found in Pinta.Core/Actions/ImageActions.cs on line 191. It seems like an easy fix.

Changed in pinta:
importance: Undecided → Medium
status: New → Confirmed
Revision history for this message
grofaty (grofaty) wrote :

I managed to reproduce the crash on master on Windows XP:
1. New image.
2. Pencil from Tools and on canvas just click to create one dot.
3. Image | Auto crop and crash appears with the following error:
=============
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.DivideByZeroException: Attempted to divide by zero.
   at Pinta.Core.DocumentWorkspace.set_Scale(Double value) in c:\Zaloga\Pinta-master\Pinta.Core\Classes\DocumentWorkspace.cs:line 100
   at Pinta.Core.ImageActions.CropImageToRectangle(Document doc, Rectangle rect) in c:\Zaloga\Pinta-master\Pinta.Core\Actions\ImageActions.cs:line 286
   at Pinta.Core.ImageActions.HandlePintaCoreActionsImageAutoCropActivated(Object sender, EventArgs e) in c:\Zaloga\Pinta-master\Pinta.Core\Actions\ImageActions.cs:line 268
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
   at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   at System.Delegate.DynamicInvokeImpl(Object[] args)
  at GLib.Signal.ClosureInvokedCB(Object o, ClosureInvokedArgs args)
   at GLib.SignalClosure.Invoke(ClosureInvokedArgs args)
   at GLib.SignalClosure.MarshalCallback(IntPtr raw_closure, IntPtr return_val, UInt32 n_param_vals, IntPtr param_values, IntPtr invocation_hint, IntPtr marshal_data)
=============

P.S. I am removing easy-to-fix tag. This code requires some knowledge how auto crop works and easy-to-fix is tag for total beginners.

tags: added: crop-tool
removed: crop easy-to-fix tools
tags: added: auto-crop-tool
removed: crop-tool
Revision history for this message
Nichole Ober (nicholeober) wrote :

Fair enough. I put easy-to-fix because no knowledge specific to pinta seems to be needed (just some miscalculated for loops that need fixing).

Honestly, I'll give this a go. If I can't fix it in a week from now, I'll un-assign myself. I assume I just branch and push like it says here? `https://code.launchpad.net/pinta`

Changed in pinta:
assignee: nobody → Nichole Ober (nicholeober)
Revision history for this message
Cameron White (cameronwhite91) wrote :

All of the development for Pinta is done on Github (see http://pinta-project.com/contribute.ashx for instructions). Launchpad automatically imports the code from Github, but we only use that for setting up the daily builds PPA.

Changed in pinta:
assignee: Nichole Ober (nicholeober) → nobody
Revision history for this message
Nico (nicohood) wrote :

This bug is still in 1.7 and also in the current 1.8 master.

Steps to reproduce:
1. Create a new image
2. Fill the image with color red
3. Expand canvas size by 2px on each side
4. Fill the new border with blue
5. Expand canvas to something larger
6. autocrop

For me only the bottom and the right side is cut off by 1 px.

Revision history for this message
Cameron White (cameronwhite91) wrote :

Fixed by https://github.com/PintaProject/Pinta/commit/971230537432fdf0ba2d2f99fddc4fdc9017b905
I couldn't repro the issues with cropping an empty image, but this should resolve the off by one error

Changed in pinta:
milestone: none → 1.8
status: Confirmed → Fix Committed
Changed in pinta:
milestone: 1.8 → 1.7.1
Changed in pinta:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.