#!/usr/local/bin/perl

# $Id: pbm2tbm,v 1.3 1997/10/25 13:45:40 czyborra Exp $

@_=<>; $"=""; $_="@_";
if (s=^P4\s+(\d+)\s+(\d+)\s==)
{
    $O=int(($1+7)/8); s=([\s\S]{$O})\s?=unpack("B*",$1)."\n"=ge;
}
else
{
    s=#.*\n=\n=g;
    s=^P1\s+(\d+)\s+(\d+)\s*==
	|| die "Input not in PBM format\n";
    $L=$1;
    s=\s+==g;
    s=.{$L}=$&\n=g;
}
y=01=-#=;
print;
