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 520078 - Rotate brushes
Rotate brushes
Status: RESOLVED FIXED
Product: GIMP
Classification: Other
Component: Tools
2.4.x
Other All
: Normal enhancement
: 2.8
Assigned To: Alexia Death
GIMP Bugs
: 323923 522705 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2008-03-03 12:19 UTC by Sven Anders
Modified: 2009-08-23 16:17 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Rename all scale related infrastructure to transform (20.95 KB, patch)
2009-01-31 22:31 UTC, Alexia Death
committed Details | Review
Very basic rotatio patch (27.06 KB, patch)
2009-02-02 08:16 UTC, Alexia Death
needs-work Details | Review
Brush rotation with full integration (55.65 KB, patch)
2009-02-04 20:38 UTC, Alexia Death
none Details | Review
Brush rotation with full integration 2 (57.76 KB, patch)
2009-02-05 17:50 UTC, Alexia Death
committed Details | Review
Fix to make rotation roll over when shortcuts are used. (519 bytes, patch)
2009-02-06 14:08 UTC, Alexia Death
committed Details | Review
Direction dynamic. Makes it possible to make the brush follow the direction of the stroke. (43.43 KB, patch)
2009-02-07 23:03 UTC, Alexia Death
committed Details | Review
Patch to change the action steppings as proposed (559 bytes, patch)
2009-02-08 22:36 UTC, Alexia Death
committed Details | Review
Fixes to rotation. (2.82 KB, patch)
2009-02-08 22:37 UTC, Alexia Death
committed Details | Review
Fixes issues fith rotation direction (2.85 KB, patch)
2009-02-10 20:41 UTC, Alexia Death
committed Details | Review
Fix bug accidentaly introduced with last patch. (505 bytes, patch)
2009-02-11 18:43 UTC, Alexia Death
committed Details | Review
More fixes to rotation (5.25 KB, patch)
2009-02-14 13:11 UTC, Alexia Death
committed Details | Review
efficient bilinear interpolation of transformed brushes (19.19 KB, patch)
2009-02-27 20:29 UTC, Tal
committed Details | Review
Bilinear algorithm accuracy boost and brush_transform_matrix bugfix (2.43 KB, patch)
2009-03-02 07:31 UTC, Tal
committed Details | Review

Description Sven Anders 2008-03-03 12:19:21 UTC
Add possibility (slider) to rotate brush when using

Possibly:

- Add auto-rotate mode, which rotates the brush by xx degrees while painting
- Add rotating depending on pencils pressure
Comment 1 Sven Neumann 2008-03-03 12:50:22 UTC
Sven, can you please stop opening enhancement requests in our bug-tracker without prior discussion on the gimp-developer mailing-list. Thanks.
Comment 2 Sven Anders 2008-03-03 13:11:32 UTC
This was my last one.
In the past few days I used GIMP frequently and I didn't want these ideas to
be lost.

I look, if I found any of these in the Bugtracker, but I didn't found
any with the keywords I used. So sorry for the duplicates.

With other projects we use the bugtracker for discussion too, so I wasn't aware of this policy...
Comment 3 Sven Neumann 2008-03-04 19:17:52 UTC
Doesn't look like Sven will open a discussion on the mailing-list, so let's reopen this one.
Comment 4 Sven Neumann 2008-03-17 07:49:57 UTC
*** Bug 522705 has been marked as a duplicate of this bug. ***
Comment 5 Sven Neumann 2008-03-18 07:52:39 UTC
In case someone wants to start working on this, here's a rough outline
of what needs to be done:

(1) Rename the scale() method of GimpBrush to transform().
(2) Add an angle parameter to the transform method.
(3) Implement the rotation for all derived brush classes.
    The difficult part is to do the rotation, efficiently,
    for pixmap brushes.

When we are this far, we can start to consider how the angle should be
controlled by the user. As a start one would add methods to GimpContext
to rotate the current brush so that keyboard shortcuts can be added for
this. Later we can add more sophisticated things then.

