Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
re-coloured pixels hide confusingly
#1
Hello,
I have been exploring Script-Fu recently, and found that the procedure "gimp-drawable-set-pixels" sets the colours of pixels but does not make the new colours visible! I've got to toggle layer visibility off then on for the display to refresh, or copy the modified pixels, paste back over themselves, and merge down.

I'm aware of the function "gimp-displays-refresh", but calling it doesn't seem to do anything.

I'm assuming I'm just very stupid and there's a simple way to make the results gimp-drawable-set-pixels visible from script-fu. I certainly feel stupid after spending so much time trying to figure out something so seemingly simple, so as a last resort I figured I'd ask here.  Wink
Reply
#2
(02-26-2026, 08:58 AM)cjel Wrote: Hello,
I have been exploring Script-Fu recently, and found that the procedure "gimp-drawable-set-pixels" sets the colours of pixels but does not make the new colours visible! I've got to toggle layer visibility off then on for the display to refresh, or copy the modified pixels, paste back over themselves, and merge down.

I'm aware of the function "gimp-displays-refresh", but calling it doesn't seem to do anything.

I'm assuming I'm just very stupid and there's a simple way to make the results gimp-drawable-set-pixels visible from script-fu. I certainly feel stupid after spending so much time trying to figure out something so seemingly simple, so as a last resort I figured I'd ask here.  Wink

Try gimp-displays-flush
Reply
#3
Ah, I misspoke. In my original post I wrote "gimp-displays-refresh" when I meant "gimp-displays-flush". I _have_ tried "gimp-displays-flush" (since I saw many other scripts calling it at the end of their main function) but it doesn't make the modifications from "gimp-drawable-set-pixel" visible. Should it? Perhaps I've found a bug?
Reply
#4
(02-27-2026, 11:27 AM)cjel Wrote: ... Perhaps I've found a bug?

Possibly. I've just tried the following lines in the Script-fu console in both V3.0.8 and 3.2.0 rc 2 with the same results - the call of gimp-displays-flush has no effect:
Code:
(gimp-get-images)
(gimp-image-get-selected-drawables 1)
(gimp-drawable-set-pixel 2 1 2 '(0 0 0 0))
(gimp-displays-flush)

As a work-around you could add the following:

Code:
(gimp-item-set-visible 2 FALSE)
(gimp-item-set-visible 2 TRUE)


Calling  (gimp-image-is-dirty 1) after setting the pixel returns a value of 0 (in V3.2.0 rc 2) - so it looks as though this is a bug where the set pixel function isn't setting the dirty flag.

Update 1.3.2026

The GIMP source code says that the image dirty flag is not to be set explicitly. Instead an undo step should be created.

The issue, I think, comes down to the gim-drawable-set-pixel not registering as an undo step. If you use the function to set a pixel, turn the layer visibility off and on then the pixel appears but Edit/Undo only shows the visibility steps - you can't undo the set-pixel operation.

I'm wondering if this was a deliberate decision - it is likely that a script may set many pixels. If each setting caused an undo entry to be created you would overflow the undo stack.

The attached demo script shows two ways of making the pixel(s) appear. The drawing a line option could be replaced by any operation that creates an undo step (the script may have things to do apart from setting pixels). For your purposes the code that turns the layer visibility off/on may be more appropriate. Alternatively you could raise the issue with the developers (although I can find no record of anyone else raising this in the 30 years that GIMP has been around)

Further update:

I have changed the brush call for gimp-pencil - with a 1 pixel brush this will be the same as set-pixel but you can set more than one pixel at a time and it will be undoable. The downside is that it always draws with the foreground colour rather than being able to specify the colour in the set-pixel call.


.scm   SetPixel.scm (Size: 1.81 KB / Downloads: 8)
Reply


Forum Jump: