10 $data=~s/^\s*#.*\n//m;
11 my($format,$width,$height)=($data=~/^(P[14])\n(\d+) (\d+)\n/);
13 die "Invalid format" if !$format || !$width || !$height;
14 die "Picture too big; width=$width < 0xFF && height=$height < 0xFF" if $width>0xFF || $height>0xFF;
15 if ($format eq "P1") {
19 $data=unpack("b*",$data);
20 my $width8=int(($width+7)/8)*8;
21 for my $y (0..$height-1) {
23 substr($data,$width*$y+$width,$width8-$width)="";
26 die "Bad data length ".length($data) if length($data)!=$width*$height;
31 0x15,0x8A, # dest port (ring tones)
32 0x15,0x8A); # src port (unused)
34 my $multihdr_uniq=int(rand(0x100));
42 $multihdr_uniq, # unique serial ID
43 $total, # total messages
44 $num+1); # message number (# from 1)
51 return pack "C*",scalar(@bytes),@bytes;
55 my $picturebyteslen=int(($width*$height+7)/8)+4; # +4 is for some part of the header
56 my $picturedata=unpack("b*",pack("C*",
57 0x30, # version string '0'
58 0x02, # item=OTA bitmap
59 ($picturebyteslen>>8)&0xFF, # picture size in bytes incl. header; HIGH
60 ($picturebyteslen>>0)&0xFF, # picture size in bytes incl. header; LOW
61 0x00, # animation pictures - 0=static picture
62 $width,$height, # picture size in pixels
63 0x01, # picture depth - B/W
67 my @out=udh(@pictureudh).pack("b*",$picturedata);
68 if (length($out[0])>140) {
69 my $datalen=int((length($picturedata)+7)/8);
70 my $hdrlen=length(udh(@pictureudh,multihdr(8,8)));
71 my $dataspace=(140-$hdrlen);
72 my $total=int(($datalen+$dataspace-1)/$dataspace);
73 die "Too big: total=$total <=0xFF !" if $total>0xFF;
75 udh(@pictureudh,multihdr($_,$total)).pack("b*",substr($picturedata,$dataspace*8*$_,$dataspace*8));
78 print map({ uc(unpack("H*",$_))."\n"; } @out);