#!/usr/bin/perl

#######################################################################
# LiVES trim_frames plugin, version 1.7
# RFX version 1.7
# autogenerated from script by Salsaman|

# rendered plugins should accept:
# <plugin_name> version (return <plugin_name> version <version>)
# <plugin_name> get_define
# <plugin_name> get_capabilities
# <plugin_name> get_description (e.g. "Edge detect|Edge detecting|1|1|")
# <plugin_name> clear (clean up any plugin generated temp files)
# and optionally any of: 
# <plugin_name> get_parameters
# <plugin_name> get_param_window
# <plugin_name> get_onchange
# <plugin_name> onchange_<when> (for any triggers, e.g. onchange_init)
#
# they must accept:
# <plugin_name> process <parameters>

# You should not skip any frames, if a frame is not changed you must do:
# `cp $in $out`
#
# for *non-Perl* plugins, LiVES will call:
# <plugin_name> process "<dir>" <in_ext> <out_ext> <start> <end>
#  <width> <height> <parameters>
# first you should chdir to <dir>
# then you should create all output frames %8d$out_ext in numerical 
# from start to end inclusive,
# each time calling sig_progress (see smogrify) - writes current frame number to 
# <dir>/.status
# and checking for pause
#
# Any errors should be transmitted as in sig_error - 
# write "error|msg1|msg2|msg3|" to <dir>/.status
# msgn must not contain "\n", but can be omitted

# output frames should be named %8d$out_ext in the same directory
# after processing, you should leave no gaps in out frames, you should not resize
# or change the palette from RGB24 (LiVES will check and autocorrect this soon)

# Also you must implement your own: &sig_error and &sig_progress


#######################################################################

use POSIX;

my $command=$ARGV[0];

if ($command eq "get_capabilities") {
    # capabilities is a bitmap field
    # 0x0001 == slow (hint to GUI)
    # 0x0002 == may resize (all frames to  x )
    # 0x0004 == block mode generator
    # 0x8000 == reserved
    print "32770\n";
    exit 0;
}

if ($command eq "version") {
    print "trim_frames version 4 : builder version 1.0.10\n";
    exit 0;
}

if ($command eq "get_define") {
    print "|1.7\n";
    exit 0;
}

if ($command eq "get_description") {
    #format here is "Menu entry|Action description|min_frames|number_of_in_channels|"
    # min_frames==-1 indicates a special "no processing" effect. This allows more
    #general parameter windows which are not really effects (e.g. frame_calculator)
    print "Trim frames/Add border|Trimming|1|1|\n";
    exit 0;
}


if ($command eq "get_parameters") {
    # "name|label|type|other fields..."
    # eg. print "radius|_radius|num0|1|1|100|";
    # types can be numx,colRGB24,bool,string or string_list
    print "xstart|_X Start|num0|0|0|10000|\n";
    print "ystart|_Y Start|num0|0|0|10000|\n";
    print "xend|_X End|num0|0|0|10000|\n";
    print "yend|_Y End|num0|0|0|10000|\n";
    print "kc|Keep _Centered|bool|0|\n";
    print "w|_Width|num0|0|0|10000|\n";
    print "h|_Height|num0|0|0|10000|\n";
    print "bord|Add _Border|bool|0|\n";
    print "offsx|_Offset X|num0|0|0|10000|\n";
    print "offsy|_Offset Y|num0|0|0|10000|\n";
    print "bordc|Border _Colour|colRGB24|0|0|0|\n";
    exit 0;
}

if ($command eq "get_param_window") {
    print "layout|p0|p1||\n";
    print "layout|p2|p3||\n";
    print "layout|p4||\n";
    print "special|framedraw|rectdemask|0|1|2|3||\n";
    print "layout|hseparator||\n";
    print "layout|p7|p5|p6||\n";
    print "layout|\"Offset of frame within border\"|p8|p9||\n";
    print "special|aspect|5|6||\n";
    exit 0;
}

if ($command eq "get_onchange") {
    print "init|\n";
    print "0|\n";
    print "1|\n";
    print "2|\n";
    print "3|\n";
    print "5|\n";
    print "6|\n";
    print "4|\n";
    exit 0;
}

#######################################################

if ($command eq "process") {

# in case of error, you should do:
# &sig_error("msg1","msg2","msg3","msg4"); [ msg's are optional, but must not
# contain newlines (\n) ]

##### check requirements first #######
    if (&location("convert") eq "") {
      &sig_error("You must install 'convert' before you can use this effect.");
      exit 1;
    }

###### handle parameters #############
# autogenerated from get_parameters

    unless (defined($ARGV[1])) {
      $p0=0;
    }
    else {
      $p0=$ARGV[1];
    }
    unless (defined($ARGV[2])) {
      $p1=0;
    }
    else {
      $p1=$ARGV[2];
    }
    unless (defined($ARGV[3])) {
      $p2=0;
    }
    else {
      $p2=$ARGV[3];
    }
    unless (defined($ARGV[4])) {
      $p3=0;
    }
    else {
      $p3=$ARGV[4];
    }
    unless (defined($ARGV[5])) {
      $p4=0;
    }
    else {
      $p4=$ARGV[5];
    }
    unless (defined($ARGV[6])) {
      $p5=0;
    }
    else {
      $p5=$ARGV[6];
    }
    unless (defined($ARGV[7])) {
      $p6=0;
    }
    else {
      $p6=$ARGV[7];
    }
    unless (defined($ARGV[8])) {
      $p7=0;
    }
    else {
      $p7=$ARGV[8];
    }
    unless (defined($ARGV[9])) {
      $p8=0;
    }
    else {
      $p8=$ARGV[9];
    }
    unless (defined($ARGV[10])) {
      $p9=0;
    }
    else {
      $p9=$ARGV[10];
    }
    unless (defined($ARGV[11])) {
      $p10=0;
    }
    else {
      $p10=$ARGV[11];
    }
    $!=0;
    $p0=int(POSIX::strtod($p0)*1+.5)/1;
    if ($p0<0) {
       &sig_error("xstart must be >= 0");
       exit 1;
    }
    if ($p0>10000) {
       &sig_error("xstart must be <= 10000");
       exit 1;
    }
    $!=0;
    $p1=int(POSIX::strtod($p1)*1+.5)/1;
    if ($p1<0) {
       &sig_error("ystart must be >= 0");
       exit 1;
    }
    if ($p1>10000) {
       &sig_error("ystart must be <= 10000");
       exit 1;
    }
    $!=0;
    $p2=int(POSIX::strtod($p2)*1+.5)/1;
    if ($p2<0) {
       &sig_error("xend must be >= 0");
       exit 1;
    }
    if ($p2>10000) {
       &sig_error("xend must be <= 10000");
       exit 1;
    }
    $!=0;
    $p3=int(POSIX::strtod($p3)*1+.5)/1;
    if ($p3<0) {
       &sig_error("yend must be >= 0");
       exit 1;
    }
    if ($p3>10000) {
       &sig_error("yend must be <= 10000");
       exit 1;
    }
    $p4=~(~$p4);
    $!=0;
    $p5=int(POSIX::strtod($p5)*1+.5)/1;
    if ($p5<0) {
       &sig_error("w must be >= 0");
       exit 1;
    }
    if ($p5>10000) {
       &sig_error("w must be <= 10000");
       exit 1;
    }
    $!=0;
    $p6=int(POSIX::strtod($p6)*1+.5)/1;
    if ($p6<0) {
       &sig_error("h must be >= 0");
       exit 1;
    }
    if ($p6>10000) {
       &sig_error("h must be <= 10000");
       exit 1;
    }
    $p7=~(~$p7);
    $!=0;
    $p8=int(POSIX::strtod($p8)*1+.5)/1;
    if ($p8<0) {
       &sig_error("offsx must be >= 0");
       exit 1;
    }
    if ($p8>10000) {
       &sig_error("offsx must be <= 10000");
       exit 1;
    }
    $!=0;
    $p9=int(POSIX::strtod($p9)*1+.5)/1;
    if ($p9<0) {
       &sig_error("offsy must be >= 0");
       exit 1;
    }
    if ($p9>10000) {
       &sig_error("offsy must be <= 10000");
       exit 1;
    }
$p10=int($p10);
if ($p10>0xFFFFFF||$p10<0) {
    &sig_error("Invalid colour for bordc.");
    exit 1;
}
$p10_red=int($p10/65536);
$p10-=$p10_red*65536;
$p10_green=int($p10/256);
$p10-=$p10_green*256;
$p10_blue=$p10;

    $antialias=&rc_get("antialias");
    $resize_ext=$out_ext;
    $xwidth=$nwidth=$p2-$p0+1;
    $xheight=$nheight=$p3-$p1+1;
    if ($nwidth<1||$nwidth>$width) {
       &sig_error("New width is invalid.");
    }
    if ($nheight<1||$nheight>$height) {
       &sig_error("New height is invalid.");
    }
    
    if ($p7) {
        $cstring1=&RGB24_to_string($p10_red,$p10_green,$p10_blue);
        system("$convert_command -size $p5!x$p6! xc:$cstring1 blank$img_ext");
        $nwidth=$p5;
        $nheight=$p6;
    }

################# loop through frames #################
    for ($frame=$start;$frame<=$end;$frame++) {
	# sig progress will update the progress bar from $start->$end
	$name=&mkname($frame);
	$in="$name$img_ext";
	$out="$name$out_ext";

 while (! -f $in) {
     sleep 1;
 }

##################### the all-important bit #######################

        &trim_frame($name,$width,$height,$p0,$p1,$nwidth,$nheight);
        if ($p7) {	
            system("$composite_command -compose plus -dissolve 100 -geometry $xwidth!x$xheight!+$p8!+$p9! $out -size $p5!x$p6! blank$img_ext $out");
        }

###################################################################
        if (! -f $out) {
            print STDERR "Warning: effect plugin trim_frames skipped frame $frame !";
            `cp $in $out`;
        }
	&sig_progress($frame);
        if ($p10_red>255) {
            $p10_red=255;
        }
        elsif ($p10_red<0) {
            $p10_red=0;
        }
        if ($p10_green>255) {
            $p10_green=255;
        }
        elsif ($p10_green<0) {
            $p10_green=0;
        }
        if ($p10_blue>255) {
            $p10_blue=255;
        }
        elsif ($p10_blue<0) {
            $p10_blue=0;
        }
    }
    return 1;
}



########## Post loop code ############
if ($command eq "clear") {
    if (-f "blank$img_ext") {
        unlink ("blank$img_ext");
    }
}

########## Triggers ############

if ($command eq "onchange_6") {
    $p0=@ARGV[1];
    $p0_min=@ARGV[2];
    $p0_max=@ARGV[3];
    $p1=@ARGV[4];
    $p1_min=@ARGV[5];
    $p1_max=@ARGV[6];
    $p2=@ARGV[7];
    $p2_min=@ARGV[8];
    $p2_max=@ARGV[9];
    $p3=@ARGV[10];
    $p3_min=@ARGV[11];
    $p3_max=@ARGV[12];
    $p4=@ARGV[13];
    $p5=@ARGV[14];
    $p5_min=@ARGV[15];
    $p5_max=@ARGV[16];
    $p6=@ARGV[17];
    $p6_min=@ARGV[18];
    $p6_max=@ARGV[19];
    $p7=@ARGV[20];
    $p8=@ARGV[21];
    $p8_min=@ARGV[22];
    $p8_max=@ARGV[23];
    $p9=@ARGV[24];
    $p9_min=@ARGV[25];
    $p9_max=@ARGV[26];
    $p10_red=@ARGV[27];
    $p10_green=@ARGV[28];
    $p10_blue=@ARGV[29];
    $width=@ARGV[30];
    $height=@ARGV[31];
    $start=@ARGV[32];
    $end=@ARGV[33];
    $last=@ARGV[34];
    $length=$end-$start+1;

    $p9_max=$p6-$p3+$p1-1;
    if ($p4) {$p9=int(($p6-$p1_max)/2.+$p1);}
    $p7=1;

    print "$p0 $p0_min $p0_max $p1 $p1_min $p1_max $p2 $p2_min $p2_max $p3 $p3_min $p3_max $p4 $p5 $p5_min $p5_max $p6 $p6_min $p6_max $p7 $p8 $p8_min $p8_max $p9 $p9_min $p9_max $p10_red $p10_green $p10_blue ";
    exit 0;
}

if ($command eq "onchange_3") {
    $p0=@ARGV[1];
    $p0_min=@ARGV[2];
    $p0_max=@ARGV[3];
    $p1=@ARGV[4];
    $p1_min=@ARGV[5];
    $p1_max=@ARGV[6];
    $p2=@ARGV[7];
    $p2_min=@ARGV[8];
    $p2_max=@ARGV[9];
    $p3=@ARGV[10];
    $p3_min=@ARGV[11];
    $p3_max=@ARGV[12];
    $p4=@ARGV[13];
    $p5=@ARGV[14];
    $p5_min=@ARGV[15];
    $p5_max=@ARGV[16];
    $p6=@ARGV[17];
    $p6_min=@ARGV[18];
    $p6_max=@ARGV[19];
    $p7=@ARGV[20];
    $p8=@ARGV[21];
    $p8_min=@ARGV[22];
    $p8_max=@ARGV[23];
    $p9=@ARGV[24];
    $p9_min=@ARGV[25];
    $p9_max=@ARGV[26];
    $p10_red=@ARGV[27];
    $p10_green=@ARGV[28];
    $p10_blue=@ARGV[29];
    $width=@ARGV[30];
    $height=@ARGV[31];
    $start=@ARGV[32];
    $end=@ARGV[33];
    $last=@ARGV[34];
    $length=$end-$start+1;

    $p9_max=$p6-$p3+$p1-1;
    if ($p4) {$p1=$height-1-$p3;$p9=int(($p6-$p1_max)/2.+$p1);}
    if ($p3<$p1) {$p1=$p3;}
    $p6_min=$p3-$p1+1;

    print "$p0 $p0_min $p0_max $p1 $p1_min $p1_max $p2 $p2_min $p2_max $p3 $p3_min $p3_max $p4 $p5 $p5_min $p5_max $p6 $p6_min $p6_max $p7 $p8 $p8_min $p8_max $p9 $p9_min $p9_max $p10_red $p10_green $p10_blue ";
    exit 0;
}

if ($command eq "onchange_2") {
    $p0=@ARGV[1];
    $p0_min=@ARGV[2];
    $p0_max=@ARGV[3];
    $p1=@ARGV[4];
    $p1_min=@ARGV[5];
    $p1_max=@ARGV[6];
    $p2=@ARGV[7];
    $p2_min=@ARGV[8];
    $p2_max=@ARGV[9];
    $p3=@ARGV[10];
    $p3_min=@ARGV[11];
    $p3_max=@ARGV[12];
    $p4=@ARGV[13];
    $p5=@ARGV[14];
    $p5_min=@ARGV[15];
    $p5_max=@ARGV[16];
    $p6=@ARGV[17];
    $p6_min=@ARGV[18];
    $p6_max=@ARGV[19];
    $p7=@ARGV[20];
    $p8=@ARGV[21];
    $p8_min=@ARGV[22];
    $p8_max=@ARGV[23];
    $p9=@ARGV[24];
    $p9_min=@ARGV[25];
    $p9_max=@ARGV[26];
    $p10_red=@ARGV[27];
    $p10_green=@ARGV[28];
    $p10_blue=@ARGV[29];
    $width=@ARGV[30];
    $height=@ARGV[31];
    $start=@ARGV[32];
    $end=@ARGV[33];
    $last=@ARGV[34];
    $length=$end-$start+1;

    $p8_max=$p5-$p2+$p0-1;
    if ($p4) {$p0=$width-1-$p2;$p8=int(($p5-$p0_max)/2.+$p0);}
    if ($p2<$p0) {$p0=$p2;}
    $p5_min=$p2-$p0+1;

    print "$p0 $p0_min $p0_max $p1 $p1_min $p1_max $p2 $p2_min $p2_max $p3 $p3_min $p3_max $p4 $p5 $p5_min $p5_max $p6 $p6_min $p6_max $p7 $p8 $p8_min $p8_max $p9 $p9_min $p9_max $p10_red $p10_green $p10_blue ";
    exit 0;
}

if ($command eq "onchange_init") {
    $p0=@ARGV[1];
    $p0_min=@ARGV[2];
    $p0_max=@ARGV[3];
    $p1=@ARGV[4];
    $p1_min=@ARGV[5];
    $p1_max=@ARGV[6];
    $p2=@ARGV[7];
    $p2_min=@ARGV[8];
    $p2_max=@ARGV[9];
    $p3=@ARGV[10];
    $p3_min=@ARGV[11];
    $p3_max=@ARGV[12];
    $p4=@ARGV[13];
    $p5=@ARGV[14];
    $p5_min=@ARGV[15];
    $p5_max=@ARGV[16];
    $p6=@ARGV[17];
    $p6_min=@ARGV[18];
    $p6_max=@ARGV[19];
    $p7=@ARGV[20];
    $p8=@ARGV[21];
    $p8_min=@ARGV[22];
    $p8_max=@ARGV[23];
    $p9=@ARGV[24];
    $p9_min=@ARGV[25];
    $p9_max=@ARGV[26];
    $p10_red=@ARGV[27];
    $p10_green=@ARGV[28];
    $p10_blue=@ARGV[29];
    $width=@ARGV[30];
    $height=@ARGV[31];
    $start=@ARGV[32];
    $end=@ARGV[33];
    $last=@ARGV[34];
    $length=$end-$start+1;

    $p0_max=$p2_max=$width-1;
    $p1_max=$p3_max=$height-1;
    $p5=$width;$p6=$height;

    print "$p0 $p0_min $p0_max $p1 $p1_min $p1_max $p2 $p2_min $p2_max $p3 $p3_min $p3_max $p4 $p5 $p5_min $p5_max $p6 $p6_min $p6_max $p7 $p8 $p8_min $p8_max $p9 $p9_min $p9_max $p10_red $p10_green $p10_blue ";
    exit 0;
}

