1 /*
2 Copyright 2011 Google Inc. All Rights Reserved.
3 
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7 
8     http://www.apache.org/licenses/LICENSE-2.0
9 
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 
16 Author: lode.vandevenne@gmail.com (Lode Vandevenne)
17 Author: jyrki.alakuijala@gmail.com (Jyrki Alakuijala)
18 */
19 
20 #ifndef ZOPFLI_ZOPFLI_H_
21 #define ZOPFLI_ZOPFLI_H_
22 
23 #include <stddef.h>
24 #include <stdlib.h> /* for size_t */
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 /*
31 Options used throughout the program.
32 */
33 typedef struct ZopfliOptions {
34   /* Whether to print output */
35   int verbose;
36 
37   /* Whether to print more detailed output */
38   int verbose_more;
39 
40   /*
41   Maximum amount of times to rerun forward and backward pass to optimize LZ77
42   compression cost. Good values: 10, 15 for small files, 5 for files over
43   several MB in size or it will be too slow.
44   */
45   int numiterations;
46 
47   /*
48   If true, splits the data in multiple deflate blocks with optimal choice
49   for the block boundaries. Block splitting gives better compression. Default:
50   true (1).
51   */
52   int blocksplitting;
53 
54   /*
55   No longer used, left for compatibility.
56   */
57   int blocksplittinglast;
58 
59   /*
60   Maximum amount of blocks to split into (0 for unlimited, but this can give
61   extreme results that hurt compression on some files). Default value: 15.
62   */
63   int blocksplittingmax;
64 } ZopfliOptions;
65 
66 /* Initializes options with default values. */
67 void ZopfliInitOptions(ZopfliOptions* options);
68 
69 /* Output format */
70 typedef enum {
71   ZOPFLI_FORMAT_GZIP,
72   ZOPFLI_FORMAT_ZLIB,
73   ZOPFLI_FORMAT_DEFLATE
74 } ZopfliFormat;
75 
76 /*
77 Compresses according to the given output format and appends the result to the
78 output.
79 
80 options: global program options
81 output_type: the output format to use
82 out: pointer to the dynamic output array to which the result is appended. Must
83   be freed after use
84 outsize: pointer to the dynamic output array size
85 */
86 void ZopfliCompress(const ZopfliOptions* options, ZopfliFormat output_type,
87                     const unsigned char* in, size_t insize,
88                     unsigned char** out, size_t* outsize);
89 
90 #ifdef __cplusplus
91 }  // extern "C"
92 #endif
93 
94 #endif  /* ZOPFLI_ZOPFLI_H_ */
95