diff --git a/include/lzf.h b/include/lzf.h index 919b6e6be2d..8d44fe679f7 100644 --- a/include/lzf.h +++ b/include/lzf.h @@ -1,5 +1,9 @@ -/* - * Copyright (c) 2000-2008 Marc Alexander Lehmann +/**************************************************************************** + * lzf -- an extremely fast/free compression/decompression-method + * http://liblzf.plan9.de/ + * + * Copyright (c) 2000-2008 Marc Alexander Lehmann + * This algorithm is believed to be patent-free. * * Redistribution and use in source and binary forms, with or without modifica- * tion, are permitted provided that the following conditions are met: @@ -22,34 +26,37 @@ * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * - * Alternatively, the contents of this file may be used under the terms of - * the GNU General Public License ("GPL") version 2 or any later version, - * in which case the provisions of the GPL are applicable instead of - * the above. If you wish to allow the use of your version of this file - * only under the terms of the GPL and not to allow others to use your - * version of this file under the BSD license, indicate your decision - * by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL. If you do not delete the - * provisions above, a recipient may use your version of this file under - * either the BSD or the GPL. - */ + ****************************************************************************/ -#ifndef LZF_H -#define LZF_H +#ifndef __INCLUDE_LZF_H +#define __INCLUDE_LZF_H 1 -/*********************************************************************** -** -** lzf -- an extremely fast/free compression/decompression-method -** http://liblzf.plan9.de/ -** -** This algorithm is believed to be patent-free. -** -***********************************************************************/ +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ #define LZF_VERSION 0x0105 /* 1.5, API version */ +#define HLOG CONFIG_LIBC_LZF_HLOG -/* - * Compress in_len bytes stored at the memory block starting at +/**************************************************************************** + * Public Types + ****************************************************************************/ + +#if LZF_USE_OFFSETS +# define LZF_HSLOT_BIAS ((const uint8_t *)in_data) + typedef unsigned int lzf_hslot_t; +#else +# define LZF_HSLOT_BIAS 0 + typedef const uint8_t *lzf_hslot_t; +#endif + +typedef lzf_hslot_t LZF_STATE[1 << HLOG]; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/* Compress in_len bytes stored at the memory block starting at * in_data and write the result to out_data, up to a maximum length * of out_len bytes. * @@ -71,14 +78,13 @@ * If the option LZF_STATE_ARG is enabled, an extra argument must be * supplied which is not reflected in this header file. Refer to lzfP.h * and lzf_c.c. - * */ -unsigned int -lzf_compress (const void *const in_data, unsigned int in_len, - void *out_data, unsigned int out_len); -/* - * Decompress data compressed with some version of the lzf_compress +unsigned int lzf_compress(FAR const void *const in_data, + unsigned int in_len, FAR void *out_data, + unsigned int out_len); + +/* Decompress data compressed with some version of the lzf_compress * function and stored at location in_data and length in_len. The result * will be stored at out_data up to a maximum of out_len characters. * @@ -92,9 +98,9 @@ lzf_compress (const void *const in_data, unsigned int in_len, * * This function is very fast, about as fast as a copying loop. */ -unsigned int -lzf_decompress (const void *const in_data, unsigned int in_len, - void *out_data, unsigned int out_len); -#endif +unsigned int lzf_decompress(FAR const void *const in_data, + unsigned int in_len, FAR void *out_data, + unsigned int out_len); +#endif /* __INCLUDE_LZF_H */ diff --git a/libc/lzf/Kconfig b/libc/lzf/Kconfig index 3b27143ddfd..9bb34a33ec9 100644 --- a/libc/lzf/Kconfig +++ b/libc/lzf/Kconfig @@ -29,6 +29,22 @@ config LIBC_LZF_FASTEST endchoice # Compression options +config LIBC_LZF_HLOG + int "Log2 Hash table size" + default 13 + range 1 22 + ---help--- + Size of hashtable is (1 << HLOG) * sizeof (char *). Decompression is + independent of the hash table size the difference between 15 and 14 is + very small for small blocks (and 14 is usually a bit faster). For a + low-memory/faster configuration, use HLOG == 13; For best compression, + use 15 or 16 (or more, up to 22). + +#ifndef HLOG +# define HLOG 13 +#endif + + config LIBC_LZF_ALIGN bool "Strict alignment" default y diff --git a/libc/lzf/lzfP.h b/libc/lzf/lzfP.h index 0b5c470cba9..45a089ab261 100644 --- a/libc/lzf/lzfP.h +++ b/libc/lzf/lzfP.h @@ -54,17 +54,6 @@ using namespace std; * Pre-processor Definitions ****************************************************************************/ -/* Size of hashtable is (1 << HLOG) * sizeof (char *). Decompression is - * independent of the hash table size the difference between 15 and 14 is - * very small for small blocks (and 14 is usually a bit faster). For a - * low-memory/faster configuration, use HLOG == 13; For best compression, - * use 15 or 16 (or more, up to 22). - */ - -#ifndef HLOG -# define HLOG 13 -#endif - /* You may choose to pre-set the hash table (might be faster on some modern * CPUs and large (>>64k) blocks, and also makes compression deterministic/ * repeatable when the configuration otherwise is the same). @@ -110,14 +99,4 @@ using namespace std; * Public Types ****************************************************************************/ -#if LZF_USE_OFFSETS -# define LZF_HSLOT_BIAS ((const uint8_t *)in_data) - typedef unsigned int LZF_HSLOT; -#else -# define LZF_HSLOT_BIAS 0 - typedef const uint8_t *LZF_HSLOT; -#endif - -typedef LZF_HSLOT LZF_STATE[1 << (HLOG)]; - #endif /* __LIBC_LZF_LZFP_H */ diff --git a/libc/lzf/lzf_c.c b/libc/lzf/lzf_c.c index 28af584e647..20ae7bf2d8b 100644 --- a/libc/lzf/lzf_c.c +++ b/libc/lzf/lzf_c.c @@ -147,7 +147,7 @@ unsigned int lzf_compress(FAR const void *const in_data, unsigned int in_len, hval = FRST (ip); while (ip < in_end - 2) { - LZF_HSLOT *hslot; + lzf_hslot_t *hslot; hval = NEXT (hval, ip); hslot = htab + IDX (hval);