#!/usr/bin/perl

eval 'exec /usr/bin/perl  -S $0 ${1+"$@"}'
    if 0; # not running under some shell

use Gimp qw(:auto __ N_);
use Gimp::Fu;
use Gimp::Util;

N_"/Filters/Logulator";  # workaround for i18n weirdnesses

#Gimp::set_trace(TRACE_CALL);

my $global_drawable;

sub register($$$$$$$$$;@) {
   my($function,$blurb,$help,$author,$copyright,$date,
      $menupath,$imagetypes,$params,$code)=@_;
   $function =~ s%^perl_fu_%logulator_% or die;
   $imagetypes ||= "RGBA,GRAYA,INDEXEDA";
   my($i,$j)=0;
   my($ti,$fsi,$fi);
   $i=@$params;
   while($i--) {
      local $_ = $params->[$i];
      if($_->[1] =~ /text_string/i &&!defined $ti) {
         $ti=$i;
         splice @$params,$i,1;
      } elsif ($_->[1] =~ /font_size_pixels/i &&!defined $fsi) {
         $fsi=$i;
         splice @$params,$i,1;
      } elsif ($_->[1] =~ /font/i &&!defined $fi) {
         $fi=$i;
         splice @$params,$i,1;
      }
   }
   defined($ti) and defined($fsi) and defined($fi) or die "$function, $menupath: no identifiable font ($ti $fsi $fi)\n";

   $menupath =~ /([^\/]+)$/;
   $menupath =~ s/\.*$/.../;
   $help=<<EOF.$help;

This "script" is actually a script-fu logo script that has been converted
to perl. Instead of producing a logo from a text string (nice but rather
limited in the shapes you can create) it uses the drawable you specified
as the text shape. Any colour that the plug-in tries to use is ignored,
which allows you to create multi-colour text.

The drawable must have an alpha channel, and the shape of this channel
prescribes the shape of the logo. Most logos ignore any colour information
and instead use the shape only as a stencil, but some logo scripts do make
use of the text colour.

The original help for $1 follows:

EOF
   
   Gimp::Fu::register($function,$blurb,$help,$author,$copyright,$date,
                      $menupath,$imagetypes,$params,sub{
      my($image,$drawable)=(shift,shift);
      $drawable->has_alpha or die "It makes no sense to call $menupath with a drawable lacking alpha!\n";
      $i=0;
      while($i<=@_) {
         if($i==$ti) {
            splice @_,$i,0,"-- Text --";
         } elsif ($i==$fsi) {
            splice @_,$i,0,$drawable->height;
         } elsif ($i==$fi) {
            splice @_,$i,0,"-*-helvetica-medium-r-normal-*-24-*-*-*-p-*-iso8859-1";
         }
         $i++;
      }
      $global_drawable=$drawable;
      &$code;
      ();
   });
}

sub gimp_text {
   die "gimp_text not yet supported\n";
}

sub gimp_text_get_extents {
   die "gimp_text_get_extents not yet supported\n";
}

# just return the width/height of the drawable instead
sub gimp_text_get_extents_fontname {
   my($text,$size,$size_type,$fontname)=@_;
   ($global_drawable->width,$global_drawable->height,$global_drawable->height,0);
}

# instead of the text layer, just return a copy of the drawable
sub gimp_text_fontname {
   my($image,$layer,$x,$y,$text,$border,$antialias,$height,$size_type,$fontname)=@_;
   $global_drawable->image->selection_all;
   $global_drawable->edit_copy;
   my $newlay;
   if ($layer == -1) {
      $newlay=$image->layer_new($global_drawable->width,$global_drawable->height,
                                $image->layertype(1), $text || "--text--", 100, NORMAL_MODE);
      $newlay->drawable_fill(TRANS_IMAGE_FILL);
      $newlay->add_layer(0);
      $newlay->edit_paste(0)->floating_sel_anchor;
   } else {
      $newlay = $layer->edit_paste(0);
   }
   $newlay;
}

# script-fu convenience functions

sub cdr {
   my(@x)=@{$_[0]};
   shift(@x);
   @x >1 ? [@x] : $x[0];
}

sub number2string {
   sprintf "%$_[1]d",$_[0];
}

sub nth {
   $_[1]->[$_[0]];
}

sub min {
   $_[0] < $_[1] ? $_[0] : $_[1];
}

sub max {
   $_[0] > $_[1] ? $_[0] : $_[1];
}

#############################################################################
# converted scripts start here
#############################################################################

sub carve_brush {
   my ($brush_size) = @_;
   $brush_size <= 5 ? "Circle (05)"
      : $brush_size <= 7 ? "Circle (07)"
      : $brush_size <= 9 ? "Circle (09)"
      : $brush_size <= 11 ? "Circle (11)"
      : $brush_size <= 13 ? "Circle (13)"
      : $brush_size <= 15 ? "Circle (15)"
      : $brush_size <= 17 ? "Circle (17)"
      : $brush_size > 17 ? "Circle (19)"
      : die 'cond fell off the end';
}

sub carve_scale {
   my ($val, $scale) = @_;
   sqrt ($val) * $scale;
}

sub calculate_inset_gamma {
   my ($img, $layer) = @_;
   do {
      my $stats = [gimp_histogram ($layer, 0, 0, 255)];
      my $mean = @{$stats}[0];
      
      $mean < 127 ? (1.0 + 0.5 * (127 - $mean) / 127.0)
         : $mean >= 127 ? (1.0 - 0.5 * ($mean - 127) / 127.0)
         : die 'cond fell off the end';
   };
}

