Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trouble replicating posterize with blending option enabled in python-fu script
#1
Python 
Hello! I've recently started scripting with gimp and I've ran into a problem with posterize. I believe the issue is with how I am trying to implement the blending option. Does anyone have experience with automating the posturize tool with a blending option enabled?

I've found:
gimp_edit_blend()
gimp_context_set_paint_mode()
gimp_layer_set_mode()

Removed Alpha layer, manually using the posterize tool with 2 levels an color erase blending
[Image: asdf.png]
With my tool set to 2 levels using gimp_edit_blend
[Image: qwer.png]

Code:
srclayer = image.layers[0]
pdb.gimp_image_insert_layer(image, pdb.gimp_layer_copy(srclayer, 0), None, -1)
pdb.gimp_drawable_posterize(image.layers[0], amount)
pdb.gimp_context_set_paint_mode(57)
image.layers[0] = blendColorErase(image.layers[0])

It's quite possible I'm completely missing how the posterize tool accomplishes the blending. So far the results I've been getting are as if I had no blending mode selected (Replace/Normal). I'm aiming to use the Color Erase paint mode, but I'm running out of ideas what I'm doing wrong.

Thank you for reading.
Reply
#2
As far as I can tell, using something other than Replace is the same as using Replace on a copy of the layer, and putting this over a copy of the initial layer using the required paint mode. For Color erase you have to fill the alpha layer to 100% in addition.

   
Reply
#3
I think this is not only a scripting issue but a GEGL issue. The Gimp 2.10 posterize in the pdb is essentially GEGL with a backward compatibility 'wrapper'. A demo here using the Filters -> Generic -> GEGL graph, it is the posterize filter with blending mode.

   

Unfortunately in keeping with the old (Gimp 2.8) posterize there is no way of applying the GEGL blend modes. Also they are not replicated in the layer modes although you can get an "effect" by adding some other procedure (maybe).
Reply
#4
Thank you Ofnuts for getting me on the right track! The issue was that I didn't make the alpha mask opaque. My code for replicating color-erase posterize is below:


Code:
   groupLayer = pdb.gimp_layer_group_new(image)
   srcLayer =  pdb.gimp_layer_copy(image.layers[0], False)
   eraseLayer = pdb.gimp_layer_copy(image.layers[0], False)

   #Insert layer group with two layers inside
   pdb.gimp_image_insert_layer(image,groupLayer, None, -1)
   pdb.gimp_image_insert_layer(image, srcLayer, image.layers[0], -1)
   pdb.gimp_image_insert_layer(image, eraseLayer, image.layers[0], -1)

   #Posturize erase layer, then set paint mode to Color Erase
   pdb.gimp_layer_set_mode(eraseLayer, 57)
   pdb.gimp_drawable_posterize(eraseLayer, amount)

   #transfer grouplayer alpha to new mask, then fill alpha with white
   mask = pdb.gimp_layer_create_mask(groupLayer, 3)
   pdb.gimp_layer_add_mask(groupLayer, mask)
   pdb.gimp_drawable_edit_fill(mask, 2)

   # Apply mask and merge group
   pdb.gimp_image_merge_layer_group(image, image.layers[0])
   pdb.gimp_layer_remove_mask(image.layers[0], 0)
Reply


Forum Jump: