*/
#include "config.h"
-#include "wimlib_tchar.h"
#include "wimlib.h"
+#include "wimlib_tchar.h"
#include <ctype.h>
#include <errno.h>
/*
- * This file provides lzx_compress(), a function to compress an in-memory buffer
- * of data using LZX compression, as used in the WIM file format.
+ * This file provides wimlib_lzx_compress(), a function to compress an in-memory
+ * buffer of data using LZX compression, as used in the WIM file format.
*
* Please see the comments in lzx-decompress.c for more information about this
* compression format.
* blocks from one input chunk is not yet implemented.
*/
+#include "wimlib.h"
#include "lzx.h"
#include "compress.h"
#include <stdlib.h>
.too_far = 4096,
};
-/*
- * Performs LZX compression on a block of data.
- *
- * Please see the documentation for the 'compress_func_t' type in write.c for
- * the exact behavior of this function and how to call it.
- */
-#ifdef EXPORT_COMPRESSION_FUNCTIONS
-WIMLIBAPI
-#endif
-unsigned
-lzx_compress(const void *__uncompressed_data, unsigned uncompressed_len,
- void *compressed_data)
+/* Documented in wimlib.h */
+WIMLIBAPI unsigned
+wimlib_lzx_compress(const void *__uncompressed_data, unsigned uncompressed_len,
+ void *compressed_data)
{
struct output_bitstream ostream;
u8 uncompressed_data[uncompressed_len + 8];
#ifdef ENABLE_VERIFY_COMPRESSION
/* Verify that we really get the same thing back when decompressing. */
u8 buf[uncompressed_len];
- ret = lzx_decompress(compressed_data, compressed_len, buf,
- uncompressed_len);
+ ret = wimlib_lzx_decompress(compressed_data, compressed_len,
+ buf, uncompressed_len);
if (ret != 0) {
ERROR("lzx_compress(): Failed to decompress data we compressed");
abort();
*/
#include "util.h"
+#include "wimlib.h"
#include "lzx.h"
#include "decompress.h"
#include <string.h>
return 0;
}
-/*
- * Decompresses a block of LZX-compressed data as used in the WIM file format.
- *
- * Note that this will NOT work unmodified for LZX as used in the cabinet
- * format, which is not the same as in the WIM format!
- *
- * @compressed_data: A pointer to the compressed data.
- *
- * @compressed_len: The length of the compressed data, in bytes.
- *
- * @uncompressed_data: A pointer to the buffer into which to write the
- * uncompressed data.
- *
- * @uncompressed_len: The length of the uncompressed data. It must be
- * 32768 bytes or less.
- *
- * Return 0 on success; non-zero on failure.
- */
-int
-lzx_decompress(const void *compressed_data, unsigned compressed_len,
- void *uncompressed_data, unsigned uncompressed_len)
+/* Documented in wimlib.h */
+WIMLIBAPI int
+wimlib_lzx_decompress(const void *compressed_data, unsigned compressed_len,
+ void *uncompressed_data, unsigned uncompressed_len)
{
struct lzx_tables tables;
struct input_bitstream istream;
u32 R2;
};
-extern int
-lzx_decompress(const void *compressed_data, unsigned compressed_len,
- void *uncompressed_data, unsigned uncompressed_len);
-
-extern unsigned
-lzx_compress(const void *uncompressed_data, unsigned uncompressed_len,
- void *compressed_data);
-
#endif /* _WIMLIB_LZX_H */
#include "dentry.h"
#include "lookup_table.h"
#include "buffer_io.h"
-#include "lzx.h"
-#include "xpress.h"
#include "sha1.h"
#ifdef __WIN32__
int (*decompress)(const void *, unsigned, void *, unsigned);
/* Set the appropriate decompress function. */
if (resource_ctype == WIMLIB_COMPRESSION_TYPE_LZX)
- decompress = lzx_decompress;
+ decompress = wimlib_lzx_decompress;
else
- decompress = xpress_decompress;
+ decompress = wimlib_xpress_decompress;
/* The structure of a compressed resource consists of a table of chunk
* offsets followed by the chunks themselves. Each chunk consists of
* but the @a pats pointer itself will not. See the man page for
* <b>wimlib-imagex capture</b> for more information about allowed
* patterns. */
- tchar **pats;
+ wimlib_tchar **pats;
/** Number of patterns in the @a pats array. */
size_t num_pats;
struct wimlib_pattern_list reserved2;
/** Library internal use only. */
- tchar *_prefix;
+ wimlib_tchar *_prefix;
/** Library internal use only. */
size_t _prefix_num_tchars;
int wim_write_flags,
wimlib_progress_func_t progress_func);
+/**
+ * Compress a chunk of a WIM resource using LZX compression.
+ *
+ * This function is exported for convenience only and need not be used.
+ *
+ * @param chunk
+ * Uncompressed data of the chunk.
+ * @param chunk_size
+ * Size of the uncompressed chunk, in bytes.
+ * @param out
+ * Pointer to output buffer of size at least (@a chunk_size - 1) bytes.
+ *
+ * @return
+ * The size of the compressed data written to @a out in bytes, or 0 if the
+ * data could not be compressed to (@a chunk_size - 1) bytes or fewer.
+ *
+ * As a special requirement, the compression code is optimized for the WIM
+ * format and therefore requires (@a chunk_size <= 32768).
+ *
+ * As another special requirement, the compression code will read up to 8 bytes
+ * off the end of the @a chunk array for performance reasons. The values of
+ * these bytes will not affect the output of the compression, but the calling
+ * code must make sure that the buffer holding the uncompressed chunk is
+ * actually at least (@a chunk_size + 8) bytes, or at least that these extra
+ * bytes are in mapped memory that will not cause a memory access violation if
+ * accessed.
+ */
+extern unsigned
+wimlib_lzx_compress(const void *chunk, unsigned chunk_size, void *out);
+
+/**
+ * Decompresses a block of LZX-compressed data as used in the WIM file format.
+ *
+ * Note that this will NOT work unmodified for LZX as used in the cabinet
+ * format, which is not the same as in the WIM format!
+ *
+ * This function is exported for convenience only and need not be used.
+ *
+ * @param compressed_data
+ * Pointer to the compressed data.
+ *
+ * @param compressed_len
+ * Length of the compressed data, in bytes.
+ *
+ * @param uncompressed_data
+ * Pointer to the buffer into which to write the uncompressed data.
+ *
+ * @param uncompressed_len
+ * Length of the uncompressed data. It must be 32768 bytes or less.
+ *
+ * @return
+ * 0 on success; non-zero on failure.
+ */
+extern int
+wimlib_lzx_decompress(const void *compressed_data, unsigned compressed_len,
+ void *uncompressed_data, unsigned uncompressed_len);
+
+
/**
* Mounts an image in a WIM file on a directory read-only or read-write.
*
unsigned num_threads,
wimlib_progress_func_t progress_func);
+/**
+ * This function is equivalent to wimlib_lzx_compress(), but instead compresses
+ * the data using "XPRESS" compression.
+ */
+extern unsigned
+wimlib_xpress_compress(const void *chunk, unsigned chunk_size, void *out);
+
+/**
+ * This function is equivalent to wimlib_lzx_decompress(), but instead assumes
+ * the data is compressed using "XPRESS" compression.
+ */
+extern int
+wimlib_xpress_decompress(const void *compressed_data, unsigned compressed_len,
+ void *uncompressed_data, unsigned uncompressed_len);
+
#endif /* _WIMLIB_H */
#include "dentry.h"
#include "lookup_table.h"
#include "xml.h"
-#include "lzx.h"
-#include "xpress.h"
-
#ifdef ENABLE_MULTITHREADED_COMPRESSION
# include <pthread.h>
/*
* compress_func_t- Pointer to a function to compresses a chunk
- * of a WIM resource. This may be either xpress_compress()
- * (xpress-compress.c) or lzx_compress() (lzx-compress.c).
+ * of a WIM resource. This may be either
+ * wimlib_xpress_compress() (xpress-compress.c) or
+ * wimlib_lzx_compress() (lzx-compress.c).
*
* @chunk: Uncompressed data of the chunk.
* @chunk_size: Size of the uncompressed chunk, in bytes.
get_compress_func(int out_ctype)
{
if (out_ctype == WIMLIB_COMPRESSION_TYPE_LZX)
- return lzx_compress;
+ return wimlib_lzx_compress;
else
- return xpress_compress;
+ return wimlib_xpress_compress;
}
/*
*/
#include "xpress.h"
+#include "wimlib.h"
#include "compress.h"
+
#include <stdlib.h>
#include <string.h>
.too_far = 4096,
};
-/*
- * Performs XPRESS compression on a block of data.
- *
- * Please see the documentation for the 'compress_func_t' type in write.c for
- * the exact behavior of this function and how to call it.
- */
-#ifdef EXPORT_COMPRESSION_FUNCTIONS
-WIMLIBAPI
-#endif
-unsigned
-xpress_compress(const void *__uncompressed_data, unsigned uncompressed_len,
- void *__compressed_data)
+/* Documented in wimlib.h */
+WIMLIBAPI unsigned
+wimlib_xpress_compress(const void *__uncompressed_data,
+ unsigned uncompressed_len, void *__compressed_data)
{
const u8 *uncompressed_data = __uncompressed_data;
u8 *compressed_data = __compressed_data;
#ifdef ENABLE_VERIFY_COMPRESSION
/* Verify that we really get the same thing back when decompressing. */
u8 buf[uncompressed_len];
- ret = xpress_decompress(__compressed_data, compressed_len, buf,
- uncompressed_len);
+ ret = wimlib_xpress_decompress(__compressed_data, compressed_len,
+ buf, uncompressed_len);
if (ret) {
ERROR("xpress_compress(): Failed to decompress data we "
"compressed");
}
-int
-xpress_decompress(const void *__compressed_data, unsigned compressed_len,
- void *uncompressed_data, unsigned uncompressed_len)
+/* Documented in wimlib.h */
+WIMLIBAPI int
+wimlib_xpress_decompress(const void *__compressed_data, unsigned compressed_len,
+ void *uncompressed_data, unsigned uncompressed_len)
{
u8 lens[XPRESS_NUM_SYMBOLS];
u16 decode_table[(1 << XPRESS_TABLEBITS) + 2 * XPRESS_NUM_SYMBOLS];
#define XPRESS_MIN_MATCH 3
#define XPRESS_MAX_MATCH 65538
-extern int
-xpress_decompress(const void *compressed_data, unsigned compressed_len,
- void *uncompressed_data, unsigned uncompressed_len);
-
-extern unsigned
-xpress_compress(const void *uncompressed_data, unsigned uncompressed_len,
- void *compressed_data);
-
#endif /* _WIMLIB_XPRESS_H */