sub script_fu_carved_logo {
   my ($text, $size, $font, $bg_img, $carve_raised) = @_;
   do {
      my $img = gimp_file_load ($bg_img, $bg_img);
      my $offx = carve_scale ($size, 0.33);
      my $offy = carve_scale ($size, 0.25);
      my $feather = carve_scale ($size, 0.3);
      my $brush_size = carve_scale ($size, 0.3);
      my $b_size = carve_scale ($size, 1.5);
      my $layer1 = gimp_image_active_drawable ($img);
      my $mask_layer = gimp_text_fontname ($img, -1, 0, 0, $text, $b_size, 1, $size, PIXELS, $font);
      my $width = gimp_drawable_width ($mask_layer);
      my $height = gimp_drawable_height ($mask_layer);
      my $mask_fs = 0;
      my $mask = gimp_channel_new ($img, $width, $height, "Engraving Mask", 50, [0, 0, 0]);
      my $inset_gamma = calculate_inset_gamma ($img, $layer1);
      my $mask_fat = 0;
      my $mask_emboss = 0;
      my $mask_highlight = 0;
      my $mask_shadow = 0;
      my $shadow_layer = 0;
      my $highlight_layer = 0;
      my $cast_shadow_layer = 0;
      my $csl_mask = 0;
      my $inset_layer = 0;
      my $il_mask = 0;
      my $old_fg = gimp_palette_get_foreground ();
      my $old_bg = gimp_palette_get_background ();
      my $old_brush = gimp_brushes_get_brush ();
      
      gimp_image_undo_disable ($img);
      gimp_layer_set_preserve_trans ($mask_layer, 1);
      gimp_palette_set_background ([255, 255, 255]);
      gimp_edit_fill ($mask_layer, BG_IMAGE_FILL);
      gimp_palette_set_background ([0, 0, 0]);
      gimp_edit_fill ($mask, BG_IMAGE_FILL);
      plug_in_tile ($img, $layer1, $width, $height, 0);
      gimp_image_add_channel ($img, $mask, 0);
      gimp_edit_copy ($mask_layer);
      $mask_fs = gimp_edit_paste ($mask, 0);
      gimp_floating_sel_anchor ($mask_fs);
      if ($carve_raised) {
         gimp_invert ($mask);
      }
      gimp_image_remove_layer ($img, $mask_layer);
      $mask_fat = gimp_channel_copy ($mask);
      gimp_image_add_channel ($img, $mask_fat, 0);
      gimp_selection_load ($mask_fat);
      gimp_brushes_set_brush (carve_brush ($brush_size));
      gimp_palette_set_foreground ([255, 255, 255]);
      gimp_edit_stroke ($mask_fat);
      gimp_selection_none ($img);
      $mask_emboss = gimp_channel_copy ($mask_fat);
      gimp_image_add_channel ($img, $mask_emboss, 0);
      plug_in_gauss_rle ($img, $mask_emboss, $feather, 1, 1);
      plug_in_emboss ($img, $mask_emboss, 315.0, 45.0, 7, 1);
      gimp_palette_set_background ([180, 180, 180]);
      gimp_selection_load ($mask_fat);
      gimp_selection_invert ($img);
      gimp_edit_fill ($mask_emboss, BG_IMAGE_FILL);
      gimp_selection_load ($mask);
      gimp_edit_fill ($mask_emboss, BG_IMAGE_FILL);
      gimp_selection_none ($img);
      $mask_highlight = gimp_channel_copy ($mask_emboss);
      gimp_image_add_channel ($img, $mask_highlight, 0);
      gimp_levels ($mask_highlight, 0, 180, 255, 1.0, 0, 255);
      $mask_shadow = $mask_emboss;
      gimp_levels ($mask_shadow, 0, 0, 180, 1.0, 0, 255);
      gimp_edit_copy ($mask_shadow);
      $shadow_layer = gimp_edit_paste ($layer1, 0);
      gimp_floating_sel_to_layer ($shadow_layer);
      gimp_layer_set_mode ($shadow_layer, MULTIPLY_MODE);
      gimp_edit_copy ($mask_highlight);
      $highlight_layer = gimp_edit_paste ($shadow_layer, 0);
      gimp_floating_sel_to_layer ($highlight_layer);
      gimp_layer_set_mode ($highlight_layer, SCREEN_MODE);
      gimp_edit_copy ($mask);
      $cast_shadow_layer = gimp_edit_paste ($highlight_layer, 0);
      gimp_floating_sel_to_layer ($cast_shadow_layer);
      gimp_layer_set_mode ($cast_shadow_layer, MULTIPLY_MODE);
      gimp_layer_set_opacity ($cast_shadow_layer, 75);
      plug_in_gauss_rle ($img, $cast_shadow_layer, $feather, 1, 1);
      gimp_layer_translate ($cast_shadow_layer, $offx, $offy);
      $csl_mask = gimp_layer_create_mask ($cast_shadow_layer, BLACK_MASK);
      gimp_image_add_layer_mask ($img, $cast_shadow_layer, $csl_mask);
      gimp_selection_load ($mask);
      gimp_palette_set_background ([255, 255, 255]);
      gimp_edit_fill ($csl_mask, BG_IMAGE_FILL);
      $inset_layer = gimp_layer_copy ($layer1, 1);
      gimp_image_add_layer ($img, $inset_layer, 1);
      $il_mask = gimp_layer_create_mask ($inset_layer, BLACK_MASK);
      gimp_image_add_layer_mask ($img, $inset_layer, $il_mask);
      gimp_selection_load ($mask);
      gimp_palette_set_background ([255, 255, 255]);
      gimp_edit_fill ($il_mask, BG_IMAGE_FILL);
      gimp_selection_none ($img);
      gimp_levels ($inset_layer, 0, 0, 255, $inset_gamma, 0, 255);
      gimp_image_remove_channel ($img, $mask);
      gimp_image_remove_channel ($img, $mask_fat);
      gimp_image_remove_channel ($img, $mask_highlight);
      gimp_image_remove_channel ($img, $mask_shadow);
      gimp_layer_set_name ($layer1, "Carved Surface");
      gimp_layer_set_name ($shadow_layer, "Bevel Shadow");
      gimp_layer_set_name ($highlight_layer, "Bevel Highlight");
      gimp_layer_set_name ($cast_shadow_layer, "Cast Shadow");
      gimp_layer_set_name ($inset_layer, "Inset");
      gimp_palette_set_foreground ($old_fg);
      gimp_palette_set_background ($old_bg);
      gimp_brushes_set_brush ($old_brush);
      gimp_display_new ($img);
      gimp_image_undo_enable ($img);
   };
}

register "perl_fu_carved_logo",
   "Carve the text from the specified image. The image will be automatically tiled to accomodate the rendered text string. The \"Carve Raised Text\" parameter determines whether to carve the text itself, or around the text.",
   "Carve the text from the specified image. The image will be automatically tiled to accomodate the rendered text string. The \"Carve Raised Text\" parameter determines whether to carve the text itself, or around the text.",
   "Spencer Kimball",
   "Spencer Kimball",
   "1997",
   N_"<Image>/Filters/Logulator/Carved",
   "",
   [
      [PF_STRING,    'text_string',      "Text String", "Marble"],
      [PF_ADJUSTMENT,'font_size_pixels', "Font Size (pixels)", [100, 2, 1000, 1, 10, 0, 1]],
      [PF_FONT,      'font',             "Font", "-*-Engraver-*-r-*-*-24-*-*-*-p-*-*-*"],
      [PF_FILE,      'background_img',   "Background Img", "".'/usr/local/share/gimp/1.1'."/scripts/texture3.jpg"],
      [PF_TOGGLE,    'carve_raised_text',"Carve Raised Text", 0],
   ],
   \&script_fu_carved_logo;

sub set_pt {
   my ($a, $index, $x, $y) = @_;
   do {
      $a->[$index * 2] = $x;
      $a->[($index * 2 + 1)] = $y;
   };
}

sub spline1 {
   
   do {
      my $a = (18,"byte",[]);
      
      set_pt ($a, 0, 0, 0);
      set_pt ($a, 1, 31, 235);
      set_pt ($a, 2, 63, 23);
      set_pt ($a, 3, 95, 230);
      set_pt ($a, 4, 127, 25);
      set_pt ($a, 5, 159, 210);
      set_pt ($a, 6, 191, 20);
      set_pt ($a, 7, 223, 240);
      set_pt ($a, 8, 255, 31);
      $a;
   };
}

sub crystal_brush {
   my ($brush_size) = @_;
   $brush_size <= 5 ? "Circle (05)"
      : $brush_size <= 7 ? "Circle (07)"
      : $brush_size <= 9 ? "Circle (09)"
      : $brush_size <= 11 ? "Circle (11)"
      : $brush_size <= 13 ? "Circle (13)"
      : $brush_size <= 15 ? "Circle (15)"
      : $brush_size <= 17 ? "Circle (17)"
      : "Circle Fuzzy (19)";
}

sub shadows {
   my ($val) = @_;
   0.96 * $val / 2.55;
}

sub midtones {
   my ($val) = @_;
   $val / 2.55;
}

sub highlights {
   my ($val) = @_;
   1.108 * $val / 2.55;
}

sub rval {
   my ($col) = @_;
   @{$col}[0];
}

sub gval {
   my ($col) = @_;
   @{$col}[1];
}

sub bval {
   my ($col) = @_;
   @{$col}[2];
}

sub sota_scale {
   my ($val, $scale, $chrome_factor) = @_;
   sqrt ($val) * $scale * $chrome_factor;
}

sub copy_layer_crystal {
   my ($dest_image, $dest_drawable, $source_image, $source_drawable) = @_;
   gimp_selection_all ($dest_image);
   gimp_edit_clear ($dest_drawable);
   gimp_selection_none ($dest_image);
   gimp_selection_all ($source_image);
   gimp_edit_copy ($source_drawable);
   do {
      my $floating_sel = gimp_edit_paste ($dest_drawable, 0);
      
      gimp_floating_sel_anchor ($floating_sel);
   };
}

sub script_fu_crystal_logo {
   my ($chrome_factor, $text, $size, $font, $bg_img, $env_map) = @_;
   do {
      my $img = gimp_image_new (256, 256, GRAY);
      my $back_img = gimp_file_load ($bg_img, $bg_img);
      my $back_layer = gimp_image_active_drawable ($back_img);
      my $banding_img = gimp_file_load ($env_map, $env_map);
      my $banding_layer = gimp_image_active_drawable ($banding_img);
      my $banding_height = gimp_drawable_height ($banding_layer);
      my $banding_width = gimp_drawable_width ($banding_layer);
      my $banding_type = gimp_drawable_type ($banding_layer);
      my $b_size = sota_scale ($size, 2, $chrome_factor);
      my $offx1 = sota_scale ($size, 0.33, $chrome_factor);
      my $offy1 = sota_scale ($size, 0.25, $chrome_factor);
      my $offx2 = sota_scale ($size, -(0.33), $chrome_factor);
      my $offy2 = sota_scale ($size, -(0.25), $chrome_factor);
      my $feather = sota_scale ($size, 0.5, $chrome_factor);
      my $blur = sota_scale ($size, 0.5, $chrome_factor);
      my $displace = sota_scale ($size, 0.25, $chrome_factor);
      my $brush_size = sota_scale ($size, 0.5, $chrome_factor);
      my $text_layer = gimp_text_fontname ($img, -1, 0, 0, $text, $b_size, 1, $size, PIXELS, $font);
      my $width = gimp_drawable_width ($text_layer);
      my $height = gimp_drawable_height ($text_layer);
      my $tile_ret = [plug_in_tile ($back_img, $back_layer, $width, $height, 1)];
      my $tile_img = @{$tile_ret}[0];
      my $tile_layer = @{$tile_ret}[1];
      my $tile_width = gimp_drawable_width ($tile_layer);
      my $tile_height = gimp_drawable_height ($tile_layer);
      my $tile_type = gimp_drawable_type ($tile_layer);
      my $bg_layer = gimp_layer_new ($img, $tile_width, $tile_height, $tile_type, "BG-Layer", 100, NORMAL_MODE);
      my $layer1 = gimp_layer_new ($img, $banding_width, $banding_height, $banding_type, "Layer1", 100, NORMAL_MODE);
      my $layer2 = gimp_layer_new ($img, $width, $height, GRAYA_IMAGE, "Layer 2", 100, DIFFERENCE_MODE);
      my $layer3 = gimp_layer_new ($img, $width, $height, GRAYA_IMAGE, "Layer 3", 100, NORMAL_MODE);
      my $layer_mask = 0;
      my $layer_mask2 = 0;
      my $disp_map = 0;
      my $old_fg = gimp_palette_get_foreground ();
      my $old_bg = gimp_palette_get_background ();
      my $old_brush = gimp_brushes_get_brush ();
      
      gimp_image_delete ($back_img);
      gimp_image_undo_disable ($img);
      gimp_image_resize ($img, $width, $height, 0, 0);
      gimp_image_add_layer ($img, $layer3, 0);
      gimp_image_add_layer ($img, $layer2, 0);
      gimp_palette_set_background ([255, 255, 255]);
      gimp_selection_none ($img);
      gimp_edit_fill ($layer2, BG_IMAGE_FILL);
      gimp_edit_fill ($layer3, BG_IMAGE_FILL);
      gimp_layer_set_visible ($text_layer, 0);
      gimp_selection_layer_alpha ($text_layer);
      gimp_palette_set_background ([0, 0, 0]);
      gimp_selection_translate ($img, $offx1, $offy1);
      gimp_selection_feather ($img, $feather);
      gimp_edit_fill ($layer2, BG_IMAGE_FILL);
      gimp_selection_translate ($img, 2 * $offx2, 2 * $offy2);
      gimp_edit_fill ($layer3, BG_IMAGE_FILL);
      gimp_selection_none ($img);
      $layer2 = gimp_image_merge_visible_layers ($img, CLIP_TO_IMAGE);
      gimp_invert ($layer2);
      copy_layer_crystal ($img, $layer1, $banding_img, $banding_layer);
      gimp_image_delete ($banding_img);
      gimp_image_add_layer ($img, $layer1, 0);
      gimp_layer_scale ($layer1, $width, $height, 0);
      plug_in_gauss_iir ($img, $layer1, 10, 1, 1);
      gimp_layer_set_opacity ($layer1, 50);
      $layer1 = gimp_image_merge_visible_layers ($img, CLIP_TO_IMAGE);
      gimp_curves_spline ($layer1, 0, 18, spline1 ());
      $layer_mask = gimp_layer_create_mask ($layer1, BLACK_MASK);
      gimp_image_add_layer_mask ($img, $layer1, $layer_mask);
      gimp_selection_layer_alpha ($text_layer);
      gimp_palette_set_background ([255, 255, 255]);
      gimp_edit_fill ($layer_mask, BG_IMAGE_FILL);
      $disp_map = gimp_selection_save ($img);
      gimp_brushes_set_brush (crystal_brush ($brush_size));
      gimp_palette_set_foreground ([0, 0, 0]);
      gimp_edit_stroke ($disp_map);
      gimp_selection_none ($img);
      plug_in_gauss_rle ($img, $disp_map, $blur, 1, 1);
      gimp_levels ($disp_map, 0, 0, 255, 1.0, 96, 255);
      if (gimp_drawable_is_rgb ($bg_layer) == 1) {
         gimp_convert_rgb ($img);
      }
      copy_layer_crystal ($img, $bg_layer, $tile_img, $tile_layer);
      gimp_image_delete ($tile_img);
      gimp_image_add_layer ($img, $bg_layer, 2);
      $layer2 = gimp_layer_copy ($bg_layer, 1);
      gimp_image_add_layer ($img, $layer2, 1);
      plug_in_displace ($img, $layer2, $displace, $displace, 1, 1, $disp_map, $disp_map, 0);
      $layer_mask2 = gimp_layer_create_mask ($layer2, BLACK_MASK);
      gimp_image_add_layer_mask ($img, $layer2, $layer_mask2);
      gimp_selection_layer_alpha ($text_layer);
      gimp_palette_set_background ([255, 255, 255]);
      gimp_edit_fill ($layer_mask2, BG_IMAGE_FILL);
      gimp_selection_none ($img);
      gimp_levels ($layer2, 0, 0, 200, 1.5, 50, 255);
      gimp_layer_set_mode ($layer1, OVERLAY_MODE);
      plug_in_gauss_rle ($img, $text_layer, $blur, 1, 1);
      gimp_layer_set_preserve_trans ($text_layer, 1);
      gimp_palette_set_background ([0, 0, 0]);
      gimp_edit_fill ($text_layer, BG_IMAGE_FILL);
      gimp_layer_set_mode ($text_layer, OVERLAY_MODE);
      gimp_layer_translate ($text_layer, $offx1, $offy1);
      gimp_image_remove_channel ($img, $disp_map);
      gimp_layer_set_visible ($text_layer, 1);
      gimp_layer_set_name ($layer1, "Crystal");
      gimp_layer_set_name ($layer2, "Interior");
      gimp_layer_set_name ($bg_layer, "Background");
      gimp_layer_set_name ($text_layer, "Shadow");
      gimp_palette_set_foreground ($old_fg);
      gimp_palette_set_background ($old_bg);
      gimp_brushes_set_brush ($old_brush);
      gimp_image_undo_enable ($img);
      gimp_display_new ($img);
   };
}

