/usr/share/perl5/wApua/WBMP2XBM.pm is in wapua 0.06.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | package wApua::WBMP2XBM;
# Copyright (C) 2000, 2006, 2009 by Axel Beckert <wapua@deuxchevaux.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
#
# You can reach the author by snail-mail at the following address:
#
# Axel Beckert
# Kuerbergstrasse 20
# 8049 Zurich, Switzerland
# This is a perl module, which converts some wireless bitmap (wbmp)
# into some X11 bitmap (xbm). It is mainly designed for use in the
# perl/Tk WAP browser wApua. See wbmp2xbm.pl for some simple example,
# how to use this module.
use strict;
### constructor
sub new {
shift;
my $self = {};
$self->{wbmp_string} = shift;
$self->{image_name} = (@_ ? shift : "WBMPtoXBM");
$self->{width} = 0;
$self->{height} = 0;
$self->{length} = length($self->{wbmp_string});
$self->{xbm_string} = 0;
$self->{config} ||= {};
$self->{config}{debug} = shift || 0;
bless($self);
return $self;
}
### Methods
sub xbm { # get the xbm equivalent of the given wbmp image
my $self = shift;
$self->convert unless $self->{xbm_string};
return $self->{xbm_string};
}
sub width { # get the width of the given image
my $self = shift;
$self->convert unless $self->{xbm_string};
return $self->{width};
}
sub height { # get the height of the given image
my $self = shift;
$self->convert unless $self->{xbm_string};
return $self->{height};
}
sub dimension { # get the width of the given image
my $self = shift;
$self->convert unless $self->{xbm_string};
return $self->{width}."×".$self->{height};
}
sub convert { # the converter itself, returns 0 if an error occured
my $self = shift;
my $debug = $self->{config}{debug};
my $wbmp = $self->{wbmp_string};
if (length $wbmp) {
my ($data, $rest) = &nextdata($wbmp); $wbmp = $rest;
print STDERR "WBMP Type: $data" if $debug >= 1;
if ($data != 0) {
warn "\nUnsupported WBMP type";
return 0;
}
print STDERR " -- OK.\n" if $debug >= 1;
($data, $rest) = &nextdata($wbmp); $wbmp = $rest;
print STDERR "WBMP FixHeader: $data" if $debug >= 1;
if ($data != 0) {
warn "\nUnsupported or wrong WBMP type (Extended headers are unsupported.)";
return 0;
}
print STDERR " -- OK.\n" if $debug >= 1;
($data, $rest) = &nextdata($wbmp); $wbmp = $rest;
my $width = $data;
($data, $rest) = &nextdata($wbmp); $wbmp = $rest;
my $height = $data;
$self->{width} = $width;
$self->{height} = $height;
my $woctets = ($width >> 3) + (($width % 8)?1:0);
my $octetrest = $width%8;
$octetrest = ($octetrest==0?8:$octetrest);
print STDERR "Image dimension: ${width}x$height ($woctets octets per row)\n"
if $debug >= 1;
$self->{xbm_string} =
("#define ".$self->{image_name}."_width $width\n".
"#define ".$self->{image_name}."_height $height\n".
"static char ".$self->{image_name}."_bits[] = {\n ");
my $xbmcol = 0;
my $col = 0;
while (length($wbmp) > 0) {
$xbmcol++;
$col++;
$data = ord(substr($wbmp,0,1));
$wbmp = substr($wbmp,1);
$self->{xbm_string} .= sprintf(" 0x%.2x,",&little_big($data)^0xff);
if ($xbmcol > 11) {
$self->{xbm_string} .= " \n ";
$xbmcol = 0;
}
}
$self->{xbm_string} .= " };\n";
return $self->{xbm_string};
} else {
return 0;
}
}
### Subroutines
sub little_big { # converts little endian 8bit integers into big
# endian ones (and vice versa of course ;-)
my $in = shift;
my $out = 0;
my $i;
foreach $i (0..7) {
if (($in & (1<<(7-$i))) == (1<<(7-$i))) {
$out += (1<<$i) ;
#print "|";
} else {
#print "-";
}
}
#print "\n";
return $out;
}
sub header { # reads one byte of some multibyte integer according to WAE
my $char = shift;
die "Not very well programmed" if length($char) != 1;
my ($value,$cont);
$value = (ord($char) & 127);# << 1;
$cont = ((ord($char) & 128) == 128)?1:0;
return ($value,$cont);
}
sub nextdata { # returns the next multibyte integer of the given
# string and the rest of the string
my $string = shift;
my $cont = 1;
my $value;
my $data = 0;
while ($cont) {
my $char = substr($string,0,1);
$string = substr($string,1);
($value,$cont) = &header($char);
$data += $value;
#print "Value: $value; Cont: $cont\n";
}
return ($data, $string)
}
1;
|