RFX-GIMP

Artifact Content
Login

Artifact 48a91d8d0951718c8379d5979d784d9baa53d1f8:


Script file generated from LiVES

<define>
|1.7
</define>

<name>
clockwipe
</name>

<version>
1
</version>

<author>
saulgoode|http://chiselapp.com/user/saulgoode/repository/RFX-GIMP/home
</author>

<description>
Clock Wipe|Clock transitioning|1|2|
</description>

<requires>
gimp
</requires>

<params>
centerx|Center X|num0|0|0|1000000|
centery|Center Y|num0|0|0|1000000|
ccw|Counter clockwise|bool|0|
wipe-to-color|Wipe To Color|bool|0|
color|Color|colRGB24|0|0|0|
</params>

<param_window>
layout|p0|p1|
layout|p2|
layout|hseparator|
layout|p3|p4|
</param_window>

<properties>
0x0000
</properties>

<language_code>
0xF0
</language_code>

<pre>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 or higher
# as published by the Free Software Foundation.

use IO::Socket; 
use Text::Balanced;

if ($ENV{'RFXGIMP_PORT'}) {
  $rfx_port = $ENV{'RFXGIMP_PORT'};
  }
else {
  $rfx_port = 10008; 
  }

$sock = new IO::Socket::INET ( PeerAddr => 'localhost', 
                               PeerPort => $rfx_port, 
                               Proto => 'tcp' 
                               );
if ( not defined $sock ) {
  my $rfx_pid = fork();
  if (not defined $rfx_pid) {
    &sig_error("UNABLE TO EXECUTE GIMP: Not enough resources");
    } 
  elsif ($rfx_pid == 0) {
    if ( -f $tmpdir . "rfxgimp.pid") {
      open(PIDFILE, $tmpdir . "rfxgimp.pid");
      # should probably do some sanity checking for the off chance that
      # the PID has been recycled or the system has rebooted (e.g, check
      # if process was executed with /usr/bin/perl. But for now...
      kill(15, -<PIDFILE>); # the negative PID means kill all children, too.
      close(PIDFILE);
      }
    setpgid($$,0); # change the pgroup to this forked process, rather than
                   # the original LiVES (so that we don't kill LiVES when 
                   # this prgroup is killed).
    open(PIDFILE, ">" . $tmpdir . "rfxgimp.pid"); # overwrite old file
    print PIDFILE $$;
    close(PIDFILE);
    my $start_gimp = qq{ gimp -i -b "(plug-in-script-fu-server 1 $rfx_port \\\"\\\")" & };
    system ( $start_gimp ); # though started as separate process, GIMP now
                            # is part of this spawned child's pgroup, not the LiVES pgroup
    sleep(); # do nothing, forever
    &sig_error("GIMP killed by external process\n");
    }
  else {
    while (not defined $sock) {
      sleep (1);
      $sock = new IO::Socket::INET ( PeerAddr => 'localhost', 
                                     PeerPort => $rfx_port, 
                                     Proto => 'tcp' 
                                     );
      }
    }
  }

# Define a Perl subroutine for sending messages to the SF server and waiting
# for a response.
#
sub rfx_sendmsg {
  my $message = $_[0];
  my $len = length ($message);
  if ($len > 65535) {
    &sig_error("ERROR: script is too long for one server request: $len > 65535");
    };
  # send script to GIMP
  my $header = pack( 'an', 'G', $len);
  syswrite( $sock, $_ ) for ($header, $message);
  # wait for response
  my $rin = '';
  vec( $rin, fileno($sock), 1 ) = 1;
  select( $rin,  undef, undef, undef );    # wait (forever) for response start
  select( undef, undef, undef, .1 );       # wait a bit for response to finish
                                           #  increase wait if INVALID/INCOMPLETE RESPONSE occurs
  # response
  $len = sysread( $sock, $header, 4 ) or &sig_error("INVALID RESPONSE: empty response");
  ( $len == 4 and $header =~ /^G/ ) or &sig_error("INVALID RESPONSE: bad header");
  my $status;
  ($status, $len) = unpack( 'xCn', $header );
  my $response;
  ( sysread( $sock, $response, $len ) == $len ) or &sig_error("INCOMPLETE RESPONSE: $response");
  # exit if response is not "Success"
  if ( $status and $response =~ /^Error: Success\n/i ) {
    &sig_error("UNSUCCESSFUL EXECUTION: Script-fu error");
    }
  $status; 
  }

# define a Script-fu utility function to save frames using the PNG or JPG
# compression levels specified in 'gimprc'. 
# To specify a PNG compression level of 5, include the following line
# in gimprc:
#   (rfx-png-compression "5") 
# If not specified then a default level of "3" is assumed.
# "3" is a good choice for PNGs because higher levels double the write
# times while only offering about 15% reduction in file size.
# To specify a JPG compression level of 85, include the following line
# in gimprc:
#   (rfx-jpg-compression "85") 
# If not specified then a default level of "93" is assumed.

# NOTE: 'rfx-save-frame' DELETES the image.  
&rfx_sendmsg( qq{
  (begin
    (define rfx-curtmpdir "$curtmpdir")
    (define rfx-imgext "$img_ext")
    (unless (defined? 'rfx-save-frame)
      (define rfx-png-compression (catch #f (gimp-gimprc-query "rfx-png-compression")))
      (set! rfx-png-compression (if rfx-png-compression
                                  (string->number (car rfx-png-compression))
                                  3 ))
      (define rfx-jpg-compression (catch #f (gimp-gimprc-query "rfx-jpg-compression")))
      (set! rfx-jpg-compression (if rfx-jpg-compression
                                  (string->number (car rfx-jpg-compression))
                                  93 ))
      (define (rfx-save-frame image basename)
        (let ((filename (string-append rfx-curtmpdir DIR-SEPARATOR basename))
              (layer (car (gimp-image-get-active-layer image))) )
          (if (string-ci=? rfx-imgext ".jpg")
            (begin
              (gimp-context-push)
              (gimp-context-set-background '(6 6 6))
              (let loop ((layers (vector->list (cadr (gimp-image-get-layers image)))))
                (unless (null? layers)
                  (if (= (car layers) layer)
                    (gimp-drawable-set-visible layer TRUE)
                    (gimp-drawable-set-visible (car layers) FALSE) )
                  (loop (cdr layers)) ))
              (set! layer (car (gimp-image-flatten image)))
              (file-jpeg-save RUN-NONINTERACTIVE 
                              image 
                              layer
                              filename 
                              filename 
                              (/ rfx-jpg-compression 100)
                              0 ; smoothing 
                              1 ; optimize 
                              1 ; progressive 
                              "" ; comment 
                              0 ; subsmp (0-4)
                              1 ; baseline 
                              0 ; restart 
                              0 ;dct 
                              )
              (gimp-context-pop) )
            (begin
              (unless (zero? (car (gimp-image-base-type image)))
                (gimp-image-convert-rgb image) )
              (file-png-save2 RUN-NONINTERACTIVE 
                              image 
                              layer
                              filename 
                              filename 
                              FALSE ; interlace
                              rfx-png-compression
                              FALSE ; bkgd
                              (car (gimp-drawable-has-alpha layer))
                              FALSE ; offs
                              FALSE ; phys
                              FALSE ; time
                              TRUE  ; comment
                              FALSE ; svtrans
                              )))
          (gimp-image-delete image) )))
    (define (make-progressor start delta . period)
      (let ((start start)
            (value start)
            (delta delta)
            (period (if (null? period)
                        #f
                        (car period)) ))
        (lambda ()
          (let ((temp value))
            (set! value (if (and period (>= (+ value delta) (+ start period)))
                          (- (+ value delta) period)
                          (+ value delta) ))
            temp ))))
    )
  }
  );
</pre>

<loop>
# $p0 - X center
# $p1 - Y center
# $p2 - direction (0 CW, 1 CCW)
# $p3 - wipe to color
# $p4_red
# $p4_green
# $p4_blue

&rfx_sendmsg (
  qq{
    (begin
      (if (= $frame $start)
        (define next-angle (make-progressor (/ *pi* 2) 
                                            (if (< (- $end $start) 0)
                                              0
                                              (* 2 *pi* (/ (succ (- $end $start)))) )
                                            (* *pi* 2) ))
        (define last-angle (next-angle)) )
      (let* ((input-file (string-append "$curtmpdir" DIR-SEPARATOR "$in"))
             (image (car (gimp-file-load RUN-NONINTERACTIVE input-file input-file)))
             (layer (car (gimp-image-get-active-layer image)))
             (b-layer 0) )
        (if (zero? $p3)
          (let* ((input-file2 (string-append "$in2"))
                 (image2 (car (gimp-file-load RUN-NONINTERACTIVE input-file2 input-file2))) )
            (set! b-layer (car (gimp-layer-new-from-drawable 
                                 (car (gimp-image-get-active-layer image2)) 
                                 image )))
            (gimp-image-add-layer image b-layer 1)
            (gimp-image-delete image2) )
          (begin
            (set! b-layer (car (gimp-layer-new image $width $height 
                                               RGBA-IMAGE "b-layer" 100 NORMAL-MODE )))
            (gimp-context-set-foreground (list $p4_red $p4_green $p4_blue))
            (gimp-drawable-fill b-layer FOREGROUND-FILL)
            (gimp-image-add-layer image b-layer 1) ))
        (gimp-image-undo-disable image)
        (let ((angle (next-angle))
              (mask (car (gimp-layer-create-mask layer ADD-WHITE-MASK))) )
          (gimp-layer-add-mask layer mask)
          (let ((p0x $p0)
                (p0y (- (* 2 $height)))
                (p1x (+ $p0 (* 2 (cos angle) $width)))
                (p1y (- $p1 (* 2 (sin angle) $height))) )
            (gimp-context-set-foreground '(0 0 0))
            (unless (< angle *pi*)
              (gimp-rect-select image 0 0 $p0 $p1 CHANNEL-OP-REPLACE FALSE 0)
              (unless (zero? (car (gimp-selection-bounds image)))
                (gimp-edit-fill mask FOREGROUND-FILL) )
              (set! p0x (- (* 2 $width)))
              (set! p0y $p1) )
            (unless (< angle (* (/ *pi* 2) 3))
              (gimp-rect-select image 0 $p1 $p0 (- $height $p1) CHANNEL-OP-REPLACE FALSE 0)
              (unless (zero? (car (gimp-selection-bounds image)))
                (gimp-edit-fill mask FOREGROUND-FILL) )
              (set! p0x $p0)
              (set! p0y (* 2 $height)) )
            (unless (< angle (* *pi* 2))
              (gimp-rect-select image $p0 $p1 (- $width $p0) (- $height $p1) CHANNEL-OP-REPLACE FALSE 0)
              (unless (zero? (car (gimp-selection-bounds image)))
                (gimp-edit-fill mask FOREGROUND-FILL) )
              (set! p0x (* 2 $width))
              (set! p0y $p1) )
            (gimp-free-select image 6 (vector p0x p0y $p0 $p1 p1x p1y)
                              CHANNEL-OP-REPLACE TRUE FALSE 0 )
            (unless (zero? (car (gimp-selection-bounds image)))
              (gimp-edit-fill mask FOREGROUND-FILL) )
            )
          (gimp-selection-none image)
          (when (zero? $p2)
            (gimp-drawable-transform-flip-simple mask 
                                                 ORIENTATION-HORIZONTAL 
                                                 FALSE 
                                                 $p0 
                                                 TRUE ))
          )
        (gimp-image-merge-visible-layers image CLIP-TO-IMAGE)
        (rfx-save-frame image "$out") 
        )
      )
    }
  );
</loop>

<post>
</post>

<onchange>
init|$p0_max = $width;
init|$p1_max = $height;
init|$p0 = int ($width / 2);
init|$p1 = int ($height / 2);
</onchange>