register "perl_fu_crystal_logo",
   "Crystal/Gel effect which displaces the image underneath",
   "Crystal/Gel effect which displaces the image underneath",
   "Spencer Kimball",
   "Spencer Kimball",
   "1997",
   N_"<Image>/Filters/Logulator/Crystal",
   "",
   [
      [PF_VALUE,     'chrome_factor',    "Chrome Factor", "1.0"],
      [PF_STRING,    'text_string',      "Text String", "Crystal"],
      [PF_ADJUSTMENT,'font_size_pixels', "Font Size (pixels)", [150, 2, 1000, 1, 10, 0, 1]],
      [PF_FONT,      'font',             "Font", "-*-Engraver-*-r-*-*-24-*-*-*-p-*-*-*"],
      [PF_FILE,      'background_img',   "Background Img", "".'/usr/local/share/gimp/1.1'."/scripts/texture1.jpg"],
      [PF_FILE,      'environment_map',  "Environment Map", "".'/usr/local/share/gimp/1.1'."/scripts/beavis.jpg"],
   ],
   \&script_fu_crystal_logo;

sub script_fu_i26_gunya2 {
   my ($text, $text_color, $frame_color, $font, $font_size, $frame_size) = @_;
   do {
      my $img = gimp_image_new (256, 256, RGB_IMAGE);
      my $border = $font_size / 10;
      my $text_layer = gimp_text_fontname ($img, -1, 0, 0, $text, $border * 2, 1, $font_size, PIXELS, $font);
      my $width = gimp_drawable_width ($text_layer);
      my $height = gimp_drawable_height ($text_layer);
      my $dist_text_layer = gimp_layer_new ($img, $width, $height, RGBA_IMAGE, "Distorted text", 100, NORMAL_MODE);
      my $dist_frame_layer = gimp_layer_new ($img, $width, $height, RGBA_IMAGE, "Distorted text", 100, NORMAL_MODE);
      my $distortion_img = gimp_image_new ($width, $height, GRAY);
      my $distortion_layer = gimp_layer_new ($distortion_img, $width, $height, GRAY_IMAGE, "temp", 100, NORMAL_MODE);
      my $radius = $font_size / 10;
      my $prob = 0.5;
      my $old_fg = gimp_palette_get_foreground ();
      my $old_bg = gimp_palette_get_background ();
      my $old_brush = gimp_brushes_get_brush ();
      my $old_paint_mode = gimp_brushes_get_paint_mode ();
      
      gimp_image_undo_disable ($img);
      gimp_image_undo_disable ($distortion_img);
      gimp_image_resize ($img, $width, $height, 0, 0);
      gimp_image_add_layer ($img, $dist_text_layer, -1);
      gimp_image_add_layer ($img, $dist_frame_layer, -1);
      gimp_image_add_layer ($distortion_img, $distortion_layer, -1);
      gimp_selection_none ($img);
      gimp_edit_clear ($dist_text_layer);
      gimp_edit_clear ($dist_frame_layer);
      gimp_selection_layer_alpha ($text_layer);
      gimp_palette_set_background ($text_color);
      gimp_edit_fill ($dist_text_layer, BG_IMAGE_FILL);
      gimp_selection_border ($img, $frame_size);
      gimp_palette_set_background ($frame_color);
      gimp_edit_fill ($dist_frame_layer, BG_IMAGE_FILL);
      gimp_selection_none ($img);
      gimp_palette_set_background ([255, 255, 255]);
      gimp_edit_fill ($distortion_layer, BG_IMAGE_FILL);
      plug_in_noisify ($distortion_img, $distortion_layer, 0, $prob, $prob, $prob, 0.0);
      plug_in_gauss_rle ($distortion_img, $distortion_layer, $radius, 1, 1);
      plug_in_c_astretch ($distortion_img, $distortion_layer);
      plug_in_gauss_rle ($distortion_img, $distortion_layer, $radius, 1, 1);
      plug_in_displace ($img, $dist_text_layer, $radius, $radius, 1, 1, $distortion_layer, $distortion_layer, 0);
      gimp_edit_fill ($distortion_layer, BG_IMAGE_FILL);
      plug_in_noisify ($distortion_img, $distortion_layer, 0, $prob, $prob, $prob, 0.0);
      plug_in_gauss_rle ($distortion_img, $distortion_layer, $radius, 1, 1);
      plug_in_c_astretch ($distortion_img, $distortion_layer);
      plug_in_gauss_rle ($distortion_img, $distortion_layer, $radius, 1, 1);
      plug_in_displace ($img, $dist_frame_layer, $radius, $radius, 1, 1, $distortion_layer, $distortion_layer, 0);
      gimp_selection_all ($img);
      gimp_palette_set_background ([255, 255, 255]);
      gimp_edit_fill ($text_layer, BG_IMAGE_FILL);
      gimp_palette_set_foreground ($old_fg);
      gimp_palette_set_background ($old_bg);
      gimp_brushes_set_brush ($old_brush);
      gimp_brushes_set_paint_mode ($old_paint_mode);
      gimp_image_set_active_layer ($img, $dist_text_layer);
      gimp_image_undo_enable ($img);
      gimp_image_delete ($distortion_img);
      gimp_display_new ($img);
   };
}

register "perl_fu_i26_gunya2",
   "Two-colored text by hand",
   "Two-colored text by hand",
   "Shuji Narazaki",
   "Shuji Narazaki",
   "1997",
   N_"<Image>/Filters/Logulator/Imigre-26",
   "",
   [
      [PF_STRING,    'text_string',      "Text", "The GIMP"],
      [PF_COLOUR,    'text_color',       "Text Color", [255, 0, 0]],
      [PF_COLOUR,    'frame_color',      "Frame Color", [0, 34, 255]],
      [PF_FONT,      'font',             "Font"],
      [PF_ADJUSTMENT,'font_size_pixels', "Font Size (pixels)", [100, 2, 1000, 1, 10, 0, 1]],
      [PF_VALUE,     'frame_size',       "Frame Size", "2"],
   ],
   \&script_fu_i26_gunya2;

sub script_fu_newsprint_text {
   my ($string, $font, $font_size, $cell_size, $density) = @_;
   do {
      my $text_ext = [gimp_text_get_extents_fontname ($string, $font_size, PIXELS, $font)];
      my $wid = (@{$text_ext}[0] + 20);
      my $hi = (nth (1, $text_ext) + 20);
      my $img = gimp_image_new ($wid, $hi, RGB_IMAGE);
      my $bg_layer = gimp_layer_new ($img, $wid, $hi, RGB_IMAGE, "Background", 100, NORMAL_MODE);
      my $text_layer = gimp_layer_new ($img, $wid, $hi, RGBA_IMAGE, "Text layer", 100, NORMAL_MODE);
      my $text_mask = 0;
      my $grey = $density * 255 / 100;
      my $old_bg = gimp_palette_get_background ();
      
      gimp_image_undo_disable ($img);
      gimp_image_add_layer ($img, $bg_layer, 1);
      gimp_image_add_layer ($img, $text_layer, -1);
      gimp_edit_clear ($bg_layer);
      gimp_edit_clear ($text_layer);
      gimp_floating_sel_anchor (gimp_text_fontname ($img, $text_layer, 10, 10, $string, 0, 1, $font_size, PIXELS, $font));
      $text_mask = gimp_layer_create_mask ($text_layer, ALPHA_MASK);
      gimp_image_add_layer_mask ($img, $text_layer, $text_mask);
      gimp_selection_layer_alpha ($text_layer);
      gimp_palette_set_background ([$grey, $grey, $grey]);
      gimp_edit_fill ($text_mask, BG_IMAGE_FILL);
      plug_in_newsprint ($img, $text_mask, $cell_size, 0, 0, 45.0, 3, 45.0, 0, 45.0, 0, 45.0, 0, 3);
      gimp_image_remove_layer_mask ($img, $text_layer, APPLY);
      gimp_palette_set_background ($old_bg);
      gimp_image_undo_enable ($img);
      gimp_display_new ($img);
   };
}

register "perl_fu_newsprint_text",
   "apply a screen to text",
   "apply a screen to text",
   "Austin Donnelly",
   "Austin Donnelly",
   "1998",
   N_"<Image>/Filters/Logulator/Newsprint text",
   "",
   [
      [PF_STRING,    'text_string',      "Text String", "Newsprint"],
      [PF_FONT,      'font',             "Font", "-*-Helvetica-*-r-*-*-24-*-*-*-p-*-*-*"],
      [PF_ADJUSTMENT,'font_size_pixels', "Font Size (pixels)", [100, 2, 1000, 1, 10, 0, 1]],
      [PF_VALUE,     'cell_size_in_pixels',"Cell size (in pixels)", "7"],
      [PF_ADJUSTMENT,'density',          "Density (%)", [60, 0, 100, 1, 10, 0, 0]],
   ],
   \&script_fu_newsprint_text;
sub set_pt {
   my ($a, $index, $x, $y) = @_;
   do {
      $a->[$index * 2] = $x;
      $a->[($index * 2 + 1)] = $y;
   };
}

sub spline1 {
   
   do {
      my $a = (18,"byte",[]);
      
      set_pt ($a, 0, 0, 0);
      set_pt ($a, 1, 31, 235);
      set_pt ($a, 2, 63, 23);
      set_pt ($a, 3, 95, 230);
      set_pt ($a, 4, 127, 25);
      set_pt ($a, 5, 159, 210);
      set_pt ($a, 6, 191, 20);
      set_pt ($a, 7, 223, 240);
      set_pt ($a, 8, 255, 31);
      $a;
   };
}

sub brush {
   my ($brush_size) = @_;
   $brush_size <= 5 ? "Circle Fuzzy (05)"
      : $brush_size <= 7 ? "Circle Fuzzy (07)"
      : $brush_size <= 9 ? "Circle Fuzzy (09)"
      : $brush_size <= 11 ? "Circle Fuzzy (11)"
      : $brush_size <= 13 ? "Circle Fuzzy (13)"
      : $brush_size <= 15 ? "Circle Fuzzy (15)"
      : $brush_size <= 17 ? "Circle Fuzzy (17)"
      : "Circle Fuzzy (19)";
}

sub shadows {
   my ($val) = @_;
   0.96 * $val / 2.55;
}

sub midtones {
   my ($val) = @_;
   $val / 2.55;
}

sub highlights {
   my ($val) = @_;
   do {
      my $h = 1.108 * $val / 2.55;
      
      if ($h > 100) {
         100;
      } else {
         $h;
      }
   };
}

sub rval {
   my ($col) = @_;
   @{$col}[0];
}

sub gval {
   my ($col) = @_;
   @{$col}[1];
}

sub bval {
   my ($col) = @_;
   @{$col}[2];
}

sub sota_scale {
   my ($val, $scale, $chrome_factor) = @_;
   sqrt ($val) * $scale * $chrome_factor;
}

sub copy_layer_sota {
   my ($dest_image, $dest_drawable, $source_image, $source_drawable) = @_;
   gimp_selection_all ($dest_image);
   gimp_edit_clear ($dest_drawable);
   gimp_selection_none ($dest_image);
   gimp_selection_all ($source_image);
   gimp_edit_copy ($source_drawable);
   do {
      my $floating_sel = gimp_edit_paste ($dest_drawable, 0);
      
      gimp_floating_sel_anchor ($floating_sel);
   };
}

sub script_fu_sota_chrome_logo {
   my ($chrome_saturation, $chrome_lightness, $chrome_factor, $text, $size, $fontname, $env_map, $hc, $cc) = @_;
   do {
      my $img = gimp_image_new (256, 256, GRAY);
      my $banding_img = gimp_file_load ($env_map, $env_map);
      my $banding_layer = gimp_image_active_drawable ($banding_img);
      my $banding_height = gimp_drawable_height ($banding_layer);
      my $banding_width = gimp_drawable_width ($banding_layer);
      my $banding_type = gimp_drawable_type ($banding_layer);
      my $b_size = sota_scale ($size, 2, $chrome_factor);
      my $offx1 = sota_scale ($size, 0.33, $chrome_factor);
      my $offy1 = sota_scale ($size, 0.25, $chrome_factor);
      my $offx2 = sota_scale ($size, -(0.33), $chrome_factor);
      my $offy2 = sota_scale ($size, -(0.25), $chrome_factor);
      my $feather = sota_scale ($size, 0.5, $chrome_factor);
      my $brush_size = sota_scale ($size, 0.5, $chrome_factor);
      my $text_layer = gimp_text_fontname ($img, -1, 0, 0, $text, $b_size * 2, 1, $size, PIXELS, $fontname);
      my $width = gimp_drawable_width ($text_layer);
      my $height = gimp_drawable_height ($text_layer);
      my $layer1 = gimp_layer_new ($img, $banding_width, $banding_height, $banding_type, "Layer1", 100, NORMAL_MODE);
      my $layer2 = gimp_layer_new ($img, $width, $height, GRAYA_IMAGE, "Layer 2", 100, DIFFERENCE_MODE);
      my $layer3 = gimp_layer_new ($img, $width, $height, GRAYA_IMAGE, "Layer 3", 100, NORMAL_MODE);
      my $shadow = gimp_layer_new ($img, $width, $height, GRAYA_IMAGE, "Drop Shadow", 100, NORMAL_MODE);
      my $layer_mask = 0;
      my $old_fg = gimp_palette_get_foreground ();
      my $old_bg = gimp_palette_get_background ();
      my $old_brush = gimp_brushes_get_brush ();
      my $old_pattern = gimp_patterns_get_pattern ();
      
      gimp_image_undo_disable ($img);
      gimp_image_resize ($img, $width, $height, 0, 0);
      gimp_image_add_layer ($img, $shadow, 0);
      gimp_image_add_layer ($img, $layer3, 0);
      gimp_image_add_layer ($img, $layer2, 0);
      gimp_palette_set_background ([255, 255, 255]);
      gimp_selection_none ($img);
      gimp_edit_fill ($layer2, BG_IMAGE_FILL);
      gimp_edit_fill ($layer3, BG_IMAGE_FILL);
      gimp_edit_clear ($shadow);
      gimp_layer_set_visible ($text_layer, 0);
      gimp_layer_set_visible ($shadow, 0);
      gimp_rect_select ($img, $b_size / 2, $b_size / 2, ($width - $b_size), ($height - $b_size), REPLACE, 0, 0);
      gimp_rect_select ($img, $b_size, $b_size, ($width - $b_size * 2), ($height - $b_size * 2), SUB, 0, 0);
      gimp_edit_fill ($text_layer, BG_IMAGE_FILL);
      gimp_selection_layer_alpha ($text_layer);
      gimp_palette_set_background ([0, 0, 0]);
      gimp_selection_translate ($img, $offx1, $offy1);
      gimp_selection_feather ($img, $feather);
      gimp_edit_fill ($layer2, BG_IMAGE_FILL);
      gimp_selection_translate ($img, 2 * $offx2, 2 * $offy2);
      gimp_edit_fill ($layer3, BG_IMAGE_FILL);
      gimp_selection_none ($img);
      gimp_layer_set_visible ($layer2, 1);
      gimp_layer_set_visible ($layer3, 1);
      $layer2 = gimp_image_merge_visible_layers ($img, CLIP_TO_IMAGE);
      gimp_invert ($layer2);
      copy_layer_sota ($img, $layer1, $banding_img, $banding_layer);
      gimp_image_delete ($banding_img);
      gimp_image_add_layer ($img, $layer1, 0);
      gimp_layer_scale ($layer1, $width, $height, 0);
      plug_in_gauss_iir ($img, $layer1, 10, 1, 1);
      gimp_layer_set_opacity ($layer1, 50);
      gimp_layer_set_visible ($layer1, 1);
      gimp_layer_set_visible ($layer2, 1);
      $layer1 = gimp_image_merge_visible_layers ($img, CLIP_TO_IMAGE);
      gimp_curves_spline ($layer1, 0, 18, spline1 ());
      $layer_mask = gimp_layer_create_mask ($layer1, BLACK_MASK);
      gimp_image_add_layer_mask ($img, $layer1, $layer_mask);
      gimp_selection_layer_alpha ($text_layer);
      gimp_palette_set_background ([255, 255, 255]);
      gimp_edit_fill ($layer_mask, BG_IMAGE_FILL);
      $layer2 = gimp_layer_copy ($layer1, 1);
      gimp_image_add_layer ($img, $layer2, 0);
      gimp_brushes_set_brush (brush ($brush_size));
      gimp_palette_set_foreground ([255, 255, 255]);
      gimp_edit_stroke ($layer_mask);
      gimp_palette_set_background ([0, 0, 0]);
      gimp_selection_feather ($img, $feather * 1.5);
      gimp_selection_translate ($img, 2.5 * $offx1, 2.5 * $offy1);
      gimp_edit_fill ($shadow, BG_IMAGE_FILL);
      gimp_selection_all ($img);
      gimp_patterns_set_pattern ("Marble #1");
      gimp_bucket_fill ($text_layer, PATTERN_BUCKET_FILL, NORMAL_MODE, 100, 0, 0, 0, 0);
      gimp_selection_none ($img);
      gimp_convert_rgb ($img);
      gimp_color_balance ($layer1, 0, 1, shadows (rval ($hc)), shadows (gval ($hc)), shadows (bval ($hc)));
      gimp_color_balance ($layer1, 1, 1, midtones (rval ($hc)), midtones (gval ($hc)), midtones (bval ($hc)));
      gimp_color_balance ($layer1, 2, 1, highlights (rval ($hc)), highlights (gval ($hc)), highlights (bval ($hc)));
      gimp_color_balance ($layer2, 0, 1, shadows (rval ($cc)), shadows (gval ($cc)), shadows (bval ($cc)));
      gimp_color_balance ($layer2, 1, 1, midtones (rval ($cc)), midtones (gval ($cc)), midtones (bval ($cc)));
      gimp_color_balance ($layer2, 2, 1, highlights (rval ($cc)), highlights (gval ($cc)), highlights (bval ($cc)));
      gimp_hue_saturation ($layer2, 0, 0, $chrome_lightness, $chrome_saturation);
      gimp_layer_set_visible ($shadow, 1);
      gimp_layer_set_visible ($text_layer, 1);
      gimp_layer_set_name ($text_layer, "Background");
      gimp_layer_set_name ($layer2, "Chrome");
      gimp_layer_set_name ($layer1, "Highlight");
      gimp_layer_translate ($shadow, $b_size / -4, $b_size / -4);
      gimp_layer_translate ($layer2, $b_size / -4, $b_size / -4);
      gimp_layer_translate ($layer1, $b_size / -4, $b_size / -4);
      gimp_palette_set_foreground ($old_fg);
      gimp_palette_set_background ($old_bg);
      gimp_brushes_set_brush ($old_brush);
      gimp_patterns_set_pattern ($old_pattern);
      gimp_image_undo_enable ($img);
      gimp_display_new ($img);
   };
}

register "perl_fu_sota_chrome_logo",
   "State of the art chromed logos.",
   "State of the art chromed logos.",
   "Spencer Kimball",
   "Spencer Kimball",
   "1997",
   N_"<Image>/Filters/Logulator/SOTA Chrome",
   "",
   [
      [PF_ADJUSTMENT,'chrome_saturation',"Chrome Saturation", [-80, -100, 100, 1, 10, 0, 0]],
      [PF_ADJUSTMENT,'chrome_lightness', "Chrome Lightness", [-47, -100, 100, 1, 10, 0, 0]],
      [PF_ADJUSTMENT,'chrome_factor',    "Chrome Factor", [.75, 0, 1, .1, .01, 0, 0]],
      [PF_STRING,    'text_string',      "Text String", "The GIMP"],
      [PF_ADJUSTMENT,'font_size_pixels', "Font Size (pixels)", [150, 2, 1000, 1, 10, 0, 1]],
      [PF_FONT,      'font',             "Font", "-*-RoostHeavy-*-r-*-*-24-*-*-*-p-*-*-*"],
      [PF_FILE,      'environment_map',  "Environment Map", "".'/usr/local/share/gimp/1.1'."/scripts/beavis.jpg"],
      [PF_COLOUR,    'highlight_balance',"Highlight Balance", [211, 95, 0]],
      [PF_COLOUR,    'chrome_balance',   "Chrome Balance", [0, 0, 0]],
   ],
   \&script_fu_sota_chrome_logo;
sub script_fu_speed_text {
   my ($string, $font, $font_size, $density) = @_;
   do {
      my $text_ext = [gimp_text_get_extents_fontname ($string, $font_size, PIXELS, $font)];
      my $wid = (@{$text_ext}[0] + 20);
      my $hi = (nth (1, $text_ext) + 20);
      my $img = gimp_image_new ($wid, $hi, RGB_IMAGE);
      my $bg_layer = gimp_layer_new ($img, $wid, $hi, RGB_IMAGE, "Background", 100, NORMAL_MODE);
      my $text_layer = gimp_layer_new ($img, $wid, $hi, RGBA_IMAGE, "Text layer", 100, NORMAL_MODE);
      my $text_mask = 0;
      my $saved_select = 0;
      my $cell_size = $font_size / 8;
      my $grey = $density * 255 / 100;
      my $old_fg = gimp_palette_get_foreground ();
      my $old_bg = gimp_palette_get_background ();
      
      gimp_image_undo_disable ($img);
      gimp_image_add_layer ($img, $bg_layer, 1);
      gimp_image_add_layer ($img, $text_layer, -1);
      gimp_edit_clear ($bg_layer);
      gimp_edit_clear ($text_layer);
      gimp_floating_sel_anchor (gimp_text_fontname ($img, $text_layer, 10, 10, $string, 0, 1, $font_size, PIXELS, $font));
      gimp_selection_layer_alpha ($text_layer);
      $saved_sel = gimp_selection_save ($img);
      $text_mask = gimp_layer_create_mask ($text_layer, ALPHA_MASK);
      gimp_image_add_layer_mask ($img, $text_layer, $text_mask);
      gimp_layer_set_edit_mask ($text_layer, 0);
      gimp_selection_grow ($img, 10);
      gimp_palette_set_background ($old_fg);
      gimp_edit_fill ($text_layer, BG_IMAGE_FILL);
      gimp_layer_set_edit_mask ($text_layer, 1);
      gimp_selection_load ($saved_sel);
      gimp_selection_feather ($img, 10);
      gimp_palette_set_background ([$grey, $grey, $grey]);
      gimp_edit_fill ($text_mask, BG_IMAGE_FILL);
      gimp_edit_fill ($text_mask, BG_IMAGE_FILL);
      gimp_edit_fill ($text_mask, BG_IMAGE_FILL);
      gimp_selection_clear ($img);
      plug_in_newsprint ($img, $text_mask, $cell_size, 0, 0, 0.0, 1, 45.0, 0, 45.0, 0, 45.0, 0, 5);
      gimp_image_remove_layer_mask ($img, $text_layer, APPLY);
      gimp_palette_set_foreground ($old_fg);
      gimp_palette_set_background ($old_bg);
      gimp_image_undo_enable ($img);
      gimp_display_new ($img);
   };
}

