Tizen 2.1 base
[external/lzo2.git] / src / lzo1a_cr.ch
1 /* lzo1a_cr.ch -- literal run handling for the the LZO1A 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 LZO package and is subject
43    to change.
44  */
45
46
47 #ifndef __LZO1A_CR_H
48 #define __LZO1A_CR_H
49
50
51 /***********************************************************************
52 // code a literal run
53 ************************************************************************/
54
55 static lzo_bytep
56 store_run(lzo_bytep const oo, const lzo_bytep const ii, lzo_uint r_len)
57 {
58     register lzo_bytep op;
59     register const lzo_bytep ip;
60     register lzo_uint t;
61
62     op = oo;
63     ip = ii;
64     assert(r_len > 0);
65
66     /* code a long R0 run */
67     if (r_len >= 512)
68     {
69         unsigned r_bits = 6;        /* 256 << 6 == 16384 */
70         lzo_uint tt = 32768u;
71
72         while (r_len >= (t = tt))
73         {
74             r_len -= t;
75             *op++ = 0; *op++ = (R0MAX - R0MIN);
76             MEMCPY8_DS(op, ip, t);
77             LZO_STATS(lzo_stats->r0long_runs++);
78         }
79         tt >>= 1;
80         do {
81             if (r_len >= (t = tt))
82             {
83                 r_len -= t;
84                 *op++ = 0; *op++ = LZO_BYTE((R0FAST - R0MIN) + r_bits);
85                 MEMCPY8_DS(op, ip, t);
86                 LZO_STATS(lzo_stats->r0long_runs++);
87             }
88             tt >>= 1;
89         } while (--r_bits > 0);
90     }
91     assert(r_len < 512);
92
93     while (r_len >= (t = R0FAST))
94     {
95         r_len -= t;
96         *op++ = 0; *op++ = (R0FAST - R0MIN);
97         MEMCPY8_DS(op, ip, t);
98         LZO_STATS(lzo_stats->r0fast_runs++);
99     }
100
101     t = r_len;
102     if (t >= R0MIN)
103     {
104         /* code a short R0 run */
105         *op++ = 0; *op++ = LZO_BYTE(t - R0MIN);
106         MEMCPY_DS(op, ip, t);
107         LZO_STATS(lzo_stats->r0short_runs++);
108     }
109     else if (t > 0)
110     {
111         /* code a short literal run */
112         LZO_STATS(lzo_stats->lit_runs++);
113         LZO_STATS(lzo_stats->lit_run[t]++);
114         *op++ = LZO_BYTE(t);
115         MEMCPY_DS(op, ip, t);
116     }
117
118     return op;
119 }
120
121
122
123 #endif /* already included */
124
125 /*
126 vi:ts=4:et
127 */
128