It is currently Sat May 04, 2024 5:59 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 312 posts ]  Go to page Previous  1, 2, 3, 4, 5 ... 16  Next
Author Message
 Post subject: Re: Multi-Fill Script Help
PostPosted: Sun Feb 27, 2011 10:57 pm  (#21) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
You need to post some code.

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Multi-Fill Script Help
PostPosted: Sun Feb 27, 2011 11:07 pm  (#22) 
Offline
Global Moderator
User avatar

Joined: Oct 06, 2010
Posts: 4050
(define (script_fu_MultiFill img inLayer inColour inThresh inRandom inPalette inIgnoreSize inFlagSize inFlagColour inHowCheck inMakeCopy inFlatten inPatternDirectory)

;helper function to compare two lists . .i.e. colours
(define (listeql? list1 list2)
(let* ((result TRUE)
      (counter (length list1)))
      (if (<> (length list1) (length list2))
      (set! result FALSE)
      (while (> counter 0)
         (set! counter (- counter 1))
         (if (<> (list-ref list1 counter) (list-ref list2 counter))
            (set! result FALSE)
         )
      )
      )   
      result
)
)

(let*
   (
   (width (car (gimp-image-width img)))
   (height (car (gimp-image-height img)))
   (bounds 0)
   (countX 0)
   (selectionValue 0)
   (numcolours (car (gimp-palette-get-colors inPalette)))
   (palettecount 0)
   (nextcolour 0)
   (layercopy 0)
   (temp 0)
   (channel 0)
   (lastY 0)
        (patterns (cadr (file-glob (string-append inPatternDirectory DIR-SEPARATOR "*.pat"))))
        (numpatterns (length patterns)) ; NOTE: should generate error if zero
        (patterncount 0) ; index into list of patterns
   )
   ;  it begins here
   (gimp-context-push)
   (gimp-image-undo-group-start img)
   (gimp-image-undo-disable img)
   ;logging
   ;(gimp-message-set-handler ERROR-CONSOLE)
   ;(gimp-message-set-handler CONSOLE)
   ;(gimp-message-set-handler MESSAGE-BOX)
   ;or start GIMP wwith "gimp --console-messages" to spawn a console box
   ;then use this:
   ;(gimp-message "foobar")

   ;testing for functions defined
   ;(if (defined? 'plug-in-shift) (gimp-message "It Exists") (gimp-message "Doesnt Exist"))

   (if (= inMakeCopy TRUE)
      (begin
      (set! layercopy (car (gimp-layer-copy inLayer (car (gimp-drawable-has-alpha inLayer)))))
      (gimp-image-add-layer img layercopy -1)
      (gimp-layer-set-mode layercopy MULTIPLY-MODE)
      (gimp-image-set-active-layer img inLayer)
      )
   )
   
   ;  Change to pure B & W
   (gimp-by-color-select inLayer inColour inThresh CHANNEL-OP-REPLACE FALSE FALSE 0 FALSE)
   (gimp-context-set-foreground (list 255 255 255))
   (gimp-edit-fill inLayer FOREGROUND-FILL)
    ;Save it to a channel
    (set! channel (car (gimp-selection-save img)))

   (gimp-selection-invert img)
   (gimp-context-set-foreground (list 0 0 0))
   (gimp-edit-fill inLayer FOREGROUND-FILL)
     
   ;select white
   (gimp-by-color-select inLayer (list 255 255 255) 0 CHANNEL-OP-REPLACE FALSE FALSE 0 FALSE)
   
   (while (= (car (gimp-selection-is-empty img)) FALSE)
      (set! bounds (gimp-selection-bounds img))
      ;get start the loop looking for this colour)
      
      (if (<> lastY (caddr bounds)) ; there is a change in Y, get the new boundary
      (begin
      (set! countX (cadr bounds)) ; x1
        (set! lastY (caddr bounds))
      )
      )

      (set! lastY (caddr bounds))
      
      (set! selectionValue (car (gimp-selection-value img countX (caddr bounds))))
   
      ;find a bg area
      (while (< selectionValue 255) ; while not white
         (set! countX (+ countX 1))
         (set! selectionValue (car (gimp-selection-value img countX (caddr bounds))))
        )
   
      ;select and fill
      (gimp-fuzzy-select inLayer countX (caddr bounds) 0 CHANNEL-OP-REPLACE FALSE FALSE 0 FALSE)
      (set! bounds (gimp-selection-bounds img))
      
      (if (or (and (= inHowCheck 0)
                 (<= (- (cadddr bounds) (cadr bounds)) inIgnoreSize)
                 (<= (- (list-ref bounds 4) (caddr bounds)) inIgnoreSize) ) ; X and Y size
            (and (= inHowCheck 1)
                 (<= (cadddr (gimp-histogram inLayer HISTOGRAM-VALUE 0 255)) inIgnoreSize) )) ; area
      (begin
        (gimp-context-set-foreground (list 0 0 0)) ; fill with black - will be ignored in flatten step
        (gimp-edit-fill inLayer FOREGROUND-FILL) )
      (if (or (and (= inHowCheck 0)
                   (> (- (cadddr bounds) (cadr bounds)) inFlagSize)
                   (> (- (list-ref bounds 4) (caddr bounds)) inFlagSize) ) ; X and Y size
              (and (= inHowCheck 1)
                   (> (cadddr (gimp-histogram inLayer HISTOGRAM-VALUE 0 255)) inFlagSize) )) ; area
        (cond
          ((= fill-type 0) ; Random color fill
            (set! nextcolour inFlagColour) ; guarantees 'while' will loop at least once
            (while (equal? nextcolour inFlagColour) ; random color must not be the flag color
              (set! nextcolour (list (+ (rand 254) 1) ; not black or white either
                                     (+ (rand 254) 1) ; hence color is ([1-254],[1-254],[1-254])
                                     (+ (rand 254) 1) )))
            (gimp-context-set-foreground nextcolour)
            (gimp-edit-fill inLayer FOREGROUND-FILL)
            )
          ((= fill-type 1) ; get color from palette
            (set! nextcolour (car (gimp-palette-entry-get-color inPalette palettecount))) ; next palette colour, - not B, W or flagcoulor
            (while (or (= (apply + nextcolour) 765)
                       (= (apply + nextcolour) 0)
                       (equal? nextcolour inFlagColour) )
              (set! palettecount (modulo (+ palettecount 1) numcolours)) ; increment palette
              (set! nextcolour (car (gimp-palette-entry-get-color inPalette palettecount))) )
            (set! palettecount (modulo (+ palettecount 1) numcolours))

            (gimp-context-set-foreground nextcolour)

            (gimp-edit-fill inLayer FOREGROUND-FILL) )
          ((= fill-type 2) ; fill with a pattern from specified directory
            (gimp-context-set-pattern (list-ref patterns patterncount))
            (gimp-edit-fill inLayer PATTERN-FILL)
            (set! patterncount (modulo (+ patterncount 1) numpatterns)) ))
        (gimp-context-set-foreground inFlagColour) )))

   (gimp-selection-none img)
   
   (if (= inFlatten TRUE)
      (begin
      (gimp-by-color-select inLayer (list 0 0 0) 0 CHANNEL-OP-REPLACE FALSE TRUE 0.5 FALSE)
   
      (while (= (car (gimp-selection-is-empty img)) FALSE)
         (plug-in-dilate RUN-NONINTERACTIVE img inLayer 1 HISTOGRAM-VALUE 1.0 7 0 255)
         (gimp-by-color-select inLayer (list 0 0 0) 0 CHANNEL-OP-REPLACE FALSE TRUE 0.5 FALSE)
      )
      )
   )
   
   (gimp-image-remove-channel img channel)
   
   ;done
    (gimp-image-undo-enable img)
   (gimp-image-undo-group-end img)
   (gimp-progress-end)
   (gimp-displays-flush)
   (gimp-context-pop)
)
)

(script-fu-register "script_fu_MultiFill"
               "<Image>/Filters/Flatting/MultiFill..."
               "Fills every separate area with a different colour from the palette."
               "Rob Antonishen"
               "Rob Antonishen"
               "Dec 2008"
               "RGB* GRAY*"
               SF-IMAGE      "image"      0
               SF-DRAWABLE   "drawable"   0
               SF-COLOR      "MultiFill Colour"       "white"
               SF-ADJUSTMENT "Colour Threshold"       (list 16 0 255 1 10 0 SF-SLIDER)
               SF-OPTION     "Fill mode"             '("Random colours" "Colours from palette" "Patterns from directory")
                                        SF-PALETTE    "Choose Fill Palette"    "Default"
                                        SF-DIRNAME    "Pattern directory"        "*.pat"
               SF-ADJUSTMENT "Ignore Areas <="        (list 3 0 255 1 10 1 SF-SLIDER)
               SF-ADJUSTMENT "Flag Areas <="          (list 10 0 255 1 10 1 SF-SLIDER)
               SF-COLOR      "Flag Colour"            "magenta"
               SF-OPTION     "Area Size Check Method" (list "Width & Height" "Area")               
               SF-TOGGLE     "Copy Layer First"       TRUE
               SF-TOGGLE     "Flatten After"          TRUE
)

_________________
"In order to attain the impossible, one must attempt the absurd."
~ Miguel de Cervantes


Top
 Post subject: Re: Multi-Fill Script Help
PostPosted: Sun Feb 27, 2011 11:48 pm  (#23) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
The position of each of your parameters in the define statement need to match up with the position of its corresponding argument specified in the 'script-fu-register' call (e.g., if inPatternDirectory is the last parameter then SF-DIRNAME should be the last argument).

Also, the value of SF-DIRNAME should be just a directory, no filename (or wildcard pattern).

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Multi-Fill Script Help
PostPosted: Sun Feb 27, 2011 11:59 pm  (#24) 
Offline
Global Moderator
User avatar

Joined: Oct 06, 2010
Posts: 4050
Error: Invalid number of arguments for file-glob (expected 2 but received 1)

Just considering the code changes, and seeing I am not meeting the arguments, I get the feeling I need another toggle for files.

I even entered what I would consider a legal use of file-blog on the script-fu console and got the same error as above.

_________________
"In order to attain the impossible, one must attempt the absurd."
~ Miguel de Cervantes


Top
 Post subject: Re: Multi-Fill Script Help
PostPosted: Mon Feb 28, 2011 2:09 am  (#25) 
Offline
Global Moderator
User avatar

Joined: Oct 06, 2010
Posts: 4050
Ok, this file-glob issue is irritating, but it's not going to scare me off. In the script-fu console, this:

(file-glob "/home/mahvin/.gimp-2.6/patterns/*")

gives me this:

Error: Invalid number of arguments for file-glob (expected 2 but received 1)

But when I add a numerical value 0 or 1:

(file-glob "/home/mahvin/.gimp-2.6/patterns/*" 1)

It properly gives me the entire contents of my patterns folder:

> (file-glob "/home/mahvin/.gimp-2.6/patterns/*" 1)
(173 ("/home/mahvin/.gimp-2.6/patterns/tumor.bmp" etc etc etc...

When I make the same attempt with the multifill script it gives me a new argument error:

Error while executing script_fu_MultiFill:

Error: eval: unbound variable: fill-type

UPDATE:

I added (fill-type 0) to let* and now...

I got it to make a copy, and start fuzzy selections, but it goes into an infinite loop on the first selection, and I can't see what its filling with (pattern fill option) because its not working on the drawing.

_________________
"In order to attain the impossible, one must attempt the absurd."
~ Miguel de Cervantes


Top
 Post subject: Re: Multi-Fill Script Help
PostPosted: Mon Feb 28, 2011 4:50 am  (#26) 
Offline
Global Moderator
User avatar

Joined: Oct 06, 2010
Posts: 4050
I know I am on the right track, file-glob needed a value, I just don't know why it needed a value and what that value should be. I added 1 for a value because I saw that value being used a lot on other scripts using file-glob.

"fill-type" wasn't in the let* statement, so I added it there and the script finally ran, but as promised, you (Saulgoode) said it wouldn't work, and now I agree, it doesn't work right. This is actually fun, I miss the excitement.

Here's a video of the script in action, this is mainly for those of you, who are keeping an eye on things:

(As always, best viewed on YouTube in fullscreen mode)

www.youtube.com Video from : www.youtube.com


The let* statements:
(let*
   (
   (width (car (gimp-image-width img)))
   (height (car (gimp-image-height img)))
   (bounds 0)
   (countX 0)
   (selectionValue 0)
   (numcolours (car (gimp-palette-get-colors inPalette)))
   (fill-type 0) ; not sure but I think it needed to be here.
   (palettecount 0)
   (nextcolour 0)
   (layercopy 0)
   (temp 0)
   (channel 0)
   (lastY 0)
        (patterns (cadr (file-glob (string-append inPatternDirectory DIR-SEPARATOR "*.pat")1)))
        (numpatterns (length patterns)) ; NOTE: should generate error if zero
        (patterncount 0) ; index into list of patterns
   )

_________________
"In order to attain the impossible, one must attempt the absurd."
~ Miguel de Cervantes


Top
 Post subject: Re: Multi-Fill Script Help
PostPosted: Mon Feb 28, 2011 5:06 am  (#27) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
mahvin wrote:
I know I am on the right track, file-glob needed a value, I just don't know why it needed a value and what that value should be. I added 1 for a value because I saw that value being used a lot on other scripts using file-glob.

The second value (sorry 'bout forgetting it) determines whether the returned filename strings are straight ASCII (1) or UTF-8 (0) encoded.

mahvin wrote:
"fill-type" wasn't in the let* statement, so I added it there and the script finally ran, but as promised, you (Saulgoode) said it wouldn't work, and now I agree, it doesn't work right. This is actually fun, I miss the excitement.

Oops. I should probably have stated that 'fill-type' is a parameter of the main function and corresponds to the value of the SF-OPTION "Fill Mode" argument.

The general syntax of SF-OPTION is:
SF-OPTION "Label" (list "arg set to 0" "arg set to 1" "arg set to 2")




Note: if you want to follow RobA's naming practice of using camel case, 'fill-type' should probably be called "inFillType" or somesuch. Traditional Scheme style guidelines, however, prefer all lowercase with words separated by hyphens.

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Multi-Fill Script Help
PostPosted: Mon Feb 28, 2011 5:35 am  (#28) 
Offline
Global Moderator
User avatar

Joined: Oct 06, 2010
Posts: 4050
Ok, I have a hit and miss situation taking place now. I added inFillType to main parameters (changing each instance of fill-type), and it threw the script off on arguments, since your edit reduced the need for the random colour toggle. I added the toggle back to see if it would satisfy the arguments and it did, but the script still gets stuck on the first fuzzy select selection and loops there. Hmmmm...

_________________
"In order to attain the impossible, one must attempt the absurd."
~ Miguel de Cervantes


Top
 Post subject: Re: Multi-Fill Script Help
PostPosted: Mon Feb 28, 2011 8:38 am  (#29) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
Try substituting '(255 0 144) for the "magenta" in the SF-COLOR line (and double-check your argument/parameter alignments). Also, there is no need for the "random" checkbox because that option is offered by the dropdown SF-OPTION.

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: Multi-Fill Script Help
PostPosted: Mon Feb 28, 2011 2:29 pm  (#30) 
Offline
Global Moderator
User avatar

Joined: Oct 06, 2010
Posts: 4050
I notice you have 3 instances of this in your code on page 1:

(gimp-edit-fill inLayer FOREGROUND-FILL)

whereas the original script didn't.

I made the changes you suggested, and removed "inRandom" from the main parameters since it was no longer being used. So, I learned something by looking closer, but still stuck at one fuzzy select looping.

_________________
"In order to attain the impossible, one must attempt the absurd."
~ Miguel de Cervantes


Top
 Post subject: Re: Multi-Fill Script Help
PostPosted: Mon Feb 28, 2011 3:12 pm  (#31) 
Offline
Global Moderator
User avatar

Joined: Oct 06, 2010
Posts: 4050
When I choose random colors, it loops on the first fuzzy select selection but fills the selection with random colors.

When I choose palette colors, it crashes:

Plug-In 'MultiFill' left image undo in inconsistent state, closing open undo groups.

When I choose Patterns, it loops on the first fuzzy select selection, but doesn't fill the selection with color.

_________________
"In order to attain the impossible, one must attempt the absurd."
~ Miguel de Cervantes


Top
 Post subject: Re: Multi-Fill Script Help
PostPosted: Mon Feb 28, 2011 3:34 pm  (#32) 
Offline
GimpChat Member
User avatar

Joined: May 16, 2010
Posts: 14709
Location: USA
I actually have the same problem with Robs original script.
I downloaded it, created a wall with a bunch of bricks, selected all the bricks with fuzzy select - ran the script and it looped endlessly forever on one brick.Then the script created one black layer, and kept looping forever after that.
I do not think its your pattern addition to the script that causes it, i believe its always been there in the original.

_________________
Image
Edmund Burke nailed it when he said, "The only thing necessary for the triumph of evil is for good men to do nothing."


Top
 Post subject: Re: Multi-Fill Script Help
PostPosted: Mon Feb 28, 2011 3:36 pm  (#33) 
Offline
GimpChat Member
User avatar

Joined: May 16, 2010
Posts: 14709
Location: USA
How exactly are you supposed to use the script?
Select every area then run it, or select one area at a time?

_________________
Image
Edmund Burke nailed it when he said, "The only thing necessary for the triumph of evil is for good men to do nothing."


Top
 Post subject: Re: Multi-Fill Script Help
PostPosted: Mon Feb 28, 2011 3:40 pm  (#34) 
Offline
Script Coder
User avatar

Joined: Jul 14, 2010
Posts: 697
I've come to the party late ;)

I've got a newer version than the one at the plugin registry. You might want to use it as a starting point, or I can add the feature you are interested in....

This added a bunch more options including to fill each space with a random direction gradient. This was done to make nifty heightfields for bumpmapping (I was using it to make tile floors - attached is a sample)
Attachment:
tiles.png
tiles.png [ 652.25 KiB | Viewed 2887 times ]


;flattingtools.scm
; by Rob Antonishen
; http://silent9.com

; Version 1.4 (20090213)

; Changes:
; V1.3 - Change the search logic to speed it up in some cases.
;      - Converted to channel opes as they are faster
; V1.4 - Added option to randomly fill from the palette, or gradient fill as well.
; Description
; will fill each separate area with a different coulour, either randomly, from a selected palette, or with a  directional  gradient.

; License:
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
;
; The GNU Public License is available at
; http://www.gnu.org/copyleft/gpl.html

(define (script_fu_Flatting img inLayer)

(let*
   (
   (width (car (gimp-image-width img)))
   (height (car (gimp-image-height img)))
)
   ;  it begins here
   (gimp-context-push)
   (gimp-image-undo-group-start img)
   ;logging
   ;(gimp-message-set-handler ERROR-CONSOLE)
   ;(gimp-message-set-handler CONSOLE)
   ;(gimp-message-set-handler MESSAGE-BOX)
   ;or start GIMP wwith "gimp --console-messages" to spawn a console box
   ;then use this:
   ;(gimp-message "foobar")

   ;testing for functions defined
   ;(if (defined? 'plug-in-shift) (gimp-message "It Exists") (gimp-message "Doesnt Exist"))

   (gimp-by-color-select inLayer (list 0 0 0) 0 CHANNEL-OP-REPLACE FALSE TRUE 0.5 FALSE)
   
   (while (= (car (gimp-selection-is-empty img)) FALSE)
   (plug-in-dilate RUN-NONINTERACTIVE img inLayer 1 HISTOGRAM-VALUE 1.0 7 0 255)
   (gimp-by-color-select inLayer (list 0 0 0) 0 CHANNEL-OP-REPLACE FALSE TRUE 0.5 FALSE)
   )
   
   ;done
   (gimp-image-undo-group-end img)
   (gimp-progress-end)
   (gimp-displays-flush)
   (gimp-context-pop)
)
)

(script-fu-register "script_fu_Flatting"
               "<Image>/Filters/Flatting/Flatten"
               "Flattens an image that has been multicoloured"
               "Rob Antonishen"
               "Rob Antonishen"
               "Jan 2009"
               "RGB* GRAY*"
               SF-IMAGE      "image"      0
               SF-DRAWABLE   "drawable"   0                  
)


(define (script_fu_MultiFill img inLayer inColour inThresh inMethod inPalette inDirection inIgnoreSize inFlagSize inFlagColour inHowCheck inMakeCopy inFlatten inHide)

;helper function to compare two lists . .i.e. colours
(define (listeql? list1 list2)
(let* ((result TRUE)
      (counter (length list1)))
      (if (<> (length list1) (length list2))
      (set! result FALSE)
      (while (> counter 0)
         (set! counter (- counter 1))
         (if (<> (list-ref list1 counter) (list-ref list2 counter))
            (set! result FALSE)
         )
      )
      )   
      result
)
)
; TinyScheme lacks pi.
(define pi (acos -1))

; TinyScheme lacks a floating-point random number generator.
(define (urandom) (/ (rand 32768) 32768))

(let*
   (
    (img (car (gimp-image-duplicate img)))
    (inLayer (car (gimp-image-get-active-layer img)))
   (width (car (gimp-image-width img)))
   (height (car (gimp-image-height img)))
   (bounds 0)
   (countX 0)
   (selectionValue 0)
   (numcolours (car (gimp-palette-get-colors inPalette)))
   (palettecount 0)
   (nextcolour 0)
   (layercopy 0)
   (temp 0)
   (channel 0)
   (lastY 0)
   )
   ;  it begins here
   (gimp-context-push)
   (gimp-image-undo-group-start img)
   (gimp-image-undo-disable img)
   ;logging
   ;(gimp-message-set-handler ERROR-CONSOLE)
   ;(gimp-message-set-handler CONSOLE)
   ;(gimp-message-set-handler MESSAGE-BOX)
   ;or start GIMP wwith "gimp --console-messages" to spawn a console box
   ;then use this:
   ;(gimp-message "foobar")

   ;testing for functions defined
   ;(if (defined? 'plug-in-shift) (gimp-message "It Exists") (gimp-message "Doesnt Exist"))
   
    (gimp-context-set-gradient (list-ref (cadr (gimp-gradients-get-list "")) 2)) ; FG to BG, RGB mapping
   
    (if (= inHide FALSE) (gimp-display-new img))
   (if (= inMakeCopy TRUE)
      (begin
      (set! layercopy (car (gimp-layer-copy inLayer (car (gimp-drawable-has-alpha inLayer)))))
      (gimp-image-add-layer img layercopy -1)
      (gimp-layer-set-mode layercopy MULTIPLY-MODE)
      (gimp-image-set-active-layer img inLayer)
      )
   )
   
   ;  Change to pure B & W
   (gimp-by-color-select inLayer inColour inThresh CHANNEL-OP-REPLACE FALSE FALSE 0 FALSE)
   (gimp-context-set-foreground (list 255 255 255))
   (gimp-edit-fill inLayer FOREGROUND-FILL)
    ;Save it to a channel
    (set! channel (car (gimp-selection-save img)))

   (gimp-selection-invert img)
   (gimp-context-set-foreground (list 0 0 0))
   (gimp-edit-fill inLayer FOREGROUND-FILL)

   (gimp-context-set-background (list 254 254 254))
   
   ;select white
   (gimp-by-color-select inLayer (list 255 255 255) 0 CHANNEL-OP-REPLACE FALSE FALSE 0 FALSE)
   
   (while (= (car (gimp-selection-is-empty img)) FALSE)
      (set! bounds (gimp-selection-bounds img))
      ;get start the loop looking for this colour)
      
      (if (<> lastY (caddr bounds)) ; there is a change in Y, get the new boundary
      (begin
      (set! countX (cadr bounds)) ; x1
        (set! lastY (caddr bounds))
      )
      )

      (set! lastY (caddr bounds))
      
      (set! selectionValue (car (gimp-selection-value img countX (caddr bounds))))
   
      ;find a bg area
      (while (< selectionValue 255) ; while not white
         (set! countX (+ countX 1))
         (set! selectionValue (car (gimp-selection-value img countX (caddr bounds))))
        )
   
      ;select and fill
      (gimp-fuzzy-select inLayer countX (caddr bounds) 0 CHANNEL-OP-REPLACE FALSE FALSE 0 FALSE)
      (set! bounds (gimp-selection-bounds img))
      
      (if (or (and (= inHowCheck 0) (<= (- (cadddr bounds) (cadr bounds)) inIgnoreSize) (<= (- (list-ref bounds 4) (caddr bounds)) inIgnoreSize)) ; X and Y size
              (and (= inHowCheck 1) (<= (cadddr (gimp-histogram inLayer HISTOGRAM-VALUE 0 255)) inIgnoreSize))) ; area
         (gimp-context-set-foreground (list 0 0 0)) ; fill with black - will be ignored in flatten step
         (if (or (and (= inHowCheck 0) (> (- (cadddr bounds) (cadr bounds)) inFlagSize) (> (- (list-ref bounds 4) (caddr bounds)) inFlagSize)) ; X and Y size
            (and (= inHowCheck 1) (> (cadddr (gimp-histogram inLayer HISTOGRAM-VALUE 0 255)) inFlagSize))) ; area
             (begin
                    (cond ((= inMethod 0)
                        (set! nextcolour (list (+ (rand 254) 1) (+ (rand 254) 1) (+ (rand 254) 1))) ;Random colour - not B, W or flagcoulor
                        (while (= (listeql? nextcolour inFlagColour) TRUE)
                            (set! nextcolour (list (+ (rand 254) 1) (+ (rand 254) 1) (+ (rand 254) 1)))
                        )
                      )
                      ((= inMethod 1)
                        (set! nextcolour (+ (rand 254) 1)) ;Random colour - not B, W or flagcoulor
                        (set! nextcolour (list nextcolour nextcolour nextcolour))
                        (while (= (listeql? nextcolour inFlagColour) TRUE)
                                (set! nextcolour (+ (rand 254) 1)) ;Random colour - not B, W or flagcoulor
                                (set! nextcolour (list nextcolour nextcolour nextcolour))                        )
                      )
                 ((= inMethod 2)
                        (set! nextcolour (car (gimp-palette-entry-get-color inPalette palettecount))) ; next palette colour, - not B, W or flagcoulor
                        (while (or (= (+ (car nextcolour) (cadr nextcolour) (caddr nextcolour)) 765)
                        (= (+ (car nextcolour) (cadr nextcolour) (caddr nextcolour)) 0)
                        (= (listeql? nextcolour inFlagColour) TRUE))
                            (set! palettecount (modulo (+ palettecount 1) numcolours)) ; increment palette
                            (set! nextcolour (car (gimp-palette-entry-get-color inPalette palettecount)))
                        )
                        (set! palettecount (modulo (+ palettecount 1) numcolours)) ; increment palette
                      )
                      ((= inMethod 3)
                        (set! nextcolour (car (gimp-palette-entry-get-color inPalette (rand numcolours)))) ; random palette colour, - not B, W or flagcoulor
                        (while (or (< (length nextcolour) 3) ; bug
                               (= (listeql? nextcolour (list 0 0 0)) TRUE)
                        (= (listeql? nextcolour (list 255 255 255)) TRUE)
                        (= (listeql? nextcolour inFlagColour) TRUE))
                            (set! nextcolour (car (gimp-palette-entry-get-color inPalette (rand numcolours)))) ; random palette colour, - not B, W or flagcoulor
                        )
                      )
                      ((or (= inMethod 4)(= inMethod 5))
                        (set! nextcolour (list 1 1 1))
                      )
               )
                    (gimp-context-set-foreground nextcolour)
            )
                (gimp-context-set-foreground inFlagColour)
         )
      )
        (if (< inMethod 4)
            (gimp-edit-fill inLayer FOREGROUND-FILL)
            (let*
                ((bounds (cdr (gimp-selection-bounds img)))
                 (xc (/ (+ (caddr bounds) (car bounds)) 2))
                 (yc (/ (+ (cadddr bounds) (cadr bounds)) 2))
                 (radius (sqrt (+ (expt (- (caddr bounds) (car bounds)) 2) (expt (- (cadddr bounds) (cadr bounds)) 2)  )))
                 (direction (* 2 pi (if (= inMethod 4) (urandom) (/ inDirection 360.0))))
                 (x1 (round (+ xc (* radius (cos direction)))))
                 (y1 (round (- yc (* radius (sin direction)))))
                 (x2 (- xc (- x1 xc)))
                 (y2 (- yc (- y1 yc))))
               
                (gimp-edit-blend inLayer FG-BG-RGB-MODE NORMAL-MODE GRADIENT-LINEAR 100 0 REPEAT-NONE FALSE TRUE 3 3 TRUE x1 y1 x2 y2)
               
            )
        )
      
        (if (= inHide FALSE) (gimp-displays-flush))
       
        (gimp-channel-combine-masks channel (car (gimp-image-get-selection img)) CHANNEL-OP-SUBTRACT 0 0)
        (gimp-selection-load channel)
   )

   (gimp-selection-none img)
   
   (if (= inFlatten TRUE)
      (begin
      (gimp-by-color-select inLayer (list 0 0 0) 0 CHANNEL-OP-REPLACE FALSE TRUE 0.5 FALSE)
   
      (while (= (car (gimp-selection-is-empty img)) FALSE)
         (plug-in-dilate RUN-NONINTERACTIVE img inLayer 1 HISTOGRAM-VALUE 1.0 7 0 255)
         (gimp-by-color-select inLayer (list 0 0 0) 0 CHANNEL-OP-REPLACE FALSE TRUE 0.5 FALSE)
      )
      )
   )
   
   (gimp-image-remove-channel img channel)
   
    (if (= inHide TRUE) (gimp-display-new img))

   ;done
    (gimp-image-undo-enable img)
   (gimp-image-undo-group-end img)
   (gimp-progress-end)
   (gimp-displays-flush)
   (gimp-context-pop)
)
)

(script-fu-register "script_fu_MultiFill"
               "<Image>/Filters/Flatting/MultiFill..."
               "Fills every separate area with a different colour from the palette."
               "Rob Antonishen"
               "Rob Antonishen"
               "Dec 2008"
               "RGB* GRAY*"
               SF-IMAGE      "image"      0
               SF-DRAWABLE   "drawable"   0
               SF-COLOR      "MultiFill Colour"       "white"
               SF-ADJUSTMENT "Colour Threshold"       (list 16 0 255 1 10 0 SF-SLIDER)
               SF-OPTION     "Fill Type"              (list "Random Colours" "Random Greyscale" "Palette" "Palette Random" "Gradient with Random Direction" "Gradient with Specified Direction")
               SF-PALETTE    "Choose Fill Palette"    "Default"
               SF-ADJUSTMENT "Gradient Direction"     (list 135 0 360 1 15 1 SF-SLIDER)                   
               SF-ADJUSTMENT "Ignore Areas <="        (list 3 0 255 1 10 1 SF-SLIDER)
               SF-ADJUSTMENT "Flag Areas <="          (list 10 0 255 1 10 1 SF-SLIDER)
               SF-COLOR      "Flag Colour"            "magenta"
               SF-OPTION     "Area Size Check Method" (list "Width & Height" "Area")               
               SF-TOGGLE     "Copy Layer First"       TRUE
               SF-TOGGLE     "Flatten After"          TRUE
               SF-TOGGLE     "Hide While Processing"  TRUE
)


-Rob A>

_________________
Image
Fantasy Cartography and Mapping by RobA


Top
 Post subject: Re: Multi-Fill Script Help
PostPosted: Mon Feb 28, 2011 3:49 pm  (#35) 
Offline
Global Moderator
User avatar

Joined: Oct 06, 2010
Posts: 4050
This is using the original script with a brick wall on palette setting (just for verification, random colors works as well, just didn't see the need to post two images):

Image

Whoa, didn't see your post RobA. I was just feeling like I was biting off more than I could chew with something of the pattern fill magnitude.

Theories and realities = chasms apart in regards to simplicity, for noobs like me.

How much work would it take for you to add that option to this script? I'd appreciate it. :)

_________________
"In order to attain the impossible, one must attempt the absurd."
~ Miguel de Cervantes


Last edited by mahvin on Mon Feb 28, 2011 3:56 pm, edited 1 time in total.

Top
 Post subject: Re: Multi-Fill Script Help
PostPosted: Mon Feb 28, 2011 3:54 pm  (#36) 
Offline
Script Coder
User avatar

Joined: Jul 14, 2010
Posts: 697
Rod wrote:
I actually have the same problem with Robs original script.
I downloaded it, created a wall with a bunch of bricks, selected all the bricks with fuzzy select - ran the script and it looped endlessly forever on one brick.Then the script created one black layer, and kept looping forever after that.
I do not think its your pattern addition to the script that causes it, i believe its always been there in the original.



You don't select anything first.

The colour parameter is the selection. It makes its own selection, then break it apart.

The default settings will work with black lines on white, all one layer as if you scanned a drawing in.

-Rob A>

_________________
Image
Fantasy Cartography and Mapping by RobA


Top
 Post subject: Re: Multi-Fill Script Help
PostPosted: Mon Feb 28, 2011 3:58 pm  (#37) 
Offline
Global Moderator
User avatar

Joined: Oct 06, 2010
Posts: 4050
You ninja'ed me, RobA, only I didn't get the option of seeing your post before I submitted my own, so I had to change my comments in my post above yours.

If you read my original post, my goal was to have my selections fill with random patterns, however, saulgoode mentioned something about pattern file usage being restricted to .pat files, but a lot of my glass patterns are .jpg and .png files. In my thinking process, I limited myself to "patterns" but then got to wondering why does it have to be patterns? Why couldn't it be "images" within a designated folder? I don't have the answer to this, I'm just asking. My idea with patterns was to make them all seamless and alter their sizes to suit the fill parameters, so larger patterns wouldn't overwhelm small selection areas.

_________________
"In order to attain the impossible, one must attempt the absurd."
~ Miguel de Cervantes


Top
 Post subject: Re: Multi-Fill Script Help
PostPosted: Mon Feb 28, 2011 5:25 pm  (#38) 
Offline
GimpChat Member
User avatar

Joined: May 16, 2010
Posts: 14709
Location: USA
yup i figured that out after about 3 trys Rob, sorry about my confusion :lol
Anyways this new one is awesome! Is there a Pulitzer for Scheme writers? :)

Image

_________________
Image
Edmund Burke nailed it when he said, "The only thing necessary for the triumph of evil is for good men to do nothing."


Top
 Post subject: Re: Multi-Fill Script Help
PostPosted: Mon Feb 28, 2011 5:26 pm  (#39) 
Offline
GimpChat Member
User avatar

Joined: May 16, 2010
Posts: 14709
Location: USA
Can you add patterns and any other image to the list :)

_________________
Image
Edmund Burke nailed it when he said, "The only thing necessary for the triumph of evil is for good men to do nothing."


Top
 Post subject: Re: Multi-Fill Script Help
PostPosted: Mon Feb 28, 2011 5:36 pm  (#40) 
Offline
GimpChat Member
User avatar

Joined: May 16, 2010
Posts: 14709
Location: USA
i like it! now that i know how to use it :lol
Image

_________________
Image
Edmund Burke nailed it when he said, "The only thing necessary for the triumph of evil is for good men to do nothing."


Top
Post new topic Reply to topic  [ 312 posts ]  Go to page Previous  1, 2, 3, 4, 5 ... 16  Next

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) Seeking Help with First Multi-File Batch Script

9

No new posts Palette from multi image

2

No new posts Attachment(s) Fill with pattern seamless

13

No new posts Bucket fill white comes out as grey

4

No new posts Filled path not exporting with fill

4



* Login  



Powered by phpBB3 © phpBB Group