xref: /netbsd/external/zlib/pigz/dist/zopfli/deflate.h (revision cf2fd8ad)
1*cf2fd8adStls /*
2*cf2fd8adStls Copyright 2011 Google Inc. All Rights Reserved.
3*cf2fd8adStls 
4*cf2fd8adStls Licensed under the Apache License, Version 2.0 (the "License");
5*cf2fd8adStls you may not use this file except in compliance with the License.
6*cf2fd8adStls You may obtain a copy of the License at
7*cf2fd8adStls 
8*cf2fd8adStls     http://www.apache.org/licenses/LICENSE-2.0
9*cf2fd8adStls 
10*cf2fd8adStls Unless required by applicable law or agreed to in writing, software
11*cf2fd8adStls distributed under the License is distributed on an "AS IS" BASIS,
12*cf2fd8adStls WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*cf2fd8adStls See the License for the specific language governing permissions and
14*cf2fd8adStls limitations under the License.
15*cf2fd8adStls 
16*cf2fd8adStls Author: lode.vandevenne@gmail.com (Lode Vandevenne)
17*cf2fd8adStls Author: jyrki.alakuijala@gmail.com (Jyrki Alakuijala)
18*cf2fd8adStls */
19*cf2fd8adStls 
20*cf2fd8adStls #ifndef ZOPFLI_DEFLATE_H_
21*cf2fd8adStls #define ZOPFLI_DEFLATE_H_
22*cf2fd8adStls 
23*cf2fd8adStls /*
24*cf2fd8adStls Functions to compress according to the DEFLATE specification, using the
25*cf2fd8adStls "squeeze" LZ77 compression backend.
26*cf2fd8adStls */
27*cf2fd8adStls 
28*cf2fd8adStls #include "zopfli.h"
29*cf2fd8adStls 
30*cf2fd8adStls /*
31*cf2fd8adStls Compresses according to the deflate specification and append the compressed
32*cf2fd8adStls result to the output.
33*cf2fd8adStls This function will usually output multiple deflate blocks. If final is 1, then
34*cf2fd8adStls the final bit will be set on the last block.
35*cf2fd8adStls 
36*cf2fd8adStls options: global program options
37*cf2fd8adStls btype: the deflate block type. Use 2 for best compression.
38*cf2fd8adStls   -0: non compressed blocks (00)
39*cf2fd8adStls   -1: blocks with fixed tree (01)
40*cf2fd8adStls   -2: blocks with dynamic tree (10)
41*cf2fd8adStls final: whether this is the last section of the input, sets the final bit to the
42*cf2fd8adStls   last deflate block.
43*cf2fd8adStls in: the input bytes
44*cf2fd8adStls insize: number of input bytes
45*cf2fd8adStls bp: bit pointer for the output array. This must initially be 0, and for
46*cf2fd8adStls   consecutive calls must be reused (it can have values from 0-7). This is
47*cf2fd8adStls   because deflate appends blocks as bit-based data, rather than on byte
48*cf2fd8adStls   boundaries.
49*cf2fd8adStls out: pointer to the dynamic output array to which the result is appended. Must
50*cf2fd8adStls   be freed after use.
51*cf2fd8adStls outsize: pointer to the dynamic output array size.
52*cf2fd8adStls */
53*cf2fd8adStls void ZopfliDeflate(const ZopfliOptions* options, int btype, int final,
54*cf2fd8adStls                    const unsigned char* in, size_t insize,
55*cf2fd8adStls                    unsigned char* bp, unsigned char** out, size_t* outsize);
56*cf2fd8adStls 
57*cf2fd8adStls /*
58*cf2fd8adStls Like ZopfliDeflate, but allows to specify start and end byte with instart and
59*cf2fd8adStls inend. Only that part is compressed, but earlier bytes are still used for the
60*cf2fd8adStls back window.
61*cf2fd8adStls */
62*cf2fd8adStls void ZopfliDeflatePart(const ZopfliOptions* options, int btype, int final,
63*cf2fd8adStls                        const unsigned char* in, size_t instart, size_t inend,
64*cf2fd8adStls                        unsigned char* bp, unsigned char** out,
65*cf2fd8adStls                        size_t* outsize);
66*cf2fd8adStls 
67*cf2fd8adStls /*
68*cf2fd8adStls Calculates block size in bits.
69*cf2fd8adStls litlens: lz77 lit/lengths
70*cf2fd8adStls dists: ll77 distances
71*cf2fd8adStls lstart: start of block
72*cf2fd8adStls lend: end of block (not inclusive)
73*cf2fd8adStls */
74*cf2fd8adStls double ZopfliCalculateBlockSize(const unsigned short* litlens,
75*cf2fd8adStls                                 const unsigned short* dists,
76*cf2fd8adStls                                 size_t lstart, size_t lend, int btype);
77*cf2fd8adStls #endif  /* ZOPFLI_DEFLATE_H_ */
78