GNOME Bugzilla – Bug 764614
Add "smooth" mode to "Select -> Border"
Last modified: 2016-05-09 21:43:31 UTC
Created attachment 325383 [details] Comparison of the different border styles As mentioned on IRC, we can get better-quality borders for selections by shrinking and growing the selection, and subtracting the shrunk selection from the grown selection. This maintains antialiasing, and, more generally, better handles partial (i.e., non full-intensity) selections, as shown in the attached image. This patch set replaces the "Feather border" toggle in the "Border Selection" dialog with a "Border style" combo, having three options: "Hard", "Smooth", and "Feathered". "Hard" and "Feathered" correspond to the current behavior, with and without feathering, respectively; "Smooth" does what's described above, and is the default. The `gimp-selection-border` procedure was hard coded to use a feathered border. The last patch changes it to use the "Smooth" mode, which is probably more appropriate. The fourth patch fixes a minor bug.
Created attachment 325384 [details] [review] 0001-app-Add-GimpChannelBorderStyle-enum.patch
Created attachment 325385 [details] [review] 0002-app-Modify-gimp_gegl_apply_border-to-take-a-style-pa.patch
Created attachment 325386 [details] [review] 0003-app-pdb-Modify-gimp_channel_border-to-take-a-style-p.patch
Created attachment 325387 [details] [review] 0004-app-Handle-zero-radius-in-gimp_channel_border.patch
Created attachment 325388 [details] [review] 0005-app-Add-Border-style-combo-to-the-Select-Border.-dia.patch
Created attachment 325389 [details] [review] 0006-pdb-Modify-gimp-selection-border-to-use-BORDER_STYLE.patch
Note that the current border-width behavior (which the patches maintain) is slightly inconsistent. In the general case, the border width is 2r+1 pixels, where r is the radius in the corresponding direction: one pixel at the "center" of the border, and r pixels on each side. However, when, and only when, radius_x = radius_y = 1, the border width is just 1 pixel, instead of 3. That is, when you type 1 in the entry box, you get a 1-pixel wide border, and when you type 2, you get a 5-pixel wide border; there's no way to get a 3-pixel wide border. This is caused by an optimization in the border operation, specifically for this case (app/operations/gimpoperationborder.c:366). I can't tell if this behavior is intentional, or an artifact of the optimization. Either way, being able to select a 1-pixel border is useful, I'm just not sure the current way the radius maps to the border width is correct. Either a 1-pixel border should be achieved with r=0, or the general case should be 2r-1, instead of 2r+1.
Great :)
Created attachment 325432 [details] [review] 0002-app-Modify-gimp_gegl_apply_border-to-take-a-style-pa.patch Heh, a few bits from a different experiment managed to slip in. Fixed.
Created attachment 325433 [details] [review] 0003-app-pdb-Modify-gimp_channel_border-to-take-a-style-p.patch ditto
Fixed in master: commit 2f96950eaa2cd866a1078b67de2c77f95d947e17 Author: Ell <ell_se@yahoo.com> Date: Mon Apr 4 16:07:06 2016 +0000 pdb: Modify gimp-selection-border to use BORDER_STYLE_SMOOTH instead of BORDER_STYLE_FEATHERD. Changes the behavior of the function, but probably for the better. This, and the previous 5 commits, fix bug 764614. commit 60b31cce0f82f0287271c9b5a2c89629ae277b83 Author: Ell <ell_se@yahoo.com> Date: Mon Apr 4 16:00:07 2016 +0000 app: Add "Border style" combo to the "Select -> Border..." dialog instead of the "Feather border" toggle, and pass the selected style to gimp_channel_border(). The border style defaults to "Smooth", whereas the previous default behavior corresponds to "Hard". commit 8b11a505d95f53aa16045d8f7e42cdf9b5faca4c Author: Ell <ell_se@yahoo.com> Date: Mon Apr 4 17:25:45 2016 +0000 app: Handle zero radius in gimp_channel_border() Can only be triggered through PDB. Currently assigns illegal values to the GEGL ops' properties. commit 15d4908076dcea5860f19099d907f0a0048e4aec Author: Ell <ell_se@yahoo.com> Date: Mon Apr 4 15:49:12 2016 +0000 app, pdb: Modify gimp_channel_border() to take a style parameter isntead of the feather parameter, and pass it to gimp_gegl_apply_border(). Make the necessary changes to the rest of the code to maintain the current behavior. Mass parameter alignment changes to gimpchannel.h. Sigh #2... commit 45efe6c405345921f1cef33ffb779cf939c0ae07 Author: Ell <ell_se@yahoo.com> Date: Mon Apr 4 15:11:05 2016 +0000 app: Modify gimp_gegl_apply_border() to take a style parameter instead of the feather parameter. The BORDER_STYLE_HARD and BORDER_STYLE_FEATHERED styles are implemented using the "gimp:border" operation, as was done previously. The BORDER_STYLE_SMOOTH style is implemented by performing a "gimp:grow" and a "gimp:shrink", and subtracting the shrunk image from the grown image using "gegl:substract". gimp_channel_border() is modified to pass either BORDER_STYLE_HARD or BORDER_STYLE_FEATHER, depending on its feather parameter, to maintain the current behavior. The next commit replaces it with a style parameter as well. Mass parameter alignment changes to gimp-gegl-apply-operation.h. Sigh... commit 46a969035358deb8502f2d1c29e4bcb862bf9197 Author: Ell <ell_se@yahoo.com> Date: Mon Apr 4 14:53:56 2016 +0000 app: Add GimpChannelBorderStyle enum Will be used as a parameter to control the behavior of gimp_channel_border(), and the corresponding "Select -> Border..." action, instead of the feather flag. Can be one of: - GIMP_CHANNEL_BORDER_STYLE_HARD: Current behavior, unfeathered. - GIMP_CHANNEL_BORDER_STYLE_SMOOTH: Smooth border, better handling partial selection, implemented as explained in the next commit. - GIMP_CHANNEL_BORDER_STYLE_FEATHERED: Current behavior, feathered.
Great news! It would also be better if we could have a preview of the "Grow" and "Shrink" selection. At the moment it's a blind operation. We have preview for Rectangle and Ellipse selections when you adjust the "Position" and "Size" in the options dialog, which unfortunately don't work for shrinked or grown selections. REF: https://bugzilla.gnome.org/show_bug.cgi?id=755537