if ($command eq "onchange_4") {
    $p0=@ARGV[1];
    $p0_min=@ARGV[2];
    $p0_max=@ARGV[3];
    $p1=@ARGV[4];
    $p1_min=@ARGV[5];
    $p1_max=@ARGV[6];
    $p2=@ARGV[7];
    $p2_min=@ARGV[8];
    $p2_max=@ARGV[9];
    $p3=@ARGV[10];
    $p3_min=@ARGV[11];
    $p3_max=@ARGV[12];
    $p4=@ARGV[13];
    $p5=@ARGV[14];
    $p5_min=@ARGV[15];
    $p5_max=@ARGV[16];
    $p6=@ARGV[17];
    $p6_min=@ARGV[18];
    $p6_max=@ARGV[19];
    $p7=@ARGV[20];
    $p8=@ARGV[21];
    $p8_min=@ARGV[22];
    $p8_max=@ARGV[23];
    $p9=@ARGV[24];
    $p9_min=@ARGV[25];
    $p9_max=@ARGV[26];
    $p10_red=@ARGV[27];
    $p10_green=@ARGV[28];
    $p10_blue=@ARGV[29];
    $width=@ARGV[30];
    $height=@ARGV[31];
    $start=@ARGV[32];
    $end=@ARGV[33];
    $last=@ARGV[34];
    $length=$end-$start+1;

    if ($p4) {
     if ($p0<=$width/2) {
         $p2=$width-1-$p0;
        }
      else {
        $p0=$width-1-$p2;
      }
     if ($p1<=$height/2) {
        $p3=$height-1-$p1;
     }
      else {
        $p1=$height-1-$p3;
      }
    }

    print "$p0 $p0_min $p0_max $p1 $p1_min $p1_max $p2 $p2_min $p2_max $p3 $p3_min $p3_max $p4 $p5 $p5_min $p5_max $p6 $p6_min $p6_max $p7 $p8 $p8_min $p8_max $p9 $p9_min $p9_max $p10_red $p10_green $p10_blue ";
    exit 0;
}

if ($command eq "onchange_1") {
    $p0=@ARGV[1];
    $p0_min=@ARGV[2];
    $p0_max=@ARGV[3];
    $p1=@ARGV[4];
    $p1_min=@ARGV[5];
    $p1_max=@ARGV[6];
    $p2=@ARGV[7];
    $p2_min=@ARGV[8];
    $p2_max=@ARGV[9];
    $p3=@ARGV[10];
    $p3_min=@ARGV[11];
    $p3_max=@ARGV[12];
    $p4=@ARGV[13];
    $p5=@ARGV[14];
    $p5_min=@ARGV[15];
    $p5_max=@ARGV[16];
    $p6=@ARGV[17];
    $p6_min=@ARGV[18];
    $p6_max=@ARGV[19];
    $p7=@ARGV[20];
    $p8=@ARGV[21];
    $p8_min=@ARGV[22];
    $p8_max=@ARGV[23];
    $p9=@ARGV[24];
    $p9_min=@ARGV[25];
    $p9_max=@ARGV[26];
    $p10_red=@ARGV[27];
    $p10_green=@ARGV[28];
    $p10_blue=@ARGV[29];
    $width=@ARGV[30];
    $height=@ARGV[31];
    $start=@ARGV[32];
    $end=@ARGV[33];
    $last=@ARGV[34];
    $length=$end-$start+1;

    $p9_max=$p6-$p3+$p1-1;
    if ($p4) {$p3=$height-1-$p1;$p9=int(($p6-$p1_max)/2.+$p1);}
    if ($p1>$p3) {$p3=$p1;}
    $p6_min=$p3-$p1+1;
    if ($p6==$height&&!$p4) {$p9=$p1;}

    print "$p0 $p0_min $p0_max $p1 $p1_min $p1_max $p2 $p2_min $p2_max $p3 $p3_min $p3_max $p4 $p5 $p5_min $p5_max $p6 $p6_min $p6_max $p7 $p8 $p8_min $p8_max $p9 $p9_min $p9_max $p10_red $p10_green $p10_blue ";
    exit 0;
}

