home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 March / PCO3_97.ISO / filesbbs / os2 / lzo026.arj / LZO026.ZIP / lzo-0.26 / src / lzo1b_cr.ch < prev    next >
Encoding:
Text File  |  1996-07-27  |  3.0 KB  |  113 lines

  1. /* lzo1b_cr.ch -- implementation of the LZO1B compression algorithm
  2.  
  3.    This file is part of the LZO real-time data compression library.
  4.  
  5.    Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
  6.  
  7.    The LZO library is free software; you can redistribute it and/or
  8.    modify it under the terms of the GNU General Public License as
  9.    published by the Free Software Foundation; either version 2 of
  10.    the License, or (at your option) any later version.
  11.  
  12.    The LZO library is distributed in the hope that it will be useful,
  13.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.    GNU General Public License for more details.
  16.  
  17.    You should have received a copy of the GNU General Public License
  18.    along with the LZO library; see the file COPYING.
  19.    If not, write to the Free Software Foundation, Inc.,
  20.    59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21.  
  22.    Markus F.X.J. Oberhumer
  23.    markus.oberhumer@jk.uni-linz.ac.at
  24.  */
  25.  
  26.  
  27. /* WARNING: this file should *not* be used by applications. It is
  28.    part of the implementation of the library and is subject
  29.    to change.
  30.  */
  31.  
  32.  
  33.  
  34. /***********************************************************************
  35. // store the current literal run
  36. ************************************************************************/
  37.  
  38.         assert(ip < ip_end);
  39.         if (ip - ii > 0)
  40.         {
  41.             lzo_uint t = ip - ii;
  42.  
  43. #if defined(LZO_HAVE_R1)
  44.             if (ip == r1)
  45.             {
  46.                 /* Code a context sensitive R1 match. */
  47.                 LZO_STATS(lzo_stats->literals += t);
  48.                 LZO_STATS(lzo_stats->r1_matches++);
  49.                 assert(t == 1);
  50.                 /* modify marker byte */
  51.                 assert((op[-2] >> M2O_BITS) == (M2_MARKER >> M2O_BITS));
  52.                 op[-2] &= M2O_MASK;
  53.                 assert((op[-2] >> M2O_BITS) == 0);
  54.                 /* copy 1 literal */
  55.                 *op++ = *ii++;
  56.                 r1 = ip + (M2_MIN_LEN + 1);        /* set new R1 pointer */
  57.             }
  58.             else 
  59. #endif
  60.             if (t < R0MIN)
  61.             {
  62.                 /* inline the copying of a short run */
  63.                 LZO_STATS(lzo_stats->literals += t);
  64.                 LZO_STATS(lzo_stats->lit_runs++);
  65.                 LZO_STATS(lzo_stats->lit_run[t]++);
  66. #if defined(LZO_HAVE_M3)
  67.                 if (t < LZO_SIZE(8-M3O_BITS) && op == m3)
  68.                 {
  69.                 /* Code a very short literal run into the low offset bits
  70.                  * of the previous M3/M4 match.
  71.                  */
  72.                     LZO_STATS(lzo_stats->lit_runs_after_m3_match++);
  73.                     LZO_STATS(lzo_stats->lit_run_after_m3_match[t]++);
  74.                     assert((m3[-2] >> M3O_BITS) == 0);
  75.                     m3[-2] |= LZO_BYTE(t << M3O_BITS);
  76.                 }
  77.                 else
  78. #endif
  79.                 {
  80.                     *op++ = LZO_BYTE(t);
  81.                 }
  82.                 MEMCPY_DS(op, ii, t);
  83. #if defined(LZO_HAVE_R1)
  84.                 r1 = ip + (M2_MIN_LEN + 1);        /* set new R1 pointer */
  85. #endif
  86.             }
  87.             else if (t < R0FAST)
  88.             {
  89.                 /* inline the copying of a short R0 run */
  90.                 LZO_STATS(lzo_stats->literals += t);
  91.                 LZO_STATS(lzo_stats->r0short_runs++);
  92.                 *op++ = 0; *op++ = LZO_BYTE(t - R0MIN);
  93.                 MEMCPY_DS(op, ii, t);
  94. #if defined(LZO_HAVE_R1)
  95.                 r1 = ip + (M2_MIN_LEN + 1);        /* set new R1 pointer */
  96. #endif
  97.             }
  98.             else
  99.             {
  100.                 op = STORE_RUN(op,ii,t);
  101.                 ii = ip;
  102.             }
  103.         }
  104.  
  105.  
  106.         /* ii now points to the start of the current match */
  107.         assert(ii == ip);
  108.  
  109.  
  110. /*
  111. vi:ts=4
  112. */
  113.