]> wimlib.net Git - wimlib/commitdiff
Export compression and decompression functions
authorEric Biggers <ebiggers3@gmail.com>
Thu, 28 Mar 2013 16:55:53 +0000 (11:55 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Thu, 28 Mar 2013 16:55:53 +0000 (11:55 -0500)
programs/imagex.c
src/lzx-compress.c
src/lzx-decompress.c
src/lzx.h
src/resource.c
src/wimlib.h
src/write.c
src/xpress-compress.c
src/xpress-decompress.c
src/xpress.h

index ffc841f680d16fd008995bcd0f8f7be90c4e44bf..d9ac676f9a126b01fb399172715d4732939dfd57 100644 (file)
@@ -23,8 +23,8 @@
  */
 
 #include "config.h"
  */
 
 #include "config.h"
-#include "wimlib_tchar.h"
 #include "wimlib.h"
 #include "wimlib.h"
+#include "wimlib_tchar.h"
 
 #include <ctype.h>
 #include <errno.h>
 
 #include <ctype.h>
 #include <errno.h>
index eb84d0cea108a69dfc16c1f0558d93e49b8724a2..a811d51c9ec9ffd43a5064d853b89aca888b1cc8 100644 (file)
@@ -27,8 +27,8 @@
 
 
 /*
 
 
 /*
- * 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.
  *
  * Please see the comments in lzx-decompress.c for more information about this
  * compression format.
@@ -57,6 +57,7 @@
  * blocks from one input chunk is not yet implemented.
  */
 
  * blocks from one input chunk is not yet implemented.
  */
 
+#include "wimlib.h"
 #include "lzx.h"
 #include "compress.h"
 #include <stdlib.h>
 #include "lzx.h"
 #include "compress.h"
 #include <stdlib.h>
@@ -638,18 +639,10 @@ static const struct lz_params lzx_lz_params = {
        .too_far        = 4096,
 };
 
        .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];
 {
        struct output_bitstream ostream;
        u8 uncompressed_data[uncompressed_len + 8];
@@ -754,8 +747,8 @@ lzx_compress(const void *__uncompressed_data, unsigned uncompressed_len,
 #ifdef ENABLE_VERIFY_COMPRESSION
        /* Verify that we really get the same thing back when decompressing. */
        u8 buf[uncompressed_len];
 #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();
        if (ret != 0) {
                ERROR("lzx_compress(): Failed to decompress data we compressed");
                abort();
index da462186c06870b2038098bc0b3aab97dc6dd229..18fa3d008b6b137bc77b8235839c8a93679a4871 100644 (file)
  */
 
 #include "util.h"
  */
 
 #include "util.h"
+#include "wimlib.h"
 #include "lzx.h"
 #include "decompress.h"
 #include <string.h>
 #include "lzx.h"
 #include "decompress.h"
 #include <string.h>
@@ -786,27 +787,10 @@ lzx_decompress_block(int block_type, unsigned block_size,
        return 0;
 }
 
        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;
 {
        struct lzx_tables tables;
        struct input_bitstream istream;
index ed6a4d4ec2aba1c87af50033bf22649495a55cab..5f87076e6a100363a3f98b4c149047ca40189f75 100644 (file)
--- a/src/lzx.h
+++ b/src/lzx.h
@@ -102,12 +102,4 @@ struct lru_queue {
        u32 R2;
 };
 
        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 */
 #endif /* _WIMLIB_LZX_H */
index 7df50e727ab7eeb1c240d0afbafe0a880a5ea4bd..a8e98ca41d2c88786795b724b17bd4da523415c7 100644 (file)
@@ -26,8 +26,6 @@
 #include "dentry.h"
 #include "lookup_table.h"
 #include "buffer_io.h"
 #include "dentry.h"
 #include "lookup_table.h"
 #include "buffer_io.h"
-#include "lzx.h"
-#include "xpress.h"
 #include "sha1.h"
 
 #ifdef __WIN32__
 #include "sha1.h"
 
 #ifdef __WIN32__
@@ -89,9 +87,9 @@ read_compressed_resource(FILE *fp, u64 resource_compressed_size,
        int (*decompress)(const void *, unsigned, void *, unsigned);
        /* Set the appropriate decompress function. */
        if (resource_ctype == WIMLIB_COMPRESSION_TYPE_LZX)
        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
        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
 
        /* The structure of a compressed resource consists of a table of chunk
         * offsets followed by the chunks themselves.  Each chunk consists of
index d3b0c9a6212188bb9e614da412d69c230ff7e519..f0be7acdba028fcc24c54fc39d321c6974af252a 100644 (file)
@@ -613,7 +613,7 @@ struct wimlib_pattern_list {
         * but the @a pats pointer itself will not.  See the man page for
         * <b>wimlib-imagex capture</b> for more information about allowed
         * patterns. */
         * 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;
 
        /** Number of patterns in the @a pats array. */
        size_t num_pats;
@@ -641,7 +641,7 @@ struct wimlib_capture_config {
        struct wimlib_pattern_list reserved2;
 
        /** Library internal use only. */
        struct wimlib_pattern_list reserved2;
 
        /** Library internal use only. */
-       tchar *_prefix;
+       wimlib_tchar *_prefix;
 
        /** Library internal use only. */
        size_t _prefix_num_tchars;
 
        /** Library internal use only. */
        size_t _prefix_num_tchars;
@@ -1656,6 +1656,64 @@ wimlib_join(const wimlib_tchar * const *swms,
            int wim_write_flags,
            wimlib_progress_func_t progress_func);
 
            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.
  *
 /**
  * Mounts an image in a WIM file on a directory read-only or read-write.
  *
@@ -2410,4 +2468,19 @@ wimlib_write(WIMStruct *wim,
             unsigned num_threads,
             wimlib_progress_func_t progress_func);
 
             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 */
 #endif /* _WIMLIB_H */
index d985aafee2494b43eca7791cd72e8dd8b6ce9188..184489b1aecf249e97a5f35747bcaa520f26996d 100644 (file)
@@ -42,9 +42,6 @@
 #include "dentry.h"
 #include "lookup_table.h"
 #include "xml.h"
 #include "dentry.h"
 #include "lookup_table.h"
 #include "xml.h"
-#include "lzx.h"
-#include "xpress.h"
-
 
 #ifdef ENABLE_MULTITHREADED_COMPRESSION
 #  include <pthread.h>
 
 #ifdef ENABLE_MULTITHREADED_COMPRESSION
 #  include <pthread.h>
@@ -152,8 +149,9 @@ out:
 
 /*
  * compress_func_t- Pointer to a function to compresses a chunk
 
 /*
  * 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.
  *
  * @chunk:       Uncompressed data of the chunk.
  * @chunk_size:          Size of the uncompressed chunk, in bytes.
@@ -179,9 +177,9 @@ compress_func_t
 get_compress_func(int out_ctype)
 {
        if (out_ctype == WIMLIB_COMPRESSION_TYPE_LZX)
 get_compress_func(int out_ctype)
 {
        if (out_ctype == WIMLIB_COMPRESSION_TYPE_LZX)
-               return lzx_compress;
+               return wimlib_lzx_compress;
        else
        else
-               return xpress_compress;
+               return wimlib_xpress_compress;
 }
 
 /*
 }
 
 /*
index 466dd7553811c73b7efe028a56e81b3d24ae78d1..68d2890656040be259f57f5b5bc69beaf354b52b 100644 (file)
@@ -26,7 +26,9 @@
  */
 
 #include "xpress.h"
  */
 
 #include "xpress.h"
+#include "wimlib.h"
 #include "compress.h"
 #include "compress.h"
+
 #include <stdlib.h>
 #include <string.h>
 
 #include <stdlib.h>
 #include <string.h>
 
@@ -139,18 +141,10 @@ static const struct lz_params xpress_lz_params = {
        .too_far        = 4096,
 };
 
        .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;
 {
        const u8 *uncompressed_data = __uncompressed_data;
        u8 *compressed_data = __compressed_data;
@@ -245,8 +239,8 @@ xpress_compress(const void *__uncompressed_data, unsigned uncompressed_len,
 #ifdef ENABLE_VERIFY_COMPRESSION
        /* Verify that we really get the same thing back when decompressing. */
        u8 buf[uncompressed_len];
 #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");
        if (ret) {
                ERROR("xpress_compress(): Failed to decompress data we "
                      "compressed");
index c16b5e32019085c5308bd136d73a94dd5439bc5c..380f017d8834bb071435126cef8968578a28eba6 100644 (file)
@@ -200,9 +200,10 @@ xpress_decompress_block(struct input_bitstream *istream,
 }
 
 
 }
 
 
-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];
 {
        u8 lens[XPRESS_NUM_SYMBOLS];
        u16 decode_table[(1 << XPRESS_TABLEBITS) + 2 * XPRESS_NUM_SYMBOLS];
index c457a72e09cff19f21439e63ccb2b7d022dc704b..2949780c00e71fd3cd29bba94f144165ed395399 100644 (file)
 #define XPRESS_MIN_MATCH       3
 #define XPRESS_MAX_MATCH       65538
 
 #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 */
 #endif /* _WIMLIB_XPRESS_H */