Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What is the api way not pdb
#1
to get bounds
or check to see if there is a selection present?
as pdb. is slow for me when i do repeated operations.

I tried looking at the api documentation but I don't know the syntax to call gimp_selection_is_empty?

image.selection.width is always width of image it's so weird.

I need this in order to speed up this knitted look 2.10 plugin
Reply
#2
Um... I'm a bit disoriented... are you @trandoductin AKA Tin > https://www.gimp-forum.net/User-trandoductin ?
Patrice
Reply
#3
(11-11-2024, 12:34 PM)PixLab Wrote: Um... I'm a bit disoriented... are you @trandoductin AKA Tin > https://www.gimp-forum.net/User-trandoductin ?

Yeah I lost access to my email a while back so created this ttt account
you got my hopes up with the api way since there was a reply hahah

I tried uploading an avatar but for some reason it's not showing
Reply
#4
Can't think of a better way than is_empty = pdb.gimp_selection_is_empty(image) or non_empty, x1, y1, x2, y2 = pdb.gimp_selection_bounds(image) but both should be quick. You would use that only once anyway, if you know what your plugin code is doing with the selection.

Looking at your plugin, a layer with the knit pattern over the original image blurred with Filter > Blur > Pixellize of adequate size would do the trick (yes, pixellize is the average and not the median...). And if you take the pattern size (width, height, bpp = pdb.gimp_pattern_get_info(name)you can do a plugin that auto-adapts to the pattern used (just pixellize to that size).
Reply
#5
what? are you saying I can pixellize and having use a pattern shape that isn't rectangular? I know my pattern is rectangular but the way I color it is a V shape kind of. I am super curious now
Currently I make selection for every V-shape on the image and then use average color to color the V-shape (not rectangle).

aha used Gravatar to show my avatar now haha
Reply
#6
I thought if pixelize can't do shape then i can at least use it to approximate colors and dodge using a bunch of repeated histogram calls.
So now my code is 10% faster because i use get_pixel to get the pixelized color.
Reply
#7
(11-11-2024, 04:37 PM)ttt Wrote: I thought if pixelize can't do shape then i can at least use it to approximate colors and dodge using a bunch of repeated histogram calls.
So now my code is 10% faster because i use get_pixel to get the pixelized color.

You can add a layer mask and fill it with the V-shape pattern.
Reply
#8
(11-11-2024, 04:54 PM)Ofnuts Wrote:
(11-11-2024, 04:37 PM)ttt Wrote: I thought if pixelize can't do shape then i can at least use it to approximate colors and dodge using a bunch of repeated histogram calls.
So now my code is 10% faster because i use get_pixel to get the pixelized color.

You can add a layer mask and fill it with the V-shape pattern.

Not sure what you mean because the V-shapes are all touching each other to fill the image.
Reply
#9
(11-11-2024, 06:10 PM)trandoductin Wrote:
(11-11-2024, 04:54 PM)Ofnuts Wrote:
(11-11-2024, 04:37 PM)ttt Wrote: I thought if pixelize can't do shape then i can at least use it to approximate colors and dodge using a bunch of repeated histogram calls.
So now my code is 10% faster because i use get_pixel to get the pixelized color.

You can add a layer mask and fill it with the V-shape pattern.

Not sure what you mean because the V-shapes are all touching each other to fill the image.

get_pixel() is a major performance problem.

Other way: Create the selection shape only once, then shift the selection mask:


channel = pdb.gimp_selection_save(image) # done once
for whatever_loop:
    pdb.gimp_selection_none(image)
    pdb.gimp_drawable_offset(channel, True, OFFSET_WRAP_AROUND, 100,200)
    pdb.gimp_image_select_item(image,CHANNEL_OP_REPLACE,channel)
    # do whatever with new selection
Reply
#10
I tried this but it seemed slower than doing my new selects everytime. Sad
worth a shot.
I even tried saving as brush so i don't select and the brush but it wasn't any faster.
I timed the get pixel and it was only 1.8 seconds out of 18 seconds.
Reply


Forum Jump: