[wellylug] some Perl again

Edouard Chalaron e.chalaron at paradise.net.nz
Fri Oct 3 12:12:04 NZST 2003


Hi all, 
following my request from the other day regarding some perl trouble.
I have attached two perl files.

yuvgimp.pl and gimpemboss.pl

They are used as such

cat yuvstream | perl yuvgimp.pl -script gimpemboss.pl | yuvplay
It is supposed to take a yuv video stream convert it into RGB space, emboss 
the frame, reconvert it back into YUV space then display it and so on...

Trouble is, it is just playing the first pict. I am not able to see where it 
could be faulty or if I am misusing (spelling ??) it.

Any help would be appreciated, since the author did not reply to this 
question.

Thanks a lot
Edouard 
-------------- next part --------------
#
# This filter allows one to pass frame data through the Gimp for
# processing.  The main script (the one you're looking at) does the
# grunt work of converting the frame data to a Gimp drawable.  Once
# this is done, the drawable is passed to a user-specified script
# which can perform it's own processing.  eg:
#
# cat stream.yuv | perl yuvgimp.pl -script myscript.pl > result.yuv
#
# See gimp_emboss.pl for an example yuvgimp script.
#

package GimpFilter::Main;

use Gimp qw(:auto);
use Gimp::Fu;
use YUV4MPEG;

register "yuv_gimp_filter",
         "filter a YUV image through The Gimp",
         "",
         "Brett Kosinski",
         "Brett Kosinski <brettk\@frodo.dyn.gno.org>",
         "20030311",
         "<None>",
         "RGB*",
         [
           [PF_STRING, "script", "The filter script to run on input."],
           [PF_STRING, "call",   "The function to call for each frame.", "filter"]
         ],
         \&yuv_filter;

exit main;

sub yuv_filter
{
    my $script = shift;
    my $function = shift;

    GimpFilter::Sandbox::load_script($script);

    my $streaminfo = new YUV4MPEG::StreamInfo;
    my $frameinfo = new YUV4MPEG::FrameInfo;

    $streaminfo->read();
    $streaminfo->write();

    my ($w, $h) = ($streaminfo->get_width(),
                   $streaminfo->get_height());

    my $frame = new YUV4MPEG::Frame($streaminfo);
    my $img = new Gimp::Image($w, $h, RGB_IMAGE);
    my $layer = $img->layer_new($w, $h, RGB_IMAGE, "image", 100, NORMAL_MODE);

    $img->add_layer($layer, 0);        

    while ($frame->read($frameinfo) == Y4M_OK)
    {
        my $region = $layer->pixel_rgn(0, 0, $w, $h, 1, 0);
        my $handle = Gimp->pixel_rgns_register($region);
        my $rgb;

        $frame->to_rgb();
        $rgb = $frame->get_packed_data();

        $region->set_rect2($rgb, 0, 0, $w);
        Gimp->pixel_rgns_process($handle);

        GimpFilter::Sandbox::exec_script($img, $function);

        $img->flatten();

        ($layer) = $img->get_layers();
        $region = $layer->pixel_rgn(0, 0, $w, $h, 0, 0);

        $rgb = $region->get_rect2(0, 0, $w, $h);
        $frame->set_packed_data($rgb);
        $frame->to_yuv();

        $frame->write($frameinfo);
        
        $frameinfo = new YUV4MPEG::FrameInfo;
    }

    return undef;
}

package GimpFilter::Sandbox;

sub load_script
{
    my $script = shift;

    do $script;

    die $@ if ($@);
}

sub exec_script
{
    my ($img, $func) = @_;

    eval "\&$func(\$img)";
}
-------------- next part --------------
#
# This script must be used with yuvgimp.pl
#
# A script for embossing frames... takes a Gimp drawable, which
# contains frame data, and runs an emboss filter over it.  
#

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

my $frame_count = 1;

sub filter
{
    my $img = shift;
    my ($layer) = $img->get_layers();
    print STDERR "Embossing frame $frame_count...\n";
    plug_in_emboss($img, $layer, 45.0, 45.0, 2, 1);
  $frame_count++;
}



More information about the wellylug mailing list