Looking for guidance on implementing a plugin
This discussion is connected to the gimp-developer-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.
This is a read-only list on gimpusers.com so this discussion thread is read-only, too.
Looking for guidance on implementing a plugin | Rob Antonishen | 27 May 18:31 |
Looking for guidance on implementing a plugin | saulgoode@flashingtwelve.brickfilms.com | 29 May 06:32 |
Looking for guidance on implementing a plugin | Rob Antonishen | 29 May 15:22 |
AANLkTimTNH7OYlkirdFfi4gzUv... | 07 Oct 20:28 | |
Looking for guidance on implementing a plugin | Rob Antonishen | 28 May 17:03 |
Looking for guidance on implementing a plugin | Burnie West | 28 May 17:25 |
Looking for guidance on implementing a plugin | Bill Skaggs | 29 May 02:27 |
Looking for guidance on implementing a plugin | saulgoode@flashingtwelve.brickfilms.com | 29 May 17:23 |
Looking for guidance on implementing a plugin
Hi-
I am writing a c plugin to scale a layer. (This is much as an exercise for me as anything).
I have looked at a few examples and they handle things differently....
- Create a new image with a new layer the new size
- Create a new layer in the existing image just above the input layer
- Create a new layer in the existing image just above the input layer
and delete the input layer
- Initialize the input pixel region then change the input layer's size
and push the output pixel region into the resized input layer
- change the image canvass to match the resized layer?
What would a suggest approach be for a plugin?
Thanks,
-Rob A.
Looking for guidance on implementing a plugin
Maybe the code for
http://registry.gimp.org/node/19582
is useful?
Nicolas Robidoux
I looked at that one and they simply create a new image with a scaled version of the active layer, which is sub-optimal from a UI perspective (the plugin registers under the Image menu, but only scales one layer, and ends up create a new image).
The "built-in" scaling options are:
Image->Scale Image which scales all the layers, layer masks, channels
(including the active selection) and paths of the image, not just the
active layer
Layer->Scale Layer which scales the active layer only but does not
change the image canvas size or scale the associated layer mask (is
that a reasonable behavior?).
Thinking about it, I guess my initial question really had two parts:
From a UI perspective:
- should an action like scaling create a new image? (I'm leaning towards no)
- should an action like scaling scale all layers, masks, channels
and paths of an image if it is the image menu (otherwise in the layer
menu)? (I'm leaning towards yes)
- should an action like scaling a layer also scale an associated
layer mask? (yes?)
- with 2.8 having layer groups, will any of this have to change?
From a programming perspective:
- Assuming I have decided my plugin will rescale a layer only (i.e. from the user's perspective the active layer gets scaled) is it better to create a new drawable to contain the scaled image and insert it in the layer stack and delete the initial layer, or better to use gimp_pixel_rgn_init to grab the pixels from the source layer, then change the layer boundary size and and use gimp_pixel_rgn_init to create a second pixel region as an output buffer pointing to the newly sized drawable?
-Rob A>
Looking for guidance on implementing a plugin
On 05/28/2010 08:03 AM, Rob Antonishen wrote:
Maybe the code for
http://registry.gimp.org/node/19582
is useful?
Nicolas Robidoux
I looked at that one and they simply create a new image with a scaled version of the active layer, which is sub-optimal from a UI perspective (the plugin registers under the Image menu, but only scales one layer, and ends up create a new image).
The "built-in" scaling options are: Image->Scale Image which scales all the layers, layer masks, channels (including the active selection) and paths of the image, not just the active layer
Layer->Scale Layer which scales the active layer only but does not change the image canvas size or scale the associated layer mask (is that a reasonable behavior?).Thinking about it, I guess my initial question really had two parts:
From a UI perspective:
- should an action like scaling create a new image? (I'm leaning towards no) - should an action like scaling scale all layers, masks, channels and paths of an image if it is the image menu (otherwise in the layer menu)? (I'm leaning towards yes)
- should an action like scaling a layer also scale an associated layer mask? (yes?)
- with 2.8 having layer groups, will any of this have to change?
From my (quite naive) perspective, it feels like a layer mask should scale with the layer in the Layer menu. I would expect a layer group to scale all layers (and their masks as well, for those layers in the group with an associated mask) in the group proportionately - which implies a Layer Group->Scale menu item.
From a programming perspective:
- Assuming I have decided my plugin will rescale a layer only (i.e. from the user's perspective the active layer gets scaled) is it better to create a new drawable to contain the scaled image and insert it in the layer stack and delete the initial layer, or better to use gimp_pixel_rgn_init to grab the pixels from the source layer, then change the layer boundary size and and use gimp_pixel_rgn_init to create a second pixel region as an output buffer pointing to the newly sized drawable?
-Rob A>
Looking for guidance on implementing a plugin
On the whole it's probably better to use the existing layer, because that
way you automatically
keep its properties such as transparency, mode, etc. If you create a new
layer, you will have to
set all those things by hand. In terms of computational load it probably
doesn't make much
difference -- you have to transport all the pixel data from Gimp to plug-in
and back no matter which
way you do it.
-- Bill
Looking for guidance on implementing a plugin
Quoting Rob Antonishen :
I am writing a c plugin to scale a layer. (This is much as an exercise for me as anything).
I have looked at a few examples and they handle things differently....
- Create a new image with a new layer the new size
The only reason I can conceive why this might be desirable is if the image is Indexed (and RGB scaling is desired); and then you must decide how the rescaled layer is to be re-converted back to Indexed.
- Create a new layer in the existing image just above the input layer
I'm not much of a fan of scripts/plug-ins which merely combine two operations into one. Running a "dup-scale" command is hardly a sufficient improvement to duplicating the layer and scaling the duplicate. (The exception to this being if a user wishes to assign a keyboard shortcut to that single command, but this is most dependent upon the use case and is best left to customized, one-off scripts.)
- Create a new layer in the existing image just above the input layer and delete the input layer
Under normal scenarios, this produces the result I should expect, effectively scaling the layer; however, it raises some implementation and behavioral issues should the active layer be in the floated state.
Furthermore, this approach has the unfortunate side effect of changing the layer's ID (and less importantly, its tattoo). A filter should avoid changing a layer's ID *if possible* as this facilitates other scripts/plug-ins being able to use the filter and in some cases permits.
- Initialize the input pixel region then change the input layer's size and push the output pixel region into the resized input layer
- change the image canvass to match the resized layer?
This seems to me the approach that should be pursued as it would appear to work with floated layers and doesn't unnecessarily modify the layer's ID.
Quoting Rob Antonishen :
The "built-in" scaling options are:
...
Layer->Scale Layer which scales the active layer only but does not change the image canvas size or scale the associated layer mask (is that a reasonable behavior?).
"Layer->Scale Layer" (in the Menus) indeed scales the associated layermask. Currently, I believe all PDB layer transformations also likewise operate upon the associated layermask (this was not always the case).
- should an action like scaling scale all layers, masks, channels and paths of an image if it is the image menu (otherwise in the layer menu)? (I'm leaning towards yes)
Yes. Commands in the Image Menu should operate on the image as a whole.
- should an action like scaling a layer also scale an associated layer mask? (yes?)
It has been my experience that having a layermask with different dimensions then the layer with which it's associated can lead to catastrophic problems in GIMP. I would highly advise that directly after changing the dimensions of a layer, its layermask's dimensions be adjusted to match.
Looking for guidance on implementing a plugin
Layer->Scale Layer which scales the active layer only but does not change the image canvas size or scale the associated layer mask (is that a reasonable behavior?).
"Layer->Scale Layer" (in the Menus) indeed scales the associated layermask. Currently, I believe all PDB layer transformations also likewise operate upon the associated layermask (this was not always the case).
Thanks for the sanity check. I tried again and determine that yes, scaling a layer (whether the layer of mask is active) scales both the layer and the associated mask. It does not change the canvas size.
It also preserves the drawable IDs of the layer and mask.
On a side note, what are tattoos good for? Are they used for anything, anywhere?
-Rob A>
Looking for guidance on implementing a plugin
Quoting Rob Antonishen :
On a side note, what are tattoos good for? Are they used for anything, anywhere?
Layer tattoos are useful when a reference to a layer needs to be maintained across GIMP sessions, subsequent open-ings of the same image within the same session, or even when using "File->Revert" (all of which result in new assignments of layer IDs within the image). Tattoos are similarly associated with channels and paths.
Example: let's say you want to create a drop shadow plug-in which when run on a previously generated "shadow layer" will permit you to modify the offsets, opacity, and blur, and then regenerate the shadow layer (whereas GIMP's Drop Shadow filter would merely create a drop shadow of the shadow layer). You would likely approach this by obtaining from a parasite attached to the shadow layer the last values used in its creation (if no shadow-parasite exists then the last values of the plug-in itself would be used to create a new, shadow layer) in addition to the tattoo of the "base layer" from which the shadow layer was generated. You could not use the ID number of the base layer because this would (likely) be different the next time you open the image; however, the layer's tattoo will always be the same (and unique from all other tattoos).
I don't really know of any scripts/plug-ins which employ tattoos, other than some SIOD-based scripts I'd written to implement layer groupings (never updated for TinyScheme).