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