EBook-Tools

 view release on metacpan or  search on metacpan

lib/EBook/Tools/LZSS.pm  view on Meta::CPAN

                $highoffset = $bitvector->Chunk_Read($extrabits,$bitoffset);

                $lzss_offset = (256 * $highoffset) + $lowoffset;
            }
            else
            {
                $bitoffset -= $offsetbits;
                $lzss_offset = $bitvector->Chunk_Read($offsetbits,$bitoffset);
            }
            $bitoffset -= $lengthbits;
            $lzss_length = $bitvector->Chunk_Read($lengthbits,$bitoffset);

            if($lzss_offset > $windowsize)
            {
                carp($subname,"(): LZSS offset points outside window!\n");
                last;
            }

            if($lzss_length == 0
               and $lzss_offset == 0)
            {
                if($bitoffset >= 16)
                {
                    carp($subname,"(): invalid LZSS code at bit position ",
                         $bitpos," [",$bitoffset," bits remaining]!\n");
                }
                last;
            }
            $bitpos += ($offsetbits + $lengthbits);
            $lzss_length += $max_uncoded + 1;

            foreach my $lzss_pos (0 .. ($lzss_length - 1) )
            {
                my $windowoffset;
                my $char = substr($window,
                                  ($lzss_offset + $lzss_pos) % $windowsize,
                                  1);
                substr($window,$windowpos,1,$char);
                $windowpos++;
                $windowpos %= $windowsize;
                $uncompressed .= $char;
            }
        }
    }

    if($self->{verbose} or $EBook::Tools::debug > 0)
    {
        print("Finished uncompressing text.\n");
    }
    return \$uncompressed;
}


################################
########## PROCEDURES ##########
################################


########## END CODE ##########

=head1 BUGS AND LIMITATIONS

=over

=item * Compression not yet implemented.

=item * The LZSS algorithm isn't documented in the POD.

=item * Once compression is implemented and the algorithm is
documented, this module is a good candidate for being forked off into
its own project.  Relying on it to keep its current name may be
unwise.

=back


=head1 AUTHOR

Zed Pobre <zed@debian.org>

The design of this module was based on the C LZSS library by Michael
Dipperstein, version 0.5.2, at http://michael.dipperstein.com/lzss/


=head1 LICENSE AND COPYRIGHT

Copyright 2008 Zed Pobre

Licensed to the public under the terms of the GNU GPL, version 2.

=cut

1;
__END__



( run in 2.401 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )