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 (at) gmail.com (Lode Vandevenne) 17 Author: jyrki.alakuijala (at) 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 If true, chooses the optimal block split points only after doing the iterative 56 LZ77 compression. If false, chooses the block split points first, then does 57 iterative LZ77 on each individual block. Depending on the file, either first 58 or last gives the best compression. Default: false (0). 59 */ 60 int blocksplittinglast; 61 62 /* 63 Maximum amount of blocks to split into (0 for unlimited, but this can give 64 extreme results that hurt compression on some files). Default value: 15. 65 */ 66 int blocksplittingmax; 67 } ZopfliOptions; 68 69 /* Initializes options with default values. */ 70 void ZopfliInitOptions(ZopfliOptions* options); 71 72 /* Output format */ 73 typedef enum { 74 ZOPFLI_FORMAT_GZIP, 75 ZOPFLI_FORMAT_ZLIB, 76 ZOPFLI_FORMAT_DEFLATE 77 } ZopfliFormat; 78 79 /* 80 Compresses according to the given output format and appends the result to the 81 output. 82 83 options: global program options 84 output_type: the output format to use 85 out: pointer to the dynamic output array to which the result is appended. Must 86 be freed after use 87 outsize: pointer to the dynamic output array size 88 */ 89 void ZopfliCompress(const ZopfliOptions* options, ZopfliFormat output_type, 90 const unsigned char* in, size_t insize, 91 unsigned char** out, size_t* outsize); 92 93 #ifdef __cplusplus 94 } // extern "C" 95 #endif 96 97 #endif /* ZOPFLI_ZOPFLI_H_ */ 98