1 ## Copyright (C) 2007 Gorka Lertxundi
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn {Function File} {@var{c} =} lz77enco (@var{m}, @var{alph}, @var{la}, @var{n})
18 ## Lempel-Ziv 77 source algorithm implementation. Where
22 ## encoded message (Mx3).
26 ## lookahead buffer size.
28 ## sliding window buffer size.
33 function c = lz77enco(m, alph, la, n)
35 if (la <= 0 || n <= 0)
36 error("lz77enco: Lookahead buffer size and window size must be higher than 0.2");
39 error("lz77enco: Unreachable configuration: n - la >= la.");
42 error("lz77enco: Alphabet size within less than 2 symbols?");
45 error("lz77enco: It is not possible to codify the message, too small alphabet size.");
48 error("lz77enco: Message to encode must be a 1xN matrix.");
59 window(1:n-la) = window(enco(2)+2:n-la+enco(2)+1);
61 window(n-la+1:n) = [m(len-x+1:len) zeros(1,la-x)];
63 window(n-la+1:n) = m(len-x+1:len-x+la);
66 ## get a reference (position ,length) to longest match, and next symbol
70 while(z ~= la && (window(y+z) == window(n-la+z+1)))
77 enco(3) = window(n-la+z+1);
93 %! lz77enco([0 0 1 0 1 0 2 1 0 2 1 0 2 1 2 0 2 1 0 2 1 2 0 0],3,9,18)