1 /* lzo1c_cc.c -- LZO1C compression internal entry point
3 This file is part of the LZO real-time data compression library.
5 Copyright (C) 1996-2015 Markus Franz Xaver Johannes Oberhumer
8 The LZO library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of
11 the License, or (at your option) any later version.
13 The LZO library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with the LZO library; see the file COPYING.
20 If not, write to the Free Software Foundation, Inc.,
21 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 Markus F.X.J. Oberhumer
24 <markus@oberhumer.com>
25 http://www.oberhumer.com/opensource/lzo/
29 #define LZO_NEED_DICT_H 1
33 /***********************************************************************
34 // compression internal entry point.
35 ************************************************************************/
38 _lzo1c_do_compress ( const lzo_bytep in
, lzo_uint in_len
,
39 lzo_bytep out
, lzo_uintp out_len
,
44 #if defined(LZO_TEST_COMPRESS_OVERRUN)
45 lzo_uint avail_out
= *out_len
;
49 #if (LZO_COLLECT_STATS)
50 _lzo1c_stats_init(lzo_stats
);
51 lzo_stats
->in_len
= in_len
;
55 /* don't try to compress a block that's too short */
61 else if (in_len
<= MIN_LOOKAHEAD
+ 1)
63 #if defined(LZO_RETURN_IF_NOT_COMPRESSIBLE)
65 r
= LZO_E_NOT_COMPRESSIBLE
;
67 *out_len
= pd(STORE_RUN(out
,in
,in_len
), out
);
68 r
= (*out_len
> in_len
) ? LZO_E_OK
: LZO_E_ERROR
;
72 r
= func(in
,in_len
,out
,out_len
,wrkmem
);
75 #if defined(LZO_EOF_CODE)
76 #if defined(LZO_TEST_COMPRESS_OVERRUN)
77 if (r
== LZO_E_OK
&& avail_out
- *out_len
< 3)
78 r
= LZO_E_COMPRESS_OVERRUN
;
82 lzo_bytep op
= out
+ *out_len
;
83 op
[0] = M3_MARKER
| 1;
91 #if (LZO_COLLECT_STATS)
92 lzo_stats
->out_len
= *out_len
;
93 lzo_stats
->match_bytes
=
94 1 * lzo_stats
->m1_matches
+ 2 * lzo_stats
->m2_matches
+
95 3 * lzo_stats
->m3_matches
+ 4 * lzo_stats
->m4_matches
;
96 _lzo1c_stats_calc(lzo_stats
);
103 /***********************************************************************
104 // note: this is not thread safe, but as it is used for finetuning only
106 ************************************************************************/
109 /* lzo_stats_t is still defined */
112 #if (LZO_COLLECT_STATS)
114 static lzo_stats_t lzo_statistics
;
115 lzo_stats_t
* const lzo1c_stats
= &lzo_statistics
;
118 void _lzo1c_stats_init(lzo_stats_t
*lzo_stats
)
120 lzo_memset(lzo_stats
,0,sizeof(*lzo_stats
));
124 void _lzo1c_stats_calc(lzo_stats_t
*lzo_stats
)
127 lzo_stats
->m1_matches
+ lzo_stats
->m2_matches
+
128 lzo_stats
->m3_matches
+ lzo_stats
->m4_matches
;
130 lzo_stats
->literal_overhead
= lzo_stats
->lit_runs
+
131 2 * (lzo_stats
->r0short_runs
+ lzo_stats
->r0fast_runs
+
132 lzo_stats
->r0long_runs
);
133 lzo_stats
->literal_bytes
= lzo_stats
->literals
+
134 lzo_stats
->literal_overhead
;
137 assert(lzo_stats
->match_bytes
+ lzo_stats
->literal_bytes
==
141 lzo_stats
->m2_matches
-= lzo_stats
->r1_matches
;
142 lzo_stats
->m2_match
[M2_MIN_LEN
] -= lzo_stats
->r1_matches
;
144 if (lzo_stats
->literals
> 0)
145 lzo_stats
->literal_overhead_percent
=
146 100.0 * lzo_stats
->literal_overhead
/ lzo_stats
->literals
;
153 /* vim:set ts=4 sw=4 et: */