Gracefully handling BPP in a python 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.
Gracefully handling BPP in a python plugin | Ofnuts | 17 Sep 20:48 |
Gracefully handling BPP in a python plugin | Sven Neumann | 18 Sep 00:33 |
Gracefully handling BPP in a python plugin | Ofnuts | 18 Sep 01:51 |
Gracefully handling BPP in a python plugin | Sven Neumann | 18 Sep 19:23 |
Gracefully handling BPP in a python plugin | Ofnuts | 18 Sep 21:55 |
Gracefully handling BPP in a python plugin | Sven Neumann | 19 Sep 20:44 |
Gracefully handling BPP in a python plugin | Ofnuts | 19 Sep 21:36 |
Gracefully handling BPP in a python plugin | Sven Neumann | 19 Sep 22:20 |
Gracefully handling BPP in a python plugin
Hello,
I'm writing a plugin that takes a drawable as input for pixel values. What kind of BPP can I expect? I'd say 4 and 3 are color layers with and without alpha. Will I encounter 2 and 1 for grey-levels with and without alpha, too? I can't find a way to create a layer in grey levels (or to change an existing color one to grey levels). Am I overlooking the obvious or would that only apply to layer masks?
I'm actually using the drawable pixels fro set the foreground color for various operation (selection stroke and bucket fill). Is there a general function to convert the pixel values betwen drawables of different "depth"? or can I put in gimp_context_set_foreground() whatever I get from gimp_drawable_get_pixel()?
Gracefully handling BPP in a python plugin
On Fri, 2010-09-17 at 20:48 +0200, Ofnuts wrote:
Hello,
I'm writing a plugin that takes a drawable as input for pixel values. What kind of BPP can I expect? I'd say 4 and 3 are color layers with and without alpha. Will I encounter 2 and 1 for grey-levels with and without alpha, too?
Well, it depends on what your procedure specifies as image types when it registers. The documentation says:
image_types is a comma separated list of image types, or actually drawable types, that this procedure can deal with. Wildcards are possible here, so you could say "RGB*" instead of "RGB, RGBA" or "*" for all image types. If the procedure doesn't need an image to run, use the empty string.
I can't find a way to create a layer in grey levels (or to change an existing color one to grey levels). Am I overlooking the obvious or would that only apply to layer masks?
Grayscale layers only exist in grayscale images. If you specify "GRAY" and/or "GRAYA" or "*", then your procedure needs to handle those drawable types.
Sven
Gracefully handling BPP in a python plugin
On 18/09/2010 00:33, Sven Neumann wrote:
On Fri, 2010-09-17 at 20:48 +0200, Ofnuts wrote:
Hello,
I'm writing a plugin that takes a drawable as input for pixel values. What kind of BPP can I expect? I'd say 4 and 3 are color layers with and without alpha. Will I encounter 2 and 1 for grey-levels with and without alpha, too?
Well, it depends on what your procedure specifies as image types when it registers. The documentation says:
image_types is a comma separated list of image types, or actually drawable types, that this procedure can deal with. Wildcards are possible here, so you could say "RGB*" instead of "RGB, RGBA" or "*" for all image types. If the procedure doesn't need an image to run, use the empty string.
I can't find a way to create a layer in grey levels (or to change an existing color one to grey levels). Am I overlooking the obvious or would that only apply to layer masks?
Grayscale layers only exist in grayscale images. If you specify "GRAY" and/or "GRAYA" or "*", then your procedure needs to handle those drawable types.
I had overlooked the fact that greyscale was an attribute of the image and not the layer. Thanks for the reminder. With that in mind I could perform some more tests with greyscale and it turns out that at least the python interface returns 3 or 4 channels even in greyscale, so everything is OK. Thx for the help.
Gracefully handling BPP in a python plugin
On Sat, 2010-09-18 at 01:51 +0200, Ofnuts wrote:
I had overlooked the fact that greyscale was an attribute of the image and not the layer. Thanks for the reminder. With that in mind I could perform some more tests with greyscale and it turns out that at least the python interface returns 3 or 4 channels even in greyscale, so everything is OK.
If that is the case, then there is a bug somewhere. But I very much doubt that gray-scale layers are reported to have 3 or channels. Perhaps you can show us some example code?
Sven
Gracefully handling BPP in a python plugin
On 18/09/2010 19:23, Sven Neumann wrote:
On Sat, 2010-09-18 at 01:51 +0200, Ofnuts wrote:
I had overlooked the fact that greyscale was an attribute of the image and not the layer. Thanks for the reminder. With that in mind I could perform some more tests with greyscale and it turns out that at least the python interface returns 3 or 4 channels even in greyscale, so everything is OK.
If that is the case, then there is a bug somewhere. But I very much doubt that gray-scale layers are reported to have 3 or channels. Perhaps you can show us some example code?
Hmm. Wrote some fresh code to demonstrate this and of course it behaves as you say. Grumble, grumble. Back to the drawing board. Thx for the heads up.
PS: well, something fishy still. Creating a greyscale layer in a RGB image works, and yields a 1BPP layer:
image_color = pdb.gimp_image_new(100,100,0) layer_grayscale=pdb.gimp_layer_new(image_color,100,100,2,'grayscale_layer',100,0) print pdb.gimp_drawable_get_pixel(layer_grayscale,0,0)
This a moot point right now because I'm not creating images & layers that way, but you said this couldn't happen?
Gracefully handling BPP in a python plugin
On Sat, 2010-09-18 at 21:55 +0200, Ofnuts wrote:
If that is the case, then there is a bug somewhere. But I very much doubt that gray-scale layers are reported to have 3 or channels. Perhaps you can show us some example code?
Hmm. Wrote some fresh code to demonstrate this and of course it behaves as you say. Grumble, grumble. Back to the drawing board. Thx for the heads up.
PS: well, something fishy still. Creating a greyscale layer in a RGB image works, and yields a 1BPP layer:
image_color = pdb.gimp_image_new(100,100,0) layer_grayscale=pdb.gimp_layer_new(image_color,100,100,2,'grayscale_layer',100,0) print pdb.gimp_drawable_get_pixel(layer_grayscale,0,0)
First of all, why are you using the PDB directly instead of using the Python objects? The code to create an image and an RGBA layer should look like this:
image = image = gimp.Image(100, 100, RGB) layer = gimp.Layer(image, "RGB layer", 100, 100, RGBA_IMAGE) image.add_layer(layer)
Then to address you problem, you are not really creating a grayscale layer in an RGB image. Your code only creates the layer, it doesn't actually add it to the image. If you tried to do that, then that would fail.
Sven
Gracefully handling BPP in a python plugin
On 19/09/2010 20:44, Sven Neumann wrote:
First of all, why are you using the PDB directly instead of using the Python objects?
Ignorance, defiance, and laziness. The doc for the Image class (http://www.gimp.org/docs/python/index.html) has around 20 methods. Compare to the number of gimp_image_* functions in the PDB (not speaking of all the Python class methods/attributes vs the whole PDB)(*) For a newcomer, it looks like using the Python classes isn't going to cut it, since PDB functions will have to be used anyway, so why bother with two ways of doing things? And for the laziness bit, the python-fu console gives pre-cooked PDB calls...
The code to create an image and an RGBA layer should look like this:
image = image = gimp.Image(100, 100, RGB) layer = gimp.Layer(image, "RGB layer", 100, 100, RGBA_IMAGE) image.add_layer(layer)
Then to address you problem, you are not really creating a grayscale layer in an RGB image. Your code only creates the layer, it doesn't actually add it to the image. If you tried to do that, then that would fail.
Indeed. Case closed :-)
(*) I'm not underestimating the challenge of having a complete Python "vision" of the PDB...
Gracefully handling BPP in a python plugin
On Sun, 2010-09-19 at 21:36 +0200, Ofnuts wrote:
On 19/09/2010 20:44, Sven Neumann wrote:
First of all, why are you using the PDB directly instead of using the Python objects?
Ignorance, defiance, and laziness. The doc for the Image class (http://www.gimp.org/docs/python/index.html) has around 20 methods. Compare to the number of gimp_image_* functions in the PDB (not speaking of all the Python class methods/attributes vs the whole PDB)(*) For a newcomer, it looks like using the Python classes isn't going to cut it, since PDB functions will have to be used anyway, so why bother with two ways of doing things?
Because the 20 methods that are available in the Image class cover about 95% of what people actually need. It's much more convenient and you can of course still use methods from the pdb module.
Oh, and the docs you pointed at are hopelessly outdated and should probably be taken off-line. You better refer to the help you get in the Python console.
Sven