I have a python-fu script, which is mostly working. It scans a layer looking for a color, rectangular selects contiguous areas of that color, copies the portion of image in another layer covered by that selection, and saves it to a separate file. All good.
Now the rectangular select has to be cleared, so that it won't be selected again as part of some other set, and the scan starts over so that it can find the next contiguous rectangular block to save.
Unfortunately, I can see the scan traverse the area that's been cleared, and the debug output shows that it still thinks the color is there. Despite the fact that I can see the area is transparent. So, I must be missing a step that tells gimp to update.
I thought I had it with the following:
pdb.gimp_edit_clear(layer)
pdb.gimp_drawable_update(layer,0,0,width,height)
gimp_edit_clear
does clear the selection in the layer I'm searching -- I see that happen -- but the gimp_drawable_update
doesn't seem to do anything, because when the loop progresses over the spot that's been cleared, it reports that the old color is still there.
What am I missing?
The problem was not with the clear, but with my understanding of what it did. I thought it erased the area reverting it to the natural color of an originally transparent area which is RGBA(0,0,0,0). That's what GIMP reports when you ask for the color of a pixel in a fresh transparent layer.
'Clear' doesn't actually remove the color, it just sets the transparency to 100%. So if the original color had been "fully visible white" RGBA(1,1,1,1), it just turns it to "invisible white" RGBA(1,1,1,0).
I had misunderstood RGBA(0,0,0,0) as "transparent", when it's really "invisible black".
So, when my scan started again, it was still seeing 'white', albeit 'invisible white'. Now, instead of using 'clear', I do a fill with the background color, which I've deliberately set to "invisible black".