1 package GSM::SMS::Bitmap;
2 # Generic package for monochrome bitmaps
10 our @ISA=qw(Exporter);
18 my ($class, $arg, @rest) = @_;
24 if ("GSM::SMS::Bitmap" eq ref $arg) {
25 my($offset_x,$offset_y,$width,$height)=@rest;
27 $self->{"width" }=$width;
28 $self->{"height"}=$height;
29 for my $y (0..$height-1) {
30 for my $x (0..$width-1) {
31 ${$self->pixref($x,$y)}=$arg->pixget($offset_x+$x,$offset_y+$y);
36 elsif ("Image::Magick" eq ref $arg) {
41 $img=Image::Magick->new() or carp "Image::Magick->new(): $!" and return undef;
42 $err=$img->Read($arg) and carp "Image::Magick->Read(\"$arg\"): $err" and return undef;
45 $img->Set("magick"=>"mono");
46 $self->{"blob" }=$img->ImageToBlob();
47 $self->{"width" }=$img->Get("columns");
48 $self->{"height"}=$img->Get("height" );
53 my ($self, $width, $height) = @_;
55 if ($self->{"width"} > $width) {
56 carp "Cutting image width to $width pixels (from ".$self->{"width"}.")";
57 $self->{"width"}=$width;
59 if ($self->{"height"} > $height) {
60 carp "Cutting image height to $height pixels (from ".$self->{"height"}.")";
61 $self->{"height"}=$height;
66 my ($self, $x, $y) = @_;
69 return \$zero if 0 # out of bouds
70 || $x<0 || $x>=$self->{"width" }
71 || $y<0 || $y>=$self->{"height"}
73 return \vec($self->{"blob"},int(($self->{"width"}+7)/8)*8*$y + $x,1);
77 my ($self, @rest) = @_;
79 return(${$self->pixref(@rest)});
82 # Convert the bit stream to the list of byte values
83 # Hmm, it is a back ineffective to unpack() it back but who cares
84 # Two versions exist - FIXME: how to merge them?
90 for my $y (0..$self->{"height"}-1) {
91 for my $x (0..int(($self->{"width"}+7)&~0x7)-1) {
92 $bits.=$self->pixget($x,$y);
95 return unpack("C*",pack("B*",$bits));
102 for my $x (0..$self->{"width"}-1) {
103 for my $y (0..int(($self->{"height"}+7)&~0x7)-1) {
104 $bits.=$self->pixget($x,$y);
107 return unpack("C*",pack("B*",$bits));