blob: 0cab81668158d240fe063060617cec9e3899c607 [file] [log] [blame]
Eugene Kliuchnikov35e69fc2018-02-26 09:04:36 -05001.TH "encode.h" 3 "Thu Feb 22 2018" "Brotli" \" -*- nroff -*-
Eugene Kliuchnikovc931e572017-02-28 16:59:52 +01002.ad l
3.nh
4.SH NAME
5encode.h \- API for Brotli compression\&.
6
7.SH SYNOPSIS
8.br
9.PP
10.SS "Macros"
11
12.in +1c
13.ti -1c
14.RI "#define \fBBROTLI_DEFAULT_MODE\fP \fBBROTLI_MODE_GENERIC\fP"
15.br
16.RI "\fIDefault value for \fBBROTLI_PARAM_MODE\fP parameter\&. \fP"
17.ti -1c
18.RI "#define \fBBROTLI_DEFAULT_QUALITY\fP 11"
19.br
20.RI "\fIDefault value for \fBBROTLI_PARAM_QUALITY\fP parameter\&. \fP"
21.ti -1c
22.RI "#define \fBBROTLI_DEFAULT_WINDOW\fP 22"
23.br
24.RI "\fIDefault value for \fBBROTLI_PARAM_LGWIN\fP parameter\&. \fP"
25.ti -1c
Eugene Kliuchnikov35e69fc2018-02-26 09:04:36 -050026.RI "#define \fBBROTLI_LARGE_MAX_WINDOW_BITS\fP 30"
27.br
28.RI "\fIMaximal value for \fBBROTLI_PARAM_LGWIN\fP parameter in 'Large Window Brotli' (32-bit)\&. \fP"
29.ti -1c
Eugene Kliuchnikovc931e572017-02-28 16:59:52 +010030.RI "#define \fBBROTLI_MAX_INPUT_BLOCK_BITS\fP 24"
31.br
32.RI "\fIMaximal value for \fBBROTLI_PARAM_LGBLOCK\fP parameter\&. \fP"
33.ti -1c
34.RI "#define \fBBROTLI_MAX_QUALITY\fP 11"
35.br
36.RI "\fIMaximal value for \fBBROTLI_PARAM_QUALITY\fP parameter\&. \fP"
37.ti -1c
38.RI "#define \fBBROTLI_MAX_WINDOW_BITS\fP 24"
39.br
40.RI "\fIMaximal value for \fBBROTLI_PARAM_LGWIN\fP parameter\&. \fP"
41.ti -1c
42.RI "#define \fBBROTLI_MIN_INPUT_BLOCK_BITS\fP 16"
43.br
44.RI "\fIMinimal value for \fBBROTLI_PARAM_LGBLOCK\fP parameter\&. \fP"
45.ti -1c
46.RI "#define \fBBROTLI_MIN_QUALITY\fP 0"
47.br
48.RI "\fIMinimal value for \fBBROTLI_PARAM_QUALITY\fP parameter\&. \fP"
49.ti -1c
50.RI "#define \fBBROTLI_MIN_WINDOW_BITS\fP 10"
51.br
52.RI "\fIMinimal value for \fBBROTLI_PARAM_LGWIN\fP parameter\&. \fP"
53.in -1c
54.SS "Typedefs"
55
56.in +1c
57.ti -1c
58.RI "typedef enum \fBBrotliEncoderMode\fP \fBBrotliEncoderMode\fP"
59.br
60.RI "\fIOptions for \fBBROTLI_PARAM_MODE\fP parameter\&. \fP"
61.ti -1c
62.RI "typedef enum \fBBrotliEncoderOperation\fP \fBBrotliEncoderOperation\fP"
63.br
64.RI "\fIOperations that can be performed by streaming encoder\&. \fP"
65.ti -1c
66.RI "typedef enum \fBBrotliEncoderParameter\fP \fBBrotliEncoderParameter\fP"
67.br
68.RI "\fIOptions to be used with \fBBrotliEncoderSetParameter\fP\&. \fP"
69.ti -1c
70.RI "typedef struct BrotliEncoderStateStruct \fBBrotliEncoderState\fP"
71.br
72.RI "\fIOpaque structure that holds encoder state\&. \fP"
73.in -1c
74.SS "Enumerations"
75.SS "Functions"
76
77.in +1c
78.ti -1c
79.RI "\fBBROTLI_BOOL\fP \fBBrotliEncoderCompress\fP (int quality, int lgwin, \fBBrotliEncoderMode\fP mode, size_t input_size, const uint8_t input_buffer[input_size], size_t *encoded_size, uint8_t encoded_buffer[*encoded_size])"
80.br
81.RI "\fIPerforms one-shot memory-to-memory compression\&. \fP"
82.ti -1c
83.RI "\fBBROTLI_BOOL\fP \fBBrotliEncoderCompressStream\fP (\fBBrotliEncoderState\fP *state, \fBBrotliEncoderOperation\fP op, size_t *available_in, const uint8_t **next_in, size_t *available_out, uint8_t **next_out, size_t *total_out)"
84.br
85.RI "\fICompresses input stream to output stream\&. \fP"
86.ti -1c
87.RI "\fBBrotliEncoderState\fP * \fBBrotliEncoderCreateInstance\fP (\fBbrotli_alloc_func\fP alloc_func, \fBbrotli_free_func\fP free_func, void *opaque)"
88.br
89.RI "\fICreates an instance of \fBBrotliEncoderState\fP and initializes it\&. \fP"
90.ti -1c
91.RI "void \fBBrotliEncoderDestroyInstance\fP (\fBBrotliEncoderState\fP *state)"
92.br
93.RI "\fIDeinitializes and frees \fBBrotliEncoderState\fP instance\&. \fP"
94.ti -1c
95.RI "\fBBROTLI_BOOL\fP \fBBrotliEncoderHasMoreOutput\fP (\fBBrotliEncoderState\fP *state)"
96.br
97.RI "\fIChecks if encoder has more output\&. \fP"
98.ti -1c
99.RI "\fBBROTLI_BOOL\fP \fBBrotliEncoderIsFinished\fP (\fBBrotliEncoderState\fP *state)"
100.br
101.RI "\fIChecks if encoder instance reached the final state\&. \fP"
102.ti -1c
103.RI "size_t \fBBrotliEncoderMaxCompressedSize\fP (size_t input_size)"
104.br
105.RI "\fICalculates the output size bound for the given \fCinput_size\fP\&. \fP"
106.ti -1c
Eugene Kliuchnikovc931e572017-02-28 16:59:52 +0100107.RI "\fBBROTLI_BOOL\fP \fBBrotliEncoderSetParameter\fP (\fBBrotliEncoderState\fP *state, \fBBrotliEncoderParameter\fP param, uint32_t value)"
108.br
109.RI "\fISets the specified parameter to the given encoder instance\&. \fP"
110.ti -1c
111.RI "const uint8_t * \fBBrotliEncoderTakeOutput\fP (\fBBrotliEncoderState\fP *state, size_t *size)"
112.br
113.RI "\fIAcquires pointer to internal output buffer\&. \fP"
114.ti -1c
115.RI "uint32_t \fBBrotliEncoderVersion\fP (void)"
116.br
117.RI "\fIGets an encoder library version\&. \fP"
118.in -1c
119.SH "Detailed Description"
120.PP
121API for Brotli compression\&.
122
123
124.SH "Macro Definition Documentation"
125.PP
126.SS "#define BROTLI_DEFAULT_MODE \fBBROTLI_MODE_GENERIC\fP"
127
128.PP
129Default value for \fBBROTLI_PARAM_MODE\fP parameter\&.
130.SS "#define BROTLI_DEFAULT_QUALITY 11"
131
132.PP
133Default value for \fBBROTLI_PARAM_QUALITY\fP parameter\&.
134.SS "#define BROTLI_DEFAULT_WINDOW 22"
135
136.PP
137Default value for \fBBROTLI_PARAM_LGWIN\fP parameter\&.
138.SS "#define BROTLI_MAX_INPUT_BLOCK_BITS 24"
139
140.PP
141Maximal value for \fBBROTLI_PARAM_LGBLOCK\fP parameter\&.
142.SS "#define BROTLI_MAX_QUALITY 11"
143
144.PP
145Maximal value for \fBBROTLI_PARAM_QUALITY\fP parameter\&.
146.SS "#define BROTLI_MAX_WINDOW_BITS 24"
147
148.PP
149Maximal value for \fBBROTLI_PARAM_LGWIN\fP parameter\&.
150.PP
151\fBNote:\fP
152.RS 4
153equal to \fCBROTLI_MAX_DISTANCE_BITS\fP constant\&.
154.RE
155.PP
156
157.SS "#define BROTLI_MIN_INPUT_BLOCK_BITS 16"
158
159.PP
160Minimal value for \fBBROTLI_PARAM_LGBLOCK\fP parameter\&.
161.SS "#define BROTLI_MIN_QUALITY 0"
162
163.PP
164Minimal value for \fBBROTLI_PARAM_QUALITY\fP parameter\&.
165.SS "#define BROTLI_MIN_WINDOW_BITS 10"
166
167.PP
168Minimal value for \fBBROTLI_PARAM_LGWIN\fP parameter\&.
169.SH "Typedef Documentation"
170.PP
171.SS "typedef enum \fBBrotliEncoderMode\fP \fBBrotliEncoderMode\fP"
172
173.PP
174Options for \fBBROTLI_PARAM_MODE\fP parameter\&.
175.SS "typedef enum \fBBrotliEncoderOperation\fP \fBBrotliEncoderOperation\fP"
176
177.PP
178Operations that can be performed by streaming encoder\&.
179.SS "typedef enum \fBBrotliEncoderParameter\fP \fBBrotliEncoderParameter\fP"
180
181.PP
182Options to be used with \fBBrotliEncoderSetParameter\fP\&.
183.SS "typedef struct BrotliEncoderStateStruct \fBBrotliEncoderState\fP"
184
185.PP
186Opaque structure that holds encoder state\&. Allocated and initialized with \fBBrotliEncoderCreateInstance\fP\&. Cleaned up and deallocated with \fBBrotliEncoderDestroyInstance\fP\&.
187.SH "Enumeration Type Documentation"
188.PP
189.SS "enum \fBBrotliEncoderMode\fP"
190
191.PP
192Options for \fBBROTLI_PARAM_MODE\fP parameter\&.
193.PP
194\fBEnumerator\fP
195.in +1c
196.TP
197\fB\fIBROTLI_MODE_GENERIC \fP\fP
198Default compression mode\&. In this mode compressor does not know anything in advance about the properties of the input\&.
199.TP
200\fB\fIBROTLI_MODE_TEXT \fP\fP
201Compression mode for UTF-8 formatted text input\&.
202.TP
203\fB\fIBROTLI_MODE_FONT \fP\fP
204Compression mode used in WOFF 2\&.0\&.
205.SS "enum \fBBrotliEncoderOperation\fP"
206
207.PP
208Operations that can be performed by streaming encoder\&.
209.PP
210\fBEnumerator\fP
211.in +1c
212.TP
213\fB\fIBROTLI_OPERATION_PROCESS \fP\fP
214Process input\&. Encoder may postpone producing output, until it has processed enough input\&.
215.TP
216\fB\fIBROTLI_OPERATION_FLUSH \fP\fP
Eugene Kliuchnikovc6056352017-09-20 15:02:01 +0200217Produce output for all processed input\&. Actual flush is performed when input stream is depleted and there is enough space in output stream\&. This means that client should repeat \fBBROTLI_OPERATION_FLUSH\fP operation until \fCavailable_in\fP becomes \fC0\fP, and \fBBrotliEncoderHasMoreOutput\fP returns \fBBROTLI_FALSE\fP\&. If output is acquired via \fBBrotliEncoderTakeOutput\fP, then operation should be repeated after output buffer is drained\&.
Eugene Kliuchnikovc931e572017-02-28 16:59:52 +0100218.PP
219\fBWarning:\fP
220.RS 4
221Until flush is complete, client \fBSHOULD\fP \fBNOT\fP swap, reduce or extend input stream\&.
222.RE
223.PP
224When flush is complete, output data will be sufficient for decoder to reproduce all the given input\&.
225.TP
226\fB\fIBROTLI_OPERATION_FINISH \fP\fP
Eugene Kliuchnikovc6056352017-09-20 15:02:01 +0200227Finalize the stream\&. Actual finalization is performed when input stream is depleted and there is enough space in output stream\&. This means that client should repeat \fBBROTLI_OPERATION_FINISH\fP operation until \fCavailable_in\fP becomes \fC0\fP, and \fBBrotliEncoderHasMoreOutput\fP returns \fBBROTLI_FALSE\fP\&. If output is acquired via \fBBrotliEncoderTakeOutput\fP, then operation should be repeated after output buffer is drained\&.
Eugene Kliuchnikovc931e572017-02-28 16:59:52 +0100228.PP
229\fBWarning:\fP
230.RS 4
231Until finalization is complete, client \fBSHOULD\fP \fBNOT\fP swap, reduce or extend input stream\&.
232.RE
233.PP
234Helper function \fBBrotliEncoderIsFinished\fP checks if stream is finalized and output fully dumped\&.
235.PP
236Adding more input data to finalized stream is impossible\&.
237.TP
238\fB\fIBROTLI_OPERATION_EMIT_METADATA \fP\fP
239Emit metadata block to stream\&. Metadata is opaque to Brotli: neither encoder, nor decoder processes this data or relies on it\&. It may be used to pass some extra information from encoder client to decoder client without interfering with main data stream\&.
240.PP
241\fBNote:\fP
242.RS 4
243Encoder may emit empty metadata blocks internally, to pad encoded stream to byte boundary\&.
244.RE
245.PP
246\fBWarning:\fP
247.RS 4
248Until emitting metadata is complete client \fBSHOULD\fP \fBNOT\fP swap, reduce or extend input stream\&.
249.PP
250The whole content of input buffer is considered to be the content of metadata block\&. Do \fBNOT\fP \fIappend\fP metadata to input stream, before it is depleted with other operations\&.
251.RE
252.PP
253Stream is soft-flushed before metadata block is emitted\&. Metadata block \fBMUST\fP be no longer than than 16MiB\&.
254.SS "enum \fBBrotliEncoderParameter\fP"
255
256.PP
257Options to be used with \fBBrotliEncoderSetParameter\fP\&.
258.PP
259\fBEnumerator\fP
260.in +1c
261.TP
262\fB\fIBROTLI_PARAM_MODE \fP\fP
263Tune encoder for specific input\&. \fBBrotliEncoderMode\fP enumerates all available values\&.
264.TP
265\fB\fIBROTLI_PARAM_QUALITY \fP\fP
266The main compression speed-density lever\&. The higher the quality, the slower the compression\&. Range is from \fBBROTLI_MIN_QUALITY\fP to \fBBROTLI_MAX_QUALITY\fP\&.
267.TP
268\fB\fIBROTLI_PARAM_LGWIN \fP\fP
269Recommended sliding LZ77 window size\&. Encoder may reduce this value, e\&.g\&. if input is much smaller than window size\&.
270.PP
271Window size is \fC(1 << value) - 16\fP\&.
272.PP
273Range is from \fBBROTLI_MIN_WINDOW_BITS\fP to \fBBROTLI_MAX_WINDOW_BITS\fP\&.
274.TP
275\fB\fIBROTLI_PARAM_LGBLOCK \fP\fP
276Recommended input block size\&. Encoder may reduce this value, e\&.g\&. if input is much smaller than input block size\&.
277.PP
278Range is from \fBBROTLI_MIN_INPUT_BLOCK_BITS\fP to \fBBROTLI_MAX_INPUT_BLOCK_BITS\fP\&.
279.PP
280\fBNote:\fP
281.RS 4
282Bigger input block size allows better compression, but consumes more memory\&.
283.br
284 The rough formula of memory used for temporary input storage is \fC3 << lgBlock\fP\&.
285.RE
286.PP
287
288.TP
289\fB\fIBROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING \fP\fP
290Flag that affects usage of 'literal context modeling' format feature\&. This flag is a 'decoding-speed vs compression ratio' trade-off\&.
291.TP
292\fB\fIBROTLI_PARAM_SIZE_HINT \fP\fP
293Estimated total input size for all \fBBrotliEncoderCompressStream\fP calls\&. The default value is 0, which means that the total input size is unknown\&.
Eugene Kliuchnikov35e69fc2018-02-26 09:04:36 -0500294.TP
295\fB\fIBROTLI_PARAM_LARGE_WINDOW \fP\fP
296Flag that determines if 'Large Window Brotli' is used\&.
Eugene Kliuchnikov631fe192018-03-20 17:37:41 +0600297.TP
298\fB\fIBROTLI_PARAM_NPOSTFIX \fP\fP
299Recommended number of postfix bits (NPOSTFIX)\&. Encoder may change this value\&.
300.PP
Eugene Kliuchnikov4b2b2d42019-04-12 13:57:42 +0200301Range is from 0 to \fBBROTLI_MAX_NPOSTFIX\fP\&.
Eugene Kliuchnikov631fe192018-03-20 17:37:41 +0600302.TP
303\fB\fIBROTLI_PARAM_NDIRECT \fP\fP
304Recommended number of direct distance codes (NDIRECT)\&. Encoder may change this value\&.
305.PP
306Range is from 0 to (15 << NPOSTFIX) in steps of (1 << NPOSTFIX)\&.
Eugene Kliuchnikov4b2b2d42019-04-12 13:57:42 +0200307.TP
308\fB\fIBROTLI_PARAM_STREAM_OFFSET \fP\fP
309Number of bytes of input stream already processed by a different instance\&.
310.PP
311\fBNote:\fP
312.RS 4
313It is important to configure all the encoder instances with same parameters (except this one) in order to allow all the encoded parts obey the same restrictions implied by header\&.
314.RE
315.PP
316If offset is not 0, then stream header is omitted\&. In any case output start is byte aligned, so for proper streams stitching 'predecessor' stream must be flushed\&.
317.PP
318Range is not artificially limited, but all the values greater or equal to maximal window size have the same effect\&. Values greater than 2**30 are not allowed\&.
Eugene Kliuchnikovc931e572017-02-28 16:59:52 +0100319.SH "Function Documentation"
320.PP
321.SS "\fBBROTLI_BOOL\fP BrotliEncoderCompress (int quality, int lgwin, \fBBrotliEncoderMode\fP mode, size_t input_size, const uint8_t input_buffer[input_size], size_t * encoded_size, uint8_t encoded_buffer[*encoded_size])"
322
323.PP
324Performs one-shot memory-to-memory compression\&. Compresses the data in \fCinput_buffer\fP into \fCencoded_buffer\fP, and sets \fC*encoded_size\fP to the compressed length\&.
325.PP
326\fBNote:\fP
327.RS 4
328If \fBBrotliEncoderMaxCompressedSize\fP(\fCinput_size\fP) returns non-zero value, then output is guaranteed to be no longer than that\&.
Eugene Kliuchnikov4b2b2d42019-04-12 13:57:42 +0200329.PP
330If \fClgwin\fP is greater than \fBBROTLI_MAX_WINDOW_BITS\fP then resulting stream might be incompatible with RFC 7932; to decode such streams, decoder should be configured with \fBBROTLI_DECODER_PARAM_LARGE_WINDOW\fP = \fC1\fP
Eugene Kliuchnikovc931e572017-02-28 16:59:52 +0100331.RE
332.PP
333\fBParameters:\fP
334.RS 4
335\fIquality\fP quality parameter value, e\&.g\&. \fBBROTLI_DEFAULT_QUALITY\fP
336.br
337\fIlgwin\fP lgwin parameter value, e\&.g\&. \fBBROTLI_DEFAULT_WINDOW\fP
338.br
339\fImode\fP mode parameter value, e\&.g\&. \fBBROTLI_DEFAULT_MODE\fP
340.br
341\fIinput_size\fP size of \fCinput_buffer\fP
342.br
343\fIinput_buffer\fP input data buffer with at least \fCinput_size\fP addressable bytes
344.br
345\fIencoded_size\fP \fBin:\fP size of \fCencoded_buffer\fP;
346.br
347 \fBout:\fP length of compressed data written to \fCencoded_buffer\fP, or \fC0\fP if compression fails
348.br
349\fIencoded_buffer\fP compressed data destination buffer
350.RE
351.PP
352\fBReturns:\fP
353.RS 4
354\fBBROTLI_FALSE\fP in case of compression error
355.PP
356\fBBROTLI_FALSE\fP if output buffer is too small
357.PP
358\fBBROTLI_TRUE\fP otherwise
359.RE
360.PP
361
362.SS "\fBBROTLI_BOOL\fP BrotliEncoderCompressStream (\fBBrotliEncoderState\fP * state, \fBBrotliEncoderOperation\fP op, size_t * available_in, const uint8_t ** next_in, size_t * available_out, uint8_t ** next_out, size_t * total_out)"
363
364.PP
365Compresses input stream to output stream\&. The values \fC*available_in\fP and \fC*available_out\fP must specify the number of bytes addressable at \fC*next_in\fP and \fC*next_out\fP respectively\&. When \fC*available_out\fP is \fC0\fP, \fCnext_out\fP is allowed to be \fCNULL\fP\&.
366.PP
367After each call, \fC*available_in\fP will be decremented by the amount of input bytes consumed, and the \fC*next_in\fP pointer will be incremented by that amount\&. Similarly, \fC*available_out\fP will be decremented by the amount of output bytes written, and the \fC*next_out\fP pointer will be incremented by that amount\&.
368.PP
Eugene Kliuchnikov3e58ea52017-10-13 14:50:51 +0200369\fCtotal_out\fP, if it is not a null-pointer, will be set to the number of bytes compressed since the last \fCstate\fP initialization\&.
Eugene Kliuchnikovc931e572017-02-28 16:59:52 +0100370.PP
371Internally workflow consists of 3 tasks:
372.IP "1." 4
373(optionally) copy input data to internal buffer
374.IP "2." 4
375actually compress data and (optionally) store it to internal buffer
376.IP "3." 4
377(optionally) copy compressed bytes from internal buffer to output stream
378.PP
379.PP
380Whenever all 3 tasks can't move forward anymore, or error occurs, this method returns the control flow to caller\&.
381.PP
382\fCop\fP is used to perform flush, finish the stream, or inject metadata block\&. See \fBBrotliEncoderOperation\fP for more information\&.
383.PP
384Flushing the stream means forcing encoding of all input passed to encoder and completing the current output block, so it could be fully decoded by stream decoder\&. To perform flush set \fCop\fP to \fBBROTLI_OPERATION_FLUSH\fP\&. Under some circumstances (e\&.g\&. lack of output stream capacity) this operation would require several calls to \fBBrotliEncoderCompressStream\fP\&. The method must be called again until both input stream is depleted and encoder has no more output (see \fBBrotliEncoderHasMoreOutput\fP) after the method is called\&.
385.PP
386Finishing the stream means encoding of all input passed to encoder and adding specific 'final' marks, so stream decoder could determine that stream is complete\&. To perform finish set \fCop\fP to \fBBROTLI_OPERATION_FINISH\fP\&. Under some circumstances (e\&.g\&. lack of output stream capacity) this operation would require several calls to \fBBrotliEncoderCompressStream\fP\&. The method must be called again until both input stream is depleted and encoder has no more output (see \fBBrotliEncoderHasMoreOutput\fP) after the method is called\&.
387.PP
388\fBWarning:\fP
389.RS 4
390When flushing and finishing, \fCop\fP should not change until operation is complete; input stream should not be swapped, reduced or extended as well\&.
391.RE
392.PP
393\fBParameters:\fP
394.RS 4
395\fIstate\fP encoder instance
396.br
397\fIop\fP requested operation
398.br
399\fIavailable_in\fP \fBin:\fP amount of available input;
400.br
401 \fBout:\fP amount of unused input
402.br
403\fInext_in\fP pointer to the next input byte
404.br
405\fIavailable_out\fP \fBin:\fP length of output buffer;
406.br
407 \fBout:\fP remaining size of output buffer
408.br
409\fInext_out\fP compressed output buffer cursor; can be \fCNULL\fP if \fCavailable_out\fP is \fC0\fP
410.br
411\fItotal_out\fP number of bytes produced so far; can be \fCNULL\fP
412.RE
413.PP
414\fBReturns:\fP
415.RS 4
416\fBBROTLI_FALSE\fP if there was an error
417.PP
418\fBBROTLI_TRUE\fP otherwise
419.RE
420.PP
421
422.SS "\fBBrotliEncoderState\fP* BrotliEncoderCreateInstance (\fBbrotli_alloc_func\fP alloc_func, \fBbrotli_free_func\fP free_func, void * opaque)"
423
424.PP
Eugene Kliuchnikovda254cf2017-12-12 14:33:12 +0100425Creates an instance of \fBBrotliEncoderState\fP and initializes it\&. \fCalloc_func\fP and \fCfree_func\fP \fBMUST\fP be both zero or both non-zero\&. In the case they are both zero, default memory allocators are used\&. \fCopaque\fP is passed to \fCalloc_func\fP and \fCfree_func\fP when they are called\&. \fCfree_func\fP has to return without doing anything when asked to free a NULL pointer\&.
Eugene Kliuchnikovc931e572017-02-28 16:59:52 +0100426.PP
427\fBParameters:\fP
428.RS 4
429\fIalloc_func\fP custom memory allocation function
430.br
Eugene Kliuchnikovda254cf2017-12-12 14:33:12 +0100431\fIfree_func\fP custom memory free function
Eugene Kliuchnikovc931e572017-02-28 16:59:52 +0100432.br
433\fIopaque\fP custom memory manager handle
434.RE
435.PP
436\fBReturns:\fP
437.RS 4
438\fC0\fP if instance can not be allocated or initialized
439.PP
440pointer to initialized \fBBrotliEncoderState\fP otherwise
441.RE
442.PP
443
444.SS "void BrotliEncoderDestroyInstance (\fBBrotliEncoderState\fP * state)"
445
446.PP
447Deinitializes and frees \fBBrotliEncoderState\fP instance\&.
448.PP
449\fBParameters:\fP
450.RS 4
451\fIstate\fP decoder instance to be cleaned up and deallocated
452.RE
453.PP
454
455.SS "\fBBROTLI_BOOL\fP BrotliEncoderHasMoreOutput (\fBBrotliEncoderState\fP * state)"
456
457.PP
458Checks if encoder has more output\&.
459.PP
460\fBParameters:\fP
461.RS 4
462\fIstate\fP encoder instance
463.RE
464.PP
465\fBReturns:\fP
466.RS 4
467\fBBROTLI_TRUE\fP, if encoder has some unconsumed output
468.PP
469\fBBROTLI_FALSE\fP otherwise
470.RE
471.PP
472
473.SS "\fBBROTLI_BOOL\fP BrotliEncoderIsFinished (\fBBrotliEncoderState\fP * state)"
474
475.PP
476Checks if encoder instance reached the final state\&.
477.PP
478\fBParameters:\fP
479.RS 4
480\fIstate\fP encoder instance
481.RE
482.PP
483\fBReturns:\fP
484.RS 4
485\fBBROTLI_TRUE\fP if encoder is in a state where it reached the end of the input and produced all of the output
486.PP
487\fBBROTLI_FALSE\fP otherwise
488.RE
489.PP
490
491.SS "size_t BrotliEncoderMaxCompressedSize (size_t input_size)"
492
493.PP
494Calculates the output size bound for the given \fCinput_size\fP\&.
495.PP
496\fBWarning:\fP
497.RS 4
Eugene Kliuchnikovda254cf2017-12-12 14:33:12 +0100498Result is only valid if quality is at least \fC2\fP and, in case \fBBrotliEncoderCompressStream\fP was used, no flushes (\fBBROTLI_OPERATION_FLUSH\fP) were performed\&.
Eugene Kliuchnikovc931e572017-02-28 16:59:52 +0100499.RE
500.PP
501\fBParameters:\fP
502.RS 4
503\fIinput_size\fP size of projected input
504.RE
505.PP
506\fBReturns:\fP
507.RS 4
508\fC0\fP if result does not fit \fCsize_t\fP
509.RE
510.PP
511
Eugene Kliuchnikovc931e572017-02-28 16:59:52 +0100512.SS "\fBBROTLI_BOOL\fP BrotliEncoderSetParameter (\fBBrotliEncoderState\fP * state, \fBBrotliEncoderParameter\fP param, uint32_t value)"
513
514.PP
515Sets the specified parameter to the given encoder instance\&.
516.PP
517\fBParameters:\fP
518.RS 4
519\fIstate\fP encoder instance
520.br
521\fIparam\fP parameter to set
522.br
523\fIvalue\fP new parameter value
524.RE
525.PP
526\fBReturns:\fP
527.RS 4
528\fBBROTLI_FALSE\fP if parameter is unrecognized, or value is invalid
529.PP
530\fBBROTLI_FALSE\fP if value of parameter can not be changed at current encoder state (e\&.g\&. when encoding is started, window size might be already encoded and therefore it is impossible to change it)
531.PP
532\fBBROTLI_TRUE\fP if value is accepted
533.RE
534.PP
535\fBWarning:\fP
536.RS 4
537invalid values might be accepted in case they would not break encoding process\&.
538.RE
539.PP
540
541.SS "const uint8_t* BrotliEncoderTakeOutput (\fBBrotliEncoderState\fP * state, size_t * size)"
542
543.PP
544Acquires pointer to internal output buffer\&. This method is used to make language bindings easier and more efficient:
545.IP "1." 4
546push data to \fBBrotliEncoderCompressStream\fP, until \fBBrotliEncoderHasMoreOutput\fP returns BROTL_TRUE
547.IP "2." 4
548use \fBBrotliEncoderTakeOutput\fP to peek bytes and copy to language-specific entity
549.PP
550.PP
551Also this could be useful if there is an output stream that is able to consume all the provided data (e\&.g\&. when data is saved to file system)\&.
552.PP
553\fBAttention:\fP
554.RS 4
555After every call to \fBBrotliEncoderTakeOutput\fP \fC*size\fP bytes of output are considered consumed for all consecutive calls to the instance methods; returned pointer becomes invalidated as well\&.
556.RE
557.PP
558\fBNote:\fP
559.RS 4
560Encoder output is not guaranteed to be contiguous\&. This means that after the size-unrestricted call to \fBBrotliEncoderTakeOutput\fP, immediate next call to \fBBrotliEncoderTakeOutput\fP may return more data\&.
561.RE
562.PP
563\fBParameters:\fP
564.RS 4
565\fIstate\fP encoder instance
566.br
567\fIsize\fP \fBin:\fP number of bytes caller is ready to take, \fC0\fP if any amount could be handled;
568.br
569 \fBout:\fP amount of data pointed by returned pointer and considered consumed;
570.br
571 out value is never greater than in value, unless it is \fC0\fP
572.RE
573.PP
574\fBReturns:\fP
575.RS 4
576pointer to output data
577.RE
578.PP
579
580.SS "uint32_t BrotliEncoderVersion (void)"
581
582.PP
583Gets an encoder library version\&. Look at BROTLI_VERSION for more information\&.
584.SH "Author"
585.PP
586Generated automatically by Doxygen for Brotli from the source code\&.