if ($command eq "onchange_0") {
    $p0=@ARGV[1];
    $p0_min=@ARGV[2];
    $p0_max=@ARGV[3];
    $p1=@ARGV[4];
    $p1_min=@ARGV[5];
    $p1_max=@ARGV[6];
    $p2=@ARGV[7];
    $p2_min=@ARGV[8];
    $p2_max=@ARGV[9];
    $p3=@ARGV[10];
    $p3_min=@ARGV[11];
    $p3_max=@ARGV[12];
    $p4=@ARGV[13];
    $p5=@ARGV[14];
    $p5_min=@ARGV[15];
    $p5_max=@ARGV[16];
    $p6=@ARGV[17];
    $p6_min=@ARGV[18];
    $p6_max=@ARGV[19];
    $p7=@ARGV[20];
    $p8=@ARGV[21];
    $p8_min=@ARGV[22];
    $p8_max=@ARGV[23];
    $p9=@ARGV[24];
    $p9_min=@ARGV[25];
    $p9_max=@ARGV[26];
    $p10_red=@ARGV[27];
    $p10_green=@ARGV[28];
    $p10_blue=@ARGV[29];
    $width=@ARGV[30];
    $height=@ARGV[31];
    $start=@ARGV[32];
    $end=@ARGV[33];
    $last=@ARGV[34];
    $length=$end-$start+1;

    $p8_max=$p5-$p2+$p0-1;
    if ($p4) {$p2=$width-1-$p0;$p8=int(($p5-$p0_max)/2.+$p0);}
    if ($p0>$p2) {$p2=$p0;}
    if ($p5==$width&&!$p4) {$p8=$p0;}
    $p5_min=$p2-$p0+1;

    print "$p0 $p0_min $p0_max $p1 $p1_min $p1_max $p2 $p2_min $p2_max $p3 $p3_min $p3_max $p4 $p5 $p5_min $p5_max $p6 $p6_min $p6_max $p7 $p8 $p8_min $p8_max $p9 $p9_min $p9_max $p10_red $p10_green $p10_blue ";
    exit 0;
}

if ($command eq "onchange_5") {
    $p0=@ARGV[1];
    $p0_min=@ARGV[2];
    $p0_max=@ARGV[3];
    $p1=@ARGV[4];
    $p1_min=@ARGV[5];
    $p1_max=@ARGV[6];
    $p2=@ARGV[7];
    $p2_min=@ARGV[8];
    $p2_max=@ARGV[9];
    $p3=@ARGV[10];
    $p3_min=@ARGV[11];
    $p3_max=@ARGV[12];
    $p4=@ARGV[13];
    $p5=@ARGV[14];
    $p5_min=@ARGV[15];
    $p5_max=@ARGV[16];
    $p6=@ARGV[17];
    $p6_min=@ARGV[18];
    $p6_max=@ARGV[19];
    $p7=@ARGV[20];
    $p8=@ARGV[21];
    $p8_min=@ARGV[22];
    $p8_max=@ARGV[23];
    $p9=@ARGV[24];
    $p9_min=@ARGV[25];
    $p9_max=@ARGV[26];
    $p10_red=@ARGV[27];
    $p10_green=@ARGV[28];
    $p10_blue=@ARGV[29];
    $width=@ARGV[30];
    $height=@ARGV[31];
    $start=@ARGV[32];
    $end=@ARGV[33];
    $last=@ARGV[34];
    $length=$end-$start+1;

    $p8_max=$p5-$p2+$p0-1;
    if ($p4) {$p8=int(($p5-$p0_max)/2.+$p0);}
    $p7=1;

    print "$p0 $p0_min $p0_max $p1 $p1_min $p1_max $p2 $p2_min $p2_max $p3 $p3_min $p3_max $p4 $p5 $p5_min $p5_max $p6 $p6_min $p6_max $p7 $p8 $p8_min $p8_max $p9 $p9_min $p9_max $p10_red $p10_green $p10_blue ";
    exit 0;
}
