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();
|| $x<0 || $x>=$self->{"width" }
|| $y<0 || $y>=$self->{"height"}
;
- return \vec($self->{"blob"},int(($self->{"width"}+7)/8)*$y + $x,1);
+ return \vec($self->{"blob"},int(($self->{"width"}+7)/8)*8*$y + $x,1);
}
sub pixget {
my ($self) = @_;
my $bits="";
- for my $y (0..$self->{"height"}) {
+ for my $y (0..$self->{"height"}-1) {
for my $x (0..int(($self->{"width"}+7)&~0x7)-1) {
$bits.=$self->pixget($x,$y);
}