aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLode Vandevenne <lode@google.com>2013-03-06 14:09:53 +0100
committerLode Vandevenne <lode@google.com>2013-03-06 14:09:53 +0100
commit6276dcd1677e74ea1c0284fffebc3c763b424351 (patch)
tree6af6486269170688d54cfdc61022730667e5c5c5
parent8c218eff39749e738c92bf34155099ad280c16f7 (diff)
downloadzopfli-6276dcd1677e74ea1c0284fffebc3c763b424351.tar.gz
Make a better distinction between zopfli binary and library
-rw-r--r--zopfli.h71
-rw-r--r--zopfli_lib.c37
2 files changed, 108 insertions, 0 deletions
diff --git a/zopfli.h b/zopfli.h
new file mode 100644
index 0000000..f520b1e
--- /dev/null
+++ b/zopfli.h
@@ -0,0 +1,71 @@
+/*
+Copyright 2013 Google Inc. All Rights Reserved.
+Author: lode@google.com (Lode Vandevenne)
+*/
+
+#ifndef UTIL_COMPRESSION_ZOPFLI_INTERNAL_ZOPFLI_H_
+#define UTIL_COMPRESSION_ZOPFLI_INTERNAL_ZOPFLI_H_
+
+#include <stdlib.h> /* for size_t */
+
+/*
+Options used throughout the program.
+*/
+typedef struct ZopfliOptions {
+ /* Whether to print output */
+ int verbose;
+
+ /*
+ Maximum amount of times to rerun forward and backward pass to optimize LZ77
+ compression cost. Good values: 10, 15 for small files, 5 for files over
+ several MB in size or it will be too slow.
+ */
+ int numiterations;
+
+ /*
+ If true, splits the data in multiple deflate blocks with optimal choice
+ for the block boundaries. Block splitting gives better compression. Default:
+ true (1).
+ */
+ int blocksplitting;
+
+ /*
+ If true, chooses the optimal block split points only after doing the iterative
+ LZ77 compression. If false, chooses the block split points first, then does
+ iterative LZ77 on each individual block. Depending on the file, either first
+ or last gives the best compression. Default: false (0).
+ */
+ int blocksplittinglast;
+
+ /*
+ Maximum amount of blocks to split into (0 for unlimited, but this can give
+ extreme results that hurt compression on some files). Default value: 15.
+ */
+ int blocksplittingmax;
+} ZopfliOptions;
+
+/* Initializes options with default values. */
+void ZopfliInitOptions(ZopfliOptions* options);
+
+/* Output format */
+typedef enum {
+ ZOPFLI_FORMAT_GZIP,
+ ZOPFLI_FORMAT_ZLIB,
+ ZOPFLI_FORMAT_DEFLATE
+} ZopfliFormat;
+
+/*
+Compresses according to the given output format and appends the result to the
+output.
+
+options: global program options
+output_type: the output format to use
+out: pointer to the dynamic output array to which the result is appended. Must
+ be freed after use
+outsize: pointer to the dynamic output array size
+*/
+void ZopfliCompress(const ZopfliOptions* options, ZopfliFormat output_type,
+ const unsigned char* in, size_t insize,
+ unsigned char** out, size_t* outsize);
+
+#endif /* UTIL_COMPRESSION_ZOPFLI_INTERNAL_ZOPFLI_H_ */
diff --git a/zopfli_lib.c b/zopfli_lib.c
new file mode 100644
index 0000000..99d3f7d
--- /dev/null
+++ b/zopfli_lib.c
@@ -0,0 +1,37 @@
+/*
+Copyright 2013 Google Inc. All Rights Reserved.
+Author: lode@google.com (Lode Vandevenne)
+*/
+
+#include "zopfli.h"
+
+#include "deflate.h"
+#include "gzip_container.h"
+#include "zlib_container.h"
+
+#include <assert.h>
+
+void ZopfliInitOptions(ZopfliOptions* options) {
+ options->verbose = 0;
+ options->numiterations = 15;
+ options->blocksplitting = 1;
+ options->blocksplittinglast = 0;
+ options->blocksplittingmax = 15;
+}
+
+void ZopfliCompress(const ZopfliOptions* options, ZopfliFormat output_type,
+ const unsigned char* in, size_t insize,
+ unsigned char** out, size_t* outsize)
+{
+ if (output_type == ZOPFLI_FORMAT_GZIP) {
+ ZopfliGzipCompress(options, in, insize, out, outsize);
+ } else if (output_type == ZOPFLI_FORMAT_ZLIB) {
+ ZopfliZlibCompress(options, in, insize, out, outsize);
+ } else if (output_type == ZOPFLI_FORMAT_DEFLATE) {
+ unsigned char bp = 0;
+ ZopfliDeflate(options, 2 /* Dynamic block */, 1,
+ in, insize, &bp, out, outsize);
+ } else {
+ assert(0);
+ }
+}