RSS/Atom feed Twitter
Site is read-only, email is disabled

gimp-python: checking if point is in selection

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.

6 of 6 messages available
Toggle history

Please log in to manage your subscriptions.

gimp-python: checking if point is in selection Sebastian Breuers 02 Jun 13:48
  gimp-python: checking if point is in selection saulgoode@brickfilms.com 02 Jun 19:44
   gimp-python: checking if point is in selection Sebastian Breuers 03 Jun 12:05
  gimp-python: checking if point is in selection Sven Neumann 02 Jun 19:54
   gimp-python: checking if point is in selection Sebastian Breuers 02 Jun 23:16
    gimp-python: checking if point is in selection Michael Natterer 02 Jun 23:30
Sebastian Breuers
2006-06-02 13:48:07 UTC (almost 18 years ago)

gimp-python: checking if point is in selection

Hello@all

i wondered if there is a possibility to check, if a point is in a given selection by using an internal gimp function. If it's not, could someone give me a hint, how to achieve this in creating an own function?

seb

Mail: sebbreuers@gmx.de

saulgoode@brickfilms.com
2006-06-02 19:44:33 UTC (almost 18 years ago)

gimp-python: checking if point is in selection

Quoting Sebastian Breuers :

i wondered if there is a possibility to check, if a point is in a given selection by using an internal gimp function. If it's not, could someone give me a hint, how to achieve this in creating an own function?

I don't use Python-fu but the following Script-fu function should be easily ported (or perhaps you can find a better way):

(define (point-in-selection image x y) (let* (
(saved (car (gimp-selection-save image))) (return-value)
)
(gimp-rect-select image x y 1 1 CHANNEL-OP-INTERSECT 0 0) (set! return-value (car (gimp-selection-is-empty image))) (gimp-selection-load saved)
(if (= return-value 0)
1
0
)
)
)

Note that the selection does not include the points at the rightmost and bottommost edges. For example, if the selection is from (0,0) to (10,10) then the point (10,10) is *not* "in" the selection but (9,9) is. You may need to adjust things to account for this.

Sven Neumann
2006-06-02 19:54:41 UTC (almost 18 years ago)

gimp-python: checking if point is in selection

Hi,

On Fri, 2006-06-02 at 13:48 +0200, Sebastian Breuers wrote:

i wondered if there is a possibility to check, if a point is in a given selection by using an internal gimp function. If it's not, could someone give me a hint, how to achieve this in creating an own function?

Use gimp-image-get-selection to get the selection mask and check the value of the pixel you are interested in.

Sven

Sebastian Breuers
2006-06-02 23:16:16 UTC (almost 18 years ago)

gimp-python: checking if point is in selection

Am Freitag, 2. Juni 2006 19:54 schrieben Sie:

Hi,

On Fri, 2006-06-02 at 13:48 +0200, Sebastian Breuers wrote:

i wondered if there is a possibility to check, if a point is in a given selection by using an internal gimp function. If it's not, could someone give me a hint, how to achieve this in creating an own function?

Use gimp-image-get-selection to get the selection mask and check the value of the pixel you are interested in.

Hi, Sven,

i've already found the selection function, but could you tell me how to check the value of the pixel?

Sven

seb

Michael Natterer
2006-06-02 23:30:39 UTC (almost 18 years ago)

gimp-python: checking if point is in selection

On Fri, 2006-06-02 at 23:16 +0200, Sebastian Breuers wrote:

Am Freitag, 2. Juni 2006 19:54 schrieben Sie:

Hi,

On Fri, 2006-06-02 at 13:48 +0200, Sebastian Breuers wrote:

i wondered if there is a possibility to check, if a point is in a given selection by using an internal gimp function. If it's not, could someone give me a hint, how to achieve this in creating an own function?

Use gimp-image-get-selection to get the selection mask and check the value of the pixel you are interested in.

Hi, Sven,

i've already found the selection function, but could you tell me how to check the value of the pixel?

Use gimp-selection-value

ciao, --mitch

Sebastian Breuers
2006-06-03 12:05:40 UTC (almost 18 years ago)

gimp-python: checking if point is in selection

Am Freitag, 2. Juni 2006 19:44 schrieb saulgoode@brickfilms.com:

Quoting Sebastian Breuers :

i wondered if there is a possibility to check, if a point is in a given selection by using an internal gimp function. If it's not, could someone give me a hint, how to achieve this in creating an own function?

I don't use Python-fu but the following Script-fu function should be easily ported (or perhaps you can find a better way):

(define (point-in-selection image x y) (let* (
(saved (car (gimp-selection-save image))) (return-value)
)
(gimp-rect-select image x y 1 1 CHANNEL-OP-INTERSECT 0 0) (set! return-value (car (gimp-selection-is-empty image))) (gimp-selection-load saved)
(if (= return-value 0)
1
0
)
)
)

Hi.

thanks for the tip. works fine.

seb

Note that the selection does not include the points at the rightmost and bottommost edges. For example, if the selection is from (0,0) to (10,10) then the point (10,10) is *not* "in" the selection but (9,9) is. You may need to adjust things to account for this.