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