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_DEFLATE_H_
21 #define ZOPFLI_DEFLATE_H_
22 
23 /*
24 Functions to compress according to the DEFLATE specification, using the
25 "squeeze" LZ77 compression backend.
26 */
27 
28 #include "zopfli.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /*
35 Compresses according to the deflate specification and append the compressed
36 result to the output.
37 This function will usually output multiple deflate blocks. If final is 1, then
38 the final bit will be set on the last block.
39 
40 options: global program options
41 btype: the deflate block type. Use 2 for best compression.
42   -0: non compressed blocks (00)
43   -1: blocks with fixed tree (01)
44   -2: blocks with dynamic tree (10)
45 final: whether this is the last section of the input, sets the final bit to the
46   last deflate block.
47 in: the input bytes
48 insize: number of input bytes
49 bp: bit pointer for the output array. This must initially be 0, and for
50   consecutive calls must be reused (it can have values from 0-7). This is
51   because deflate appends blocks as bit-based data, rather than on byte
52   boundaries.
53 out: pointer to the dynamic output array to which the result is appended. Must
54   be freed after use.
55 outsize: pointer to the dynamic output array size.
56 */
57 void ZopfliDeflate(const ZopfliOptions* options, int btype, int final,
58                    const unsigned char* in, size_t insize,
59                    unsigned char* bp, unsigned char** out, size_t* outsize);
60 
61 /*
62 Like ZopfliDeflate, but allows to specify start and end byte with instart and
63 inend. Only that part is compressed, but earlier bytes are still used for the
64 back window.
65 */
66 void ZopfliDeflatePart(const ZopfliOptions* options, int btype, int final,
67                        const unsigned char* in, size_t instart, size_t inend,
68                        unsigned char* bp, unsigned char** out,
69                        size_t* outsize);
70 
71 /*
72 Calculates block size in bits.
73 litlens: lz77 lit/lengths
74 dists: ll77 distances
75 lstart: start of block
76 lend: end of block (not inclusive)
77 */
78 double ZopfliCalculateBlockSize(const unsigned short* litlens,
79                                 const unsigned short* dists,
80                                 size_t lstart, size_t lend, int btype);
81 
82 #ifdef __cplusplus
83 }  // extern "C"
84 #endif
85 
86 #endif  /* ZOPFLI_DEFLATE_H_ */
87