Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bug: gimp-drawable-get-pixel fails despite channels visible in UI
#8
(07-04-2025, 01:17 PM)AgHornet Wrote:
(07-04-2025, 07:10 AM)teapot Wrote: PS: There are big differences between gimp 2.10 and 3.0 so please clarify what version of gimp you're using in this case.  Your profile says 3.0 but post #1 in this thread says '**GIMP Version:** 2.10.38'.  Then again your post on your thread 'GIMP 3.0.4 Script-Fu Batch Issue: SF-TOGGLE Without Run-Mode' says 'gimp 3.0.4'.

As stated my above answer assumes you first post in this thread contains the appropriate version in this case.

Thanks very much for getting back. Yes, I am using gimp 2.10.38. I had been trying to use Gimp 3.0.4 last week, but that proved to problematic, so I reverted to, what I thought might be better documented, with more examples. So, for the sack of this thread, I am using gimp 2.10. 

Thanks


ps. I'm going to look at the other suggestion now. Cheers

(07-04-2025, 04:21 AM)teapot Wrote: Hi AgHornet,

Assuming you are on gimp 2.10 as your post says (so not gimp 3.0), hopefully the test script below helps. Example output:
    Test get pixel Warning
    Name: Background
    Coordinate: 4 9
    Bpp: 4
    Do num-channels = bpp? #t
    Is pixel a vector? #t
    Is len pixel = bpp? #t
    Channel: 0 Value: 152
    Channel: 1 Value: 229
    Channel: 2 Value: 84
    Channel: 3 Value: 197

As for Image -> Image properties
    ...
    Number of Channels
    ...

It's the number of selection mask channels in the mage. You can add these using the 'Create a new channel' icon at the bottom left of the channels dialog. See https://docs.gimp.org/2.10/en/gimp-channel-dialog.html


Code:
(define (boolean->string b) (if b "#t" "#f"))

(define (script-fu-test-get-pixel image drawable x y)

  (let* ((bpp (car (gimp-drawable-bpp drawable)))
         (pixel-result (gimp-drawable-get-pixel drawable x y))
         (num-channels (car pixel-result))
         (pixel (cadr pixel-result))
         (mess "")
        )

    (set! mess (string-append mess "Name: " (car (gimp-item-get-name drawable)) "\n"))
    (set! mess (string-append mess "Coordinate: " (number->string x) " " (number->string y) "\n"))
    (set! mess (string-append mess "Bpp: " (number->string bpp) "\n"))
    (set! mess (string-append mess "Do num-channels = bpp? " (boolean->string (= num-channels bpp)) "\n"))
    (set! mess (string-append mess "Is pixel a vector? " (boolean->string (vector? pixel)) "\n"))
    (set! mess (string-append mess "Is len pixel = bpp? " (boolean->string (= (vector-length pixel) bpp)) "\n"))

    (do ((len (vector-length pixel))
         (i 0 (+ i 1)))
        ((= i len))
        (set! mess (string-append mess "Channel: " (number->string i) " Value: " (number->string (vector-ref pixel i)) "\n"))
    )

    (gimp-message mess)

  ))

(script-fu-register
  "script-fu-test-get-pixel"                  ; Name
  "Test get pixel"                            ; Menu label
  ""                                          ; Description
  "Author"                                    ; Author
  "Copyright"                                 ; Copyright
  ""                                          ; Date
  "*"                                         ; Types
  SF-IMAGE       "image"     0
  SF-DRAWABLE    "drawable"  0
  SF-ADJUSTMENT  "x"        (list 0 0 1000 1 10 0 SF-SPINNER)
  SF-ADJUSTMENT  "y"        (list 0 0 1000 1 10 0 SF-SPINNER)
)

(script-fu-menu-register "script-fu-test-get-pixel" "<Image>/Script-Fu")
Thanks so much for this explaination. This proved to be the problem. Whilst pixel-result was a pair
(a list), I was treating the second element as a scheme list when it was a scheme vector. I can now correctly read the values from the file. (What I didn't realise is how slow this function call is :-( )

Thanks for the help. Much appreciated.

This call is not really meant to check all pixels in layer. For this you have better get a "buffer" from the drawable. However this is Gegl territory. Doable in Python (in 2.x you could use "tiles"), but  I doubt the API is available from script-fu.
Reply


Messages In This Thread
RE: Bug: gimp-drawable-get-pixel fails despite channels visible in UI - by Ofnuts - 07-04-2025, 02:55 PM

Forum Jump: