&new: +($class,"GSM::SMS::Bitmap"-instance,$offset_x,$offset_y,$width,$heigh)
authorshort <>
Wed, 16 Oct 2002 23:05:43 +0000 (23:05 +0000)
committershort <>
Wed, 16 Oct 2002 23:05:43 +0000 (23:05 +0000)
 - copies the specified rectangular area

GSM/SMS/Bitmap.pm

index e74d490..26f9520 100644 (file)
@@ -15,20 +15,32 @@ use Carp;
 
 
 sub new {
-       my ($class, $arg) = @_;
+       my ($class, $arg, @rest) = @_;
        my $self={};
 
        bless($self,$class);
 
        my $img;
-       if ("Image::Magick" ne ref $arg) {
+          if ("GSM::SMS::Bitmap" eq ref $arg) {
+               my($offset_x,$offset_y,$width,$height)=@rest;
+               $self->{"blob"  }="";
+               $self->{"width" }=$width;
+               $self->{"height"}=$height;
+               for my $y (0..$height-1) {
+                       for my $x (0..$width-1) {
+                               ${$self->pixref($x,$y)}=$arg->pixget($offset_x+$x,$offset_y+$y);
+                               }
+                       }
+               return $self;
+               }
+       elsif ("Image::Magick" eq ref $arg) {
+               $img=$arg;
+               }
+       else {
                my $err;
                $img=Image::Magick->new() or carp "Image::Magick->new(): $!" and return undef;
                $err=$img->Read($arg) and carp "Image::Magick->Read(\"$arg\"): $err" and return undef;
                }
-       else {
-               $img=$arg;
-               }
 
        $img->Set("magick"=>"mono");
        $self->{"blob"  }=$img->ImageToBlob();