GIMP Chat
http://gimpchat.com/

Help with plug-in-displace and plug-in-colors-channel-mixer
http://gimpchat.com/viewtopic.php?f=9&t=3021
Page 1 of 1

Author:  InkyDinky [ Mon Nov 07, 2011 1:15 pm ]
Post subject:  Help with plug-in-displace and plug-in-colors-channel-mixer

I'm trying to write a plugin that will create red-cyan anaglyphs from an image and a depth map (as well as learn how to write Gimp scripts).
The things that are broken are the non-interactive use of the displace plugin and the channel mixer.
I get a 'vector-ref out of bounds' error for the displacement plugin.
For the channel mixer instead of layer's channel being changed somehow it acts as if the layer is all white and changes the channels for that. (Although at one point I think it was working properly..but I can't get it back to behaving.)
(define (script-fu-anaglyph theImage drawable)
  (let* (
;       (cyanLyr (car (gimp-layer-copy drawable TRUE)))                                                                                                         
;       (redLyr (car (gimp-layer-copy drawable TRUE)))                                                                                                         
        (theLayersList (cadr (gimp-image-get-layers theImage)))
        (theImageMapLayer (aref theLayersList 0))
        (theBackgroundLayer (aref theLayersList 1))
        (redLyr (car (gimp-layer-copy theBackgroundLayer TRUE)))
        (cyanLyr (car (gimp-layer-copy theBackgroundLayer TRUE)))
        )

;theLayersList gave unbound variable?? when it was just let instead of let*                                                                                     

    (gimp-image-add-layer theImage cyanLyr -1)
    (gimp-drawable-set-name cyanLyr "Cyan")
    (plug-in-colors-channel-mixer RUN-NONINTERACTIVE theImage cyanLyr FALSE 0.0 0.0 0.0 100.0 100.0 100.0 100.0 100.0 100.0 )


    (gimp-image-add-layer theImage redLyr -1)
    (gimp-drawable-set-name redLyr "Red")
    ;(plug-in-colors-channel-mixer RUN-NONINTERACTIVE theImage redLyr FALSE 100.00 100.0 100.0 00.0 00.0 00.0 00.0 00.0 00.0 )                                 
    (gimp-layer-set-mode redLyr SCREEN-MODE)

                                        ;(gimp-curves-explicit cyanLyr HISTOGRAM-RED                                                                           
                                        ;perform displacement                                                                                                   
;    (plug-in-displace RUN-NONINTERACTIVE theImage cyanLyr 10 0 0.0 0 theImageMapLayer theImageMapLayer 1)                                                     
;    (plug-in-displace RUN-INTERACTIVE theImage cyanLyr 10 0 0.0 0 theImageMapLayer theImageMapLayer 1)                                                         
                                        ;0 WRAP 1 SMEAR 2 BLACK                                                                                                 
    (plug-in-displace RUN-NONINTERACTIVE theImage redLyr -10.0 0.0 1 1 theImageMapLayer theImageMapLayer 2)  ;if the do-x and do-y variables (currently 1's to 0's) then I don't get the vector-ref out of bounds error                                                                                                       
;   (plug-in-displace RUN-INTERACTIVE theImage redLyr -10 0 TRUE TRUE 0 theImageMapLayer theImageMapLayer 2)                                                   
    (gimp-displays-flush)
    )
  )
(script-fu-register "script-fu-anaglyph"
                    _"<Image>/Script-Fu/Anaglyph"
                    "Processes an image and depth-map into a red-cyan anaglyph"
                    "InkyDinky"
                    "InkyDinky"
                    "2011 11 7"
                    "*"
                    SF-IMAGE        "Image"     0
                    SF-DRAWABLE     "Drawable"  0
                    )
                                        ; the Red layer is the top layer, set to screen mode                                                                   
                                        ; even though we opened two parens we only close one here, close the other at the end of the script

I'm new to scripting so please be gentle. I've looked at the tutorials and they aren't much help for my problems.
Any help is greatly appreciated.
Running GIMP 2.6.11
Thanks!

Attachments:
File comment: attached script
Test.scm [2.07 KiB]
Downloaded 134 times

Author:  Rod [ Mon Nov 07, 2011 2:24 pm ]
Post subject:  Re: Help with plug-in-displace and plug-in-colors-channel-mixer

Shouldn't x and y displacement be 10.00 ?
Channel mixer i am not sure of.

Author:  saulgoode [ Mon Nov 07, 2011 2:33 pm ]
Post subject:  Re: Help with plug-in-displace and plug-in-colors-channel-mixer

Try removing the backslash and either joining the two lines or inserting a semi-colon to comment the second line.

Author:  InkyDinky [ Mon Nov 07, 2011 2:43 pm ]
Post subject:  Re: Help with plug-in-displace and plug-in-colors-channel-mixer

Nope we only want to displace X.
Think of your eyes. They are a stereo pair. They have a X offset but not a Y offset.

Author:  Rod [ Mon Nov 07, 2011 3:15 pm ]
Post subject:  Re: Help with plug-in-displace and plug-in-colors-channel-mixer

saulgoode wrote:
Try removing the backslash and either joining the two lines or inserting a semi-colon to comment the second line.


Saul would you mind explaining what you mean by "backslash" ?

Thanks.

Author:  InkyDinky [ Mon Nov 07, 2011 3:32 pm ]
Post subject:  Re: Help with plug-in-displace and plug-in-colors-channel-mixer

I edited the code that is displayed in the code block that I think he was referring to.
When I pasted from my editor it inserted the / for the line break.

Author:  Rod [ Mon Nov 07, 2011 3:36 pm ]
Post subject:  Re: Help with plug-in-displace and plug-in-colors-channel-mixer

Ahh okay, thanks. :)
Welcome to Gimp Chat by the way.

Author:  InkyDinky [ Mon Nov 07, 2011 11:01 pm ]
Post subject:  Re: Help with plug-in-displace and plug-in-colors-channel-mixer

Well I have a working script.
I didn't solve the channel-mixer problem. The documentation isn't clear as to what the "gain" does for the color.
I had to work around this problem.
And as far as the displace plugin I had to set the do-x and do-y options to 1 otherwise it wouldn't work.
Here is my working script and a sample image to play with.
The images work best with a depth map from 0-127 and not 0-255
And BTW the cartestion/polar option doesn't do anything in the pop up menu.
Enjoy and happy anaglyphing!

Attachments:
Zelda_by_Fennewalde.xcf [3.35 MiB]
Downloaded 174 times
Anaglyph3.scm [4 KiB]
Downloaded 160 times

Author:  saulgoode [ Tue Nov 08, 2011 1:01 am ]
Post subject:  Re: Help with plug-in-displace and plug-in-colors-channel-mixer

InkyDinky wrote:
Well I have a working script.
I didn't solve the channel-mixer problem. The documentation isn't clear as to what the "gain" does for the color.

The gain values of the PDB function are multiplication factors, not the percentage values expected by the dialog interface.

For example, to convert a layer to grayscale luminance using CIE Rec. 709 weighting (0.2126*R + 0.7152*G + 0.0722*B), you would use:
(plug-in-colors-channel-mixer RUN-NONINTERACTIVE image layer FALSE
                              0.2126 0.7152 0.0722
                              0.2126 0.7152 0.0722
                              0.2126 0.7152 0.0722 )


or to extract the green channel only:
(plug-in-colors-channel-mixer RUN-NONINTERACTIVE image layer FALSE
                              0 0 0
                              0 1 0
                              0 0 0 )

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/