It is currently Mon Apr 15, 2024 8:01 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Memory issues with homemade script
PostPosted: Wed Sep 05, 2018 3:02 pm  (#1) 
Offline
New Member

Joined: Sep 05, 2018
Posts: 2
The script I wrote (see below) would work on one of two layers that made up image (3600x2400 pixels). The two layers are interlaced, so one layer would have 7 or 8 pixels of transparency, then 7 or 8 pixels of colour, and visa versa. The script is supposed to find these vertical lines of colour information, and flip each individual one vertically.

And it works, so that's not the issue. However, while the image size in gimp is measured in a couple of 10's of MB's, the undo file for the script ends up in excess of 8 GB, meaning it'll get through the available RAM halfway the process and use virtual memory afterwards. I get the feeling I'm using the template for a new script wrong or am unaware of a particular function requiring the storage. Perhaps I'm being stupid in some other way. Would anyone know what I'm doing wrong?

(define (script-fu-lentflip img drawable)
    (gimp-image-undo-group-start img)
    (gimp-context-push)

   (let* ((x 0))
      (while (< x 3599)
      
      (if (= (vector-ref(cadr(gimp-drawable-get-pixel drawable x 0)) 3) 255)
          (begin
             (if (= (vector-ref(cadr(gimp-drawable-get-pixel drawable (+ x 8) 0)) 3) 255)
                 (begin
                   (gimp-rect-select img x 0 8 2400 2 0 0)
                   (gimp-item-transform-flip-simple drawable 0 1 0)
                   (set! x (+ 9 x))
                 )
                 (begin
                   (gimp-rect-select img x 0 7 2400 2 0 0)
                   (gimp-item-transform-flip-simple drawable 0 1 0)
                   (set! x (+ 8 x))
                 )

             )
          )   
      )



      (set! x (+ x 1))
   )
   )

    (gimp-context-pop)
    (gimp-image-undo-group-end img)
    (gimp-displays-flush)
)


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: Memory issues with homemade script
PostPosted: Wed Sep 05, 2018 3:31 pm  (#2) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3975
Location: Canada
You can always try to make a duplicated of image and run script version where you remove the undo group calls.

_________________
TinT


Top
 Post subject: Re: Memory issues with homemade script
PostPosted: Wed Sep 05, 2018 3:46 pm  (#3) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4734
Each of your "gimp-rect-select" and each of your "gimp-item-transform-flip-simple" creates an undo point... and your "gimp-item-transform-flip-simple" creates a new layer

An even better version would copy the layer to a new image, totally disable the undo stack, do the flip thing, copy the result back to the inital image, and delete the work image.

And even better version would perhaps flip a copy of the layer once, and create a mask.

If using Python instead, you can use "pixel regions" that can be readily transformed into very efficient numpy arrays (that you can convert bask to a layer). See https://www.gimp-forum.net/Thread-Gimp-python-and-numpy

_________________
Image


Top
 Post subject: Re: Memory issues with homemade script
PostPosted: Wed Sep 05, 2018 4:02 pm  (#4) 
Offline
New Member

Joined: Sep 05, 2018
Posts: 2
I think the mask solution would end up with a different result, but the new image->disable-undo->copy back was the solution I needed. So obvious once you know how it works. Thank you guys, and thanks for the quick answers!


Top
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) You Got Something - In Memory Of JJ Cale

6

No new posts Attachment(s) UI issues with UHD monitor

9

No new posts GC Connection Issues

11

No new posts Is anyone using Gimp 2.10.34 revision 2 having issues with my plugins

1

No new posts Attachment(s) Issues opening RAW files [Solved]

2



* Login  



Powered by phpBB3 © phpBB Group