The next logical step after adding rotation would be to change the
GimpBrush::transform method to take a GimpMatrix3 parameter and to allow
for arbitrary affine transformations (that includes shearing). I am sure
that there is some efficient code for this out there that we could
use...
Comment 6 tobias 2008-10-09 17:56:56 UTC
Isn't this a duplicate of Bug 323923 ?
Comment 7 Sven Neumann 2008-10-09 18:39:41 UTC
Yes, but this report has a better description of what needs to be done in order to implement this.
Comment 8 Sven Neumann 2008-10-09 18:40:02 UTC
*** Bug 323923 has been marked as a duplicate of this bug. ***
Comment 9 Alexia Death 2009-01-22 13:14:21 UTC
Assigning it to myself but with future milestone. I will be looking into it.
Comment 10 Alexia Death 2009-01-31 22:31:35 UTC
Created attachment 127670 [details] [review]
Rename all scale related infrastructure to transform

Preparations for adding more transforms.
Comment 11 Martin Nordholts 2009-02-01 11:14:36 UTC
Commited after cleanups and file renames to trunk rev 27975:

2009-02-01  Martin Nordholts  <martinn@svn.gnome.org>

	Applied patch from Alexia Death that prepares brushes for
	arbitrary transforms by renaming stuff with 'scale' to
	'transform'. Takes us one step closer to fixing bug #520078.

	* app/core/gimpbrush.[ch]
	* app/core/gimpbrushgenerated.c
	* app/paint/gimpbrushcore.[ch]
	* app/paint/gimpsmudge.c

	* app/core/gimpbrush-transform.[ch]: New names of
	* app/core/gimpbrush-scale.[ch]

	* app/core/Makefile.am: Update.
Comment 12 Alexia Death 2009-02-02 08:16:15 UTC
Created attachment 127752 [details] [review]
Very basic rotatio patch

The infrastructure should be OK, but rhe rotation algorthm is not good. The rotation is linear without any interpolation and thus very ugly... Ideas in that department are very welcome. Dynamics support for rotation is not there and wont be Dynamics rework for both tilt and rotation is IMHO its own chore.
Comment 13 Alexia Death 2009-02-04 20:38:41 UTC
Created attachment 127947 [details] [review]
Brush rotation with full integration

Kudos to Sven for doing the serious bit, where I got stuck :)
Comment 14 Alexia Death 2009-02-05 17:50:10 UTC
Created attachment 128027 [details] [review]
Brush rotation with full integration 2

Angle scale now runs from -180 to 180. Patch format should be different.
Comment 15 Sven Neumann 2009-02-05 21:48:28 UTC
2009-02-05  Sven Neumann  <sven@gimp.org>

	Bug 520078 – Rotate brushes

	Applied patch from Alexia Death:

	* app/core/gimpbrush.[ch]
	* app/core/gimpbrushgenerated.c
	* app/core/gimpbrush-transform.[ch]: affine transformations for
	brushes. So far only scaling and rotation is supported. The
	transformation is done using nearest-neighbour. This is a
	regression and we need to add back interpolation before the next
	release.

	* app/paint/gimpsmudge.c
	* app/paint/gimppaintoptions.[ch]
	* app/paint/gimpbrushcore.[ch]: allow to control the brush
	rotation angle.

	* app/tools/gimppaintoptions-gui.c
	* app/tools/gimpbrushtool.c: added UI for controlling the
	brush rotation angle.

	* app/actions/tools-actions.c
	* app/actions/tools-commands.[ch]: add actions for controlling the
	brush rotation angle.