register "perl_fu_speed_text",
   "give text a speedy effect",
   "give text a speedy effect",
   "Austin Donnelly",
   "Austin Donnelly",
   "1998",
   N_"<Image>/Filters/Logulator/Speed text",
   "",
   [
      [PF_STRING,    'text_string',      "Text String", "Speed!"],
      [PF_FONT,      'font',             "Font", "-*-Charter-*-r-*-*-24-*-*-*-p-*-*-*"],
      [PF_ADJUSTMENT,'font_size_pixels', "Font Size (pixels)", [100, 2, 1000, 1, 10, 0, 1]],
      [PF_ADJUSTMENT,'density',          "Density (%)", [80, 0, 100, 1, 10, 0, 0]],
   ],
   \&script_fu_speed_text;

sub script_fu_title_header {
   my ($text, $size, $fontname) = @_;
   do {
      my $padding = 8;
      my $fade_width = 64;
      my $old_fg_color = gimp_palette_get_foreground ();
      my $old_bg_color = gimp_palette_get_background ();
      my $img = gimp_image_new (256, 256, RGB_IMAGE);
      my $text_layer = gimp_text_fontname ($img, -1, 0, 0, $text, $padding, 1, $size, PIXELS, $fontname);
      my $text_width = gimp_drawable_width ($text_layer);
      my $text_height = gimp_drawable_height ($text_layer);
      my $text_layers_offset = $text_height / 2;
      my $img_width = ($text_layers_offset + $text_width + $fade_width);
      my $img_height = $text_height;
      my $bg_layer = gimp_layer_new ($img, $img_width, $img_height, RGBA_IMAGE, "bg-layer", 100, NORMAL_MODE);
      my $bumpmap_layer = gimp_layer_new ($img, $text_width, $text_height, RGBA_IMAGE, "bumpmap-layer", 100, NORMAL_MODE);
      my $fore_layer = gimp_layer_new ($img, $text_width, $text_height, RGBA_IMAGE, "fore-layer", 100, NORMAL_MODE);
      
      gimp_image_undo_disable ($img);
      gimp_image_resize ($img, $img_width, $img_height, 0, 0);
      gimp_image_add_layer ($img, $bg_layer, -1);
      gimp_image_add_layer ($img, $bumpmap_layer, -1);
      gimp_image_add_layer ($img, $fore_layer, -1);
      gimp_image_raise_layer ($img, $text_layer);
      gimp_image_raise_layer ($img, $text_layer);
      gimp_image_raise_layer ($img, $text_layer);
      gimp_layer_set_offsets ($bg_layer, 0, 0);
      gimp_layer_set_offsets ($text_layer, $text_layers_offset, 0);
      gimp_layer_set_offsets ($bumpmap_layer, $text_layers_offset, 0);
      gimp_layer_set_offsets ($fore_layer, $text_layers_offset, 0);
      gimp_palette_set_background ([0, 0, 0]);
      gimp_edit_fill ($bumpmap_layer, BG_IMAGE_FILL);
      gimp_selection_layer_alpha ($text_layer);
      gimp_palette_set_background ([255, 255, 255]);
      gimp_edit_fill ($bumpmap_layer, BG_IMAGE_FILL);
      gimp_selection_none ($img);
      plug_in_gauss_rle ($img, $bumpmap_layer, 4.0, 1, 1);
      gimp_palette_set_background ([255, 255, 255]);
      gimp_edit_fill ($fore_layer, BG_IMAGE_FILL);
      plug_in_bump_map ($img, $fore_layer, $bumpmap_layer, 135.0, 45.0, 4, 0, 0, 0, 0, 0, 0, 0);
      gimp_layer_set_visible ($text_layer, 1);
      gimp_layer_set_preserve_trans ($text_layer, 1);
      gimp_blend ($text_layer, CUSTOM, NORMAL_MODE, LINEAR, 100, 0, REPEAT_NONE, 0, 0.2, 3, $padding, $padding, ($text_width - $padding - 1), ($text_height - $padding - 1));
      gimp_palette_set_background ([0, 0, 0]);
      gimp_edit_fill ($bg_layer, BG_IMAGE_FILL);
      gimp_ellipse_select ($img, 0, 0, $text_height, $text_height, REPLACE, 1, 0, 0);
      gimp_palette_set_background (gimp_color_picker ($text_layer, $text_layers_offset, 0, 1, 0, 6, 0));
      gimp_edit_fill ($bg_layer, BG_IMAGE_FILL);
      gimp_rect_select ($img, ($img_width - $fade_width), 0, $fade_width, $text_height, REPLACE, 0, 0);
      gimp_palette_set_foreground (gimp_palette_get_background ());
      gimp_palette_set_background ([0, 0, 0]);
      gimp_blend ($bg_layer, FG_BG_RGB, NORMAL_MODE, LINEAR, 100, 0, REPEAT_NONE, 0, 0.2, 3, ($img_width - $fade_width), 0, ($img_width - 1), 0);
      gimp_selection_none ($img);
      gimp_palette_set_foreground ($old_fg_color);
      gimp_palette_set_background ($old_bg_color);
      gimp_image_undo_enable ($img);
      gimp_display_new ($img);
   };
}

register "perl_fu_title_header",
   "Web title header",
   "Web title header",
   "Federico Mena Quintero",
   "Federico Mena Quintero",
   "June 1997",
   N_"<Image>/Filters/Logulator/Web title header",
   "",
   [
      [PF_STRING,    'text_string',      "Text", "Hello world!"],
      [PF_ADJUSTMENT,'font_size_pixels', "Text size", [32, 2, 256, 1, 10, 0, 0]],
      [PF_FONT,      'font',             "Font", "-adobe-helvetica-bold-r-normal-*-30-*-*-*-p-*-*-*"],
   ],
   \&script_fu_title_header;

exit main;
