Range Coder for Perl
Perl
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples
inc/Module
lib/Algorithm
t
Changes
MANIFEST
Makefile.PL
README

README

NAME
    Algorithm::RangeCoder - Data compression with Range Coder

SYNOPSIS
      use Algorithm::RangeCoder;
      use constant UCHAR_MAX => 0x100;

      my $str = shift or die "usage: $0 <string>";

      my @char = unpack('C*', $str);

      my @freq;
      for (my $i = 0; $i < UCHAR_MAX; $i++) {
          $freq[$i] = 0;
      }

      for my $c (@char) {
          $freq[$c]++;
      }

      my @cum = (0);
      for (my $i = 0; $i < UCHAR_MAX; $i++) {
          $cum[$i + 1] = $cum[$i] + $freq[$i];
      }

      my $rc = Algorithm::RangeCoder->new;
      $rc->freq    = \@freq;
      $rc->cumfreq = \@cum;

      my $bin = $rc->encode($str);

      say "origin:  ", $str;
      say "decoded: ", $rc->decode( $bin );

DESCRIPTION
    Range coder is an algorithm used for entropy coding in compression
    algorithms.

SEE ALSO
    <http://en.wikipedia.org/wiki/Range_encoding>

AUTHOR
    Naoya Ito, <naoya at bloghackers.net<gt>

COPYRIGHT AND LICENSE
    Copyright (C) 2008 by Naoya Ito

    This library is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself, either Perl version 5.8.8 or, at
    your option, any later version of Perl 5 you may have available.