I guess we should keep this report open until we have looked at the interpolation issue.
Comment 16 Alexia Death 2009-02-06 14:08:44 UTC
Created attachment 128093 [details] [review]
Fix to make rotation roll over when shortcuts are used.
Comment 17 david gowers 2009-02-07 02:17:48 UTC
A minor issue here is the action step size -- it's tiny, even '-skip' variants are extremely slow to change angle. I suggest to use "0.1, 1.0, 15.0" rather than "0.01, 0.1, 1.0", 
Comment 18 Sven Neumann 2009-02-07 21:58:30 UTC
Sounds reasonable to me. Can you make a patch for this change?
Comment 19 Alexia Death 2009-02-07 23:01:05 UTC
I agree. Ill make a patch a little later. first, patch that adds direction dynamic.
Comment 20 Alexia Death 2009-02-07 23:03:01 UTC
Created attachment 128196 [details] [review]
Direction dynamic. Makes it possible to make the brush follow the direction of the stroke.
Comment 21 Michael Natterer 2009-02-08 12:56:05 UTC
Committed the last patch. Alexia, does this count as FIXED now?

2009-02-08  Michael Natterer  <mitch@gimp.org>

	Bug 520078 – Rotate brushes

	Applied a slightly modified patch from Alexia Death:

	* app/core/core-types.h (struct GimpCoords): add "direction" member.

	* app/core/gimpcoords.c: take direction into account in mix(),
	scalarprod(), length_squared(), manhattan_dist() and equal().

	* app/core/gimpcoords-interpolate.c
	(gimp_coords_interpolate_catmull): same here.
	* app/display/gimpdisplayshell-coords.c

	(gimp_display_shell_eval_event): same here.

	* app/paint/gimppaintoptions.[ch]: add properties for direction
	dynamics and adapt dynamics mixing accordingly.

	* app/paint/gimpbrushcore.c (gimp_brush_core_interpolate):
	"interpolate" direction too (in fact, just copy it from
	last_coords since it doesn't change along a straight line).

	* app/paint/gimppaintcore-stroke.c
	(gimp_paint_core_stroke_emulate_dynamics): emulate direction too.

	* app/tools/gimppaintoptions-gui.c: add GUI for direction dynamics.
Comment 22 Alexia Death 2009-02-08 13:15:59 UTC
Id say its fixed, but Sven wanted to look at possible interpolation on transforming the brushes... So I'm not sure.
Comment 23 Sven Neumann 2009-02-08 16:41:35 UTC
Looking at the results of mapping direction to brush rotation, I'd say we still have work to do. There are frequent outliers. Looks like there is more smoothing needed in the direction domain...
Comment 24 Alexia Death 2009-02-08 22:36:12 UTC
Created attachment 128254 [details] [review]
Patch to change the action steppings as proposed
Comment 25 Alexia Death 2009-02-08 22:37:28 UTC
Created attachment 128255 [details] [review]
Fixes to rotation.

fixes (for now) generated brushes rotating the wrong way and adds smooth to direction.
Comment 26 Sven Neumann 2009-02-10 19:45:19 UTC
2009-02-10  Sven Neumann  <sven@gimp.org>

	* app/display/gimpdisplayshell-coords.c
	(gimp_display_shell_eval_event): applied patch from Alexia Death
	that introduces smoothing for the stroke direction (bug #520078).
Comment 27 Sven Neumann 2009-02-10 19:59:53 UTC
I haven't committed the brush direction change in the attached patch because I think this needs to be addressed differently. Let's mark the patch as committed nevertheless...
Comment 28 Alexia Death 2009-02-10 20:41:37 UTC
Created attachment 128411 [details] [review]
Fixes issues fith rotation direction
Comment 29 Sven Neumann 2009-02-10 21:07:45 UTC
2009-02-10  Sven Neumann  <sven@gimp.org>

	* app/core/gimpcoords-interpolate.c
	* app/core/gimpbrush-transform.c
	* app/paint/gimppaintoptions.c
	* app/display/gimpdisplayshell-coords.c: applied patch from Alexia
	Death that fixes the direction of brush rotation (bug #520078).
Comment 30 Michael Natterer 2009-02-10 22:07:11 UTC
test, please ignore.
Comment 31 Alexia Death 2009-02-11 18:43:42 UTC
Created attachment 128486 [details] [review]
Fix bug accidentaly introduced with last patch.
Comment 32 Alexia Death 2009-02-14 13:11:36 UTC
Created attachment 128712 [details] [review]
More fixes to rotation

All the obvious quirks should be out now.
Comment 33 Sven Neumann 2009-02-14 13:37:09 UTC
Committed with some coding style cleanups:

2009-02-14  Sven Neumann  <sven@gimp.org>

	* app/core/gimpcoords-interpolate.c
	* app/display/gimpdisplayshell-coords.c: applied patch from Alexia
	Death that fixes issues with the new stroke direction code
	(bug #520078).
Comment 34 Alexia Death 2009-02-14 21:07:37 UTC
closing as fixed. Feature is there now and looks stable enough.
Comment 35 Sven Neumann 2009-02-14 22:25:58 UTC
We still have a regression here. The brush transform code is really just a placeholder as it is now. It doesn't perform any interpolation.
Comment 36 david gowers 2009-02-14 23:23:38 UTC
yes, and that lack of interpolation means that the fix for bug #548631 has become ineffective (since scale < 1.0 with a 1-pixel brush already makes the result disappear). I would reopen it, however I think the problem would be properly addressed by the interpolation required here.
Comment 37 Tal 2009-02-27 20:29:48 UTC
Created attachment 129686 [details] [review]
efficient bilinear interpolation of transformed brushes

I have a feeling the speed could still be improved somehow, so any performance gurus looking for a challenge are welcome to give it a go.
Comment 38 david gowers 2009-02-27 21:21:22 UTC
This patch works for most brushes, but very small brushes (1xNpx or Nx1px) it doesn't work at all on (any brush scale other than 1.00 causes the brush to become completely empty/transparent). I think you may need to special case that.
Comment 39 Sven Neumann 2009-02-27 21:48:35 UTC
Might make sense to add specific algorithms for these corner cases (just one src row or just one src column). That code should be significantly less complex and it would not hurt performance of the general case.

Without having tried it, the patch looks good otherwise. Tal, would you prefer that we commit this patch and you continue to work on it based on that version or would you prefer to attach an updated patch that addresses the problem outlined in comment #38?
Comment 40 Tal 2009-02-28 00:08:14 UTC
Sven, I prefer we commit the patch now and then continue working on it based on that version.

I need to think carefully about how to implement special algorithms for the 1x1, 1xN and Nx1 source cases.

David, I will try to see what could be causing the issue you mentioned in #38.
Comment 41 david gowers 2009-02-28 02:09:49 UTC
Attn Alexia: 
Related to the polishing of the rotation interface, mapping Direction to Color doesn't work correctly. Half of the possible directions map to a range of the gradient, and the other half map to that same range. This is easily detectable when you reset colors to default, select 'FG to BG (RGB)' gradient, and draw using that with Pencil or Paintbrush.
We might also need to review other Direction mappings. IMO Direction -> Hardness is also dubious, and Direction -> Size is definitely wrong (jumps from small -> large after a certain angle ,about the same angle as the split that occurs with mapping to Color). Direction -> Opacity looks correct though :)

Re: comment #16

Something weird is happening, which means that only backward wrapping (eg. -180 becomes +165) works correctly. Try using shortcuts to move past +180 to -165, nothing happens.


Comment 42 Sven Neumann 2009-02-28 13:07:34 UTC
There is also a problem with this code when rotating a square brush. There are edges cropped off in the result. I have committed the patch anyway, in the hope that we can solve the remaining issues together...
Comment 43 Tal 2009-03-02 07:31:50 UTC
Created attachment 129832 [details] [review]
Bilinear algorithm accuracy boost and brush_transform_matrix bugfix

re#42 Boosted fraction accuracy from 8 bits to 12 bits to limit the cropping issue.

re#38 Fixed bug in gimp_brush_transform_matrix (corrected y-translation value). Solves brushes sometimes partially or completely disappearing and possibly other issues. 1xn, nx1 and 1x1 brushes work fine for me apart from issues noted below.

Unresolved issues:

1) At some scales < 1 and for some angles, sometimes brush edges are lost or brushes disappear completely if they are very small already. Possibly due to source image undersampling.

2) At some scales < 1, 1x1 pixel brush will disappear at angles < -90 and >= 90. If a 1x1 pixel brush at scale < 1.0 is special cased to give a 1x1 pixel result, the brush no longer disappears at these angles. However, for scale 1.0 the 1x1 brush appears thinner at these angles compared to the other angles. In particular, at scale 1.0, through angles > -90 and < 90 and at -180 the 1x1 brush appears thicker and may occupy 2x3, 3x2, 1x3, or 3x1 pixels despite the function returning a forced 1x1 pixel result early (prior to the bilinear algorithm processing). To prevent 1x1 pixel brushes scaled < 1.0 appearing thicker than at 1.0 the special case has been commented out in the patch (see gimp_brush_real_transform_mask) but is there so developers can investigate this.

3) Scaling 1xn and nx1 brushes below 0.5 does not make them smaller. Instead, they keep their 0.5 scale size.


