how i can normal repaint image??



Hi all!!!

I write perl-script for repaint image (motion blur),

When I press on the button, I want, that the new picture was shown on the old place. But the new picture all time moves on the left, closing thus an initial picture. What do I do not so?

my script (run it ./iamges.pl 3 test.jpg) :

#!/usr/bin/perl -w

use Gtk; use strict; use Image::Size;
use Gtk::Gdk::ImlibImage;
use Image::Magick;
set_locale Gtk; init Gtk;

my $false = 0; my $true = 1;

my ($mask1,$tt,$buffer,$window,$box, $main_vbox1, $hseparator,$menubar);
my ($frame,$menu, $table1,$style,$button1, $pixmap, $numcl,$pixmapwid, $mask);
my ($hbox,$hbox2,$hbox3,$farme,$vbox,$vbox2,$adj,$label,$spinner,$table,$numcl1);
my $img=$ARGV[1];
my $img1="out.bmp";
my ($image1,$count, $x, @massiv);
my ($w, $h) = imgsize($img);
my $jj=$ARGV[0];
$image1 = Image::Magick->new;
#ЯВХРЮКХ ЙЮПРХМЙС
$x = $image1->Read($img);
warn "$x" if "$x";
print "read pix: $w $h in massiv\n";

# create window widget

$window = new Gtk::Window('toplevel');
$window->signal_connect('destroy', sub { Gtk->exit(0)});
$window->set_title("Work images");
$window->set_usize(2*$w+10, $h+100); $window->set_position('center'); $window->show();

# initialised Vbox

$box = new Gtk::VBox($false, 5);
$box->border_width(0);
$window->add($box);

# show box

$box->show();


my $fixed;
my $gdkpixmap;
my $normal;
my $gc;

# strings for grafics and widgets

$menubar = create_menu_bar($window);
$box->pack_start($menubar, $false, $true, 0);
$menubar -> show();

# read image

&massiv();

my ($cc,@m1,$j,$count1);

# create hbox

$hbox = new Gtk::HBox( $false, 0 );
$box->pack_start( $hbox, $false, $true, 0 );
$hbox->show();


sub second{
 $cc++;
 foreach my $i(0 .. $h-1){
   foreach my $k(0 .. $w-1){ my ($tmp,$tmp1,$xx);
     for $j(-$jj .. $jj) { my $tmp_num=$j+$i;
       $tmp+=$massiv[$tmp_num][$k] if $massiv[$tmp_num][$k];
     }
     for $j(-$jj .. $jj) { my $tmp_num=$j+$k;
       $tmp1+=$massiv[$i][$tmp_num] if $massiv[$i][$tmp_num];
     }
     my $tmp2=($tmp+$tmp1)/2;
     $massiv[$i][$k]=int($tmp2/(2*$jj+1));
     my $tt1 = pack "C" => $massiv[$i][$k];
     $tt1 x= 3;
     $count.=$tt1;
     $tt1='';
   }
 }

#  do{
   # first image
   print "$cc\n";
   my $image = create_image_from_data Gtk::Gdk::ImlibImage($count,1,$w,$h);
   $count='';
   $image->render ($image->rgb_width, $image->rgb_height);
   #my $gdk_pixmap = $image->copy_image;
   my $gdk_pixmap = $image -> move_image();
   my $mask = $image -> move_mask;

   $pixmap = new Gtk::Pixmap( $gdk_pixmap, $mask );
   $pixmap->show();

   $fixed = new Gtk::Fixed();
   $fixed->set_usize( $w, $h );
   $fixed->put( $pixmap, 0, 0 );
   #$hbox->add( $fixed );
   $hbox->pack_end( $fixed, 0, 0, 0 );
   $fixed -> show() if $cc%2!=0;
do{
   $fixed -> hide();
   $image=undef;
   $gdk_pixmap=undef;
 } if $cc%2==0;
}

# second image

foreach my $i(0 .. $h-1){
 foreach my $k(0 .. $w-1){ my ($tmp,$tmp1,$xx);
   my $tt11 = pack "C" => $massiv[$i][$k];
   $tt11 x= 3;
   $count1.=$tt11;
   $tt11='';
 }
}

# create image

my $image11 = create_image_from_data Gtk::Gdk::ImlibImage($count1,1,$w,$h);
$count1='';
$image11->render ($image11->rgb_width, $image11->rgb_height);
my $gdk_pixmap1 = $image11->copy_image;
$gdk_pixmap1 = $image11 -> move_image();
my $m1 = $image11 -> move_mask;
my $pixmap1 = new Gtk::Pixmap( $gdk_pixmap1, $mask1 );
$pixmap1->show();

# add image in a box

my $fixed1 = new Gtk::Fixed();
$fixed1->set_usize( $w, $h );
$fixed1->put( $pixmap1, 0, 0 );
my $ccc;
$hbox->add( $fixed1 );
$fixed1->show();
# new horisontal box

my $hbox1 = new Gtk::HBox( $false, 0 );
$box->pack_start( $hbox1, $false, $true, 0 );
$hbox1->show();

my $button = new Gtk::Button( "motion blir parametr" );

$button->signal_connect("clicked",\&second);
$hbox1->add($button);
$button->show();

# after clicked $button, picture was draw.

$adj = new Gtk::Adjustment( 3, 0.0, 2100.0, 1.0, 100.0, 0.0 );
$spinner = new Gtk::SpinButton( $adj, 0, 0 );
$spinner->set_wrap( $false );
$spinner->set_shadow_type( 'in' );
$spinner->set_usize( 55, 0 );
$hbox1->pack_start( $spinner, $false, $true, 0 );
$spinner->show();



sub create_menu_bar{  my ($window) = @_;
 my @menu_items = ( { path        => '/_File',
                      accelerator => '<control>X',
                      callback    => \&open_file,
                      type        => '<Branch>'},
                    { path        => '/File/_New',
                      accelerator => '<control>N',
                      callback    => \&new_file },
                    { path        => '/File/_Open',
                      accelerator => '<control>O',
                      callback    => \&open_file },
                    { path        => '/File/_Save',
                      accelerator => '<control>S',
                      callback    => \&open_file },
                    { path        => '/File/Save _As' },
                    { path        => '/File/',
                      type        => '<Separator>' },
                    { path        => '/File/Quit',
                      accelerator => '<alt>q',
                      callback    => sub { Gtk->exit( 0 ); } },
                    { path        => '/_Options',
                      type        => '<Branch>' },
                    { path        => '/Options/Set parametrs of blur',
                      callback    => \&new_file},
                    { path        => '/Options/set it old'},
                    { path        => '/_Help',
                      type        => '<LastBranch>' },
                    { path        => '/_Help/About',
                      callback    => \&test} );
  my ($menubar,$item_factory,$accel_group);
  $accel_group = new Gtk::AccelGroup();
  $item_factory = new Gtk::ItemFactory('Gtk::MenuBar', '<main>', $accel_group);
  $item_factory->create_items(@menu_items);
  $window->add_accel_group($accel_group);
  return ($item_factory->get_widget('<main>'));
}

sub open_file{
 my $file_dialog = new Gtk::FileSelection("File Selection");
 $file_dialog->signal_connect("destroy", sub { Gtk->exit(0)});
 $file_dialog->ok_button->signal_connect("clicked", \&file_ok_sel, $file_dialog);
 $file_dialog->cancel_button->signal_connect("clicked", sub {Gtk->exit(0)});
 $file_dialog->set_filename("penguin.png");
 $file_dialog->show();
}

# read pixels into massiv
sub massiv{
 foreach my $i(0 .. $h-1){
   foreach my $k(0 .. $w-1){
     # read only one color, for b/w image
     $massiv[$i][$k] = 255*${[split m!,! => $image1->Get("pixel[$k,$i]")]}[0]/65535;
   }
 }
}

sub sqr { return $_[0]*$_[0] }

main Gtk;
exit( 0 );


Thank you!

dmitriy




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]