Anyone who wishes to solve any of these issues or improve upon the bilinear algorithm presented, please feel free to do so. Issues 2 and 3 may have something to do with infrastructure code.
Comment 44 Alexia Death 2009-03-02 08:53:40 UTC
3) is enforced elsewhere in the code. Making a brush smaller than half a pixel makes little sense anyway.
Comment 45 david gowers 2009-03-09 02:41:59 UTC
With the current state of SVN head, somehow smudge tool ignores brush scale and angle..
So, the brush outline is shown with the scale and angle set in the tool options, but the smudge operation is performed as if brush scale = 1.0 and angle = 0.0.

IMO it's important to fix this before 2.8.


Also, the following tools respect brush scale and angle OK while not supporting 'angle' dynamic mapping, which IMO makes sense for them.

Dodge/Burn
Heal
Clone + perspective-clone
Convolve

This seems relatively simple to implement, perhaps it could be included in the 'brush dynamics' proposed SoC project. Support for Smudge also makes sense but Smudge support could be quite demanding (rotating the smudge buffer as well as the brush mask)
Comment 46 Alexia Death 2009-03-09 07:19:53 UTC
Thank you for the bug finding. I will check out smudge bug later tonight.

Allowing for tools that already respect angle to have angle dynamic is most likely a change of one, perhaps two lines of code. Just enabling the controls is probably all that needs to be done.
Comment 47 Martin Nordholts 2009-07-12 09:47:56 UTC
It would be nice if we could have a real name instead of just "Tal" in athors.xml. Tal, would you mind providing your real name please?
Comment 48 Martin Nordholts 2009-07-19 10:13:49 UTC
Alexia, what is the current state?
Comment 49 Alexia Death 2009-07-19 14:22:04 UTC
There are the corner cases for interpolation Tal worked on still open, the core of the bug report is done tho... So Im not sure if it can be closed or not.
Comment 50 Tal 2009-08-23 13:51:21 UTC
Martin, thanks for adding me to authors.xml. I'm happy to be credited with my real name: Tal Trachtman
Comment 51 Martin Nordholts 2009-08-23 16:15:47 UTC
Ok thanks I've updated your name now

commit 34bccb087617cebb22a0ac6ac31cffde5016de11
Author: Martin Nordholts <martinn@src.gnome.org>

    authors: Tal's real name is Tal Trachtman
Comment 52 Martin Nordholts 2009-08-23 16:17:03 UTC
Since the bulk of this is done now, let's close this as FIXED and handle remaining issues in separate to-the-point bug reports.