Tianjie Xu | a5dcb7c | 2018-09-25 12:25:15 -0700 | [diff] [blame] | 1 | .TH "encode.h" 3 "Thu Feb 22 2018" "Brotli" \" -*- nroff -*- |
Eugene Kliuchnikov | c931e57 | 2017-02-28 16:59:52 +0100 | [diff] [blame] | 2 | .ad l |
| 3 | .nh |
| 4 | .SH NAME |
| 5 | encode.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 |
Tianjie Xu | a5dcb7c | 2018-09-25 12:25:15 -0700 | [diff] [blame] | 26 | .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 Kliuchnikov | c931e57 | 2017-02-28 16:59:52 +0100 | [diff] [blame] | 30 | .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 Kliuchnikov | c931e57 | 2017-02-28 16:59:52 +0100 | [diff] [blame] | 107 | .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 |
| 121 | API 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 |
| 129 | Default value for \fBBROTLI_PARAM_MODE\fP parameter\&. |
| 130 | .SS "#define BROTLI_DEFAULT_QUALITY 11" |
| 131 | |
| 132 | .PP |
| 133 | Default value for \fBBROTLI_PARAM_QUALITY\fP parameter\&. |
| 134 | .SS "#define BROTLI_DEFAULT_WINDOW 22" |
| 135 | |
| 136 | .PP |
| 137 | Default value for \fBBROTLI_PARAM_LGWIN\fP parameter\&. |
| 138 | .SS "#define BROTLI_MAX_INPUT_BLOCK_BITS 24" |
| 139 | |
| 140 | .PP |
| 141 | Maximal value for \fBBROTLI_PARAM_LGBLOCK\fP parameter\&. |
| 142 | .SS "#define BROTLI_MAX_QUALITY 11" |
| 143 | |
| 144 | .PP |
| 145 | Maximal value for \fBBROTLI_PARAM_QUALITY\fP parameter\&. |
| 146 | .SS "#define BROTLI_MAX_WINDOW_BITS 24" |
| 147 | |
| 148 | .PP |
| 149 | Maximal value for \fBBROTLI_PARAM_LGWIN\fP parameter\&. |
| 150 | .PP |
| 151 | \fBNote:\fP |
| 152 | .RS 4 |
| 153 | equal to \fCBROTLI_MAX_DISTANCE_BITS\fP constant\&. |
| 154 | .RE |
| 155 | .PP |
| 156 | |
| 157 | .SS "#define BROTLI_MIN_INPUT_BLOCK_BITS 16" |
| 158 | |
| 159 | .PP |
| 160 | Minimal value for \fBBROTLI_PARAM_LGBLOCK\fP parameter\&. |
| 161 | .SS "#define BROTLI_MIN_QUALITY 0" |
| 162 | |
| 163 | .PP |
| 164 | Minimal value for \fBBROTLI_PARAM_QUALITY\fP parameter\&. |
| 165 | .SS "#define BROTLI_MIN_WINDOW_BITS 10" |
| 166 | |
| 167 | .PP |
| 168 | Minimal value for \fBBROTLI_PARAM_LGWIN\fP parameter\&. |
| 169 | .SH "Typedef Documentation" |
| 170 | .PP |
| 171 | .SS "typedef enum \fBBrotliEncoderMode\fP \fBBrotliEncoderMode\fP" |
| 172 | |
| 173 | .PP |
| 174 | Options for \fBBROTLI_PARAM_MODE\fP parameter\&. |
| 175 | .SS "typedef enum \fBBrotliEncoderOperation\fP \fBBrotliEncoderOperation\fP" |
| 176 | |
| 177 | .PP |
| 178 | Operations that can be performed by streaming encoder\&. |
| 179 | .SS "typedef enum \fBBrotliEncoderParameter\fP \fBBrotliEncoderParameter\fP" |
| 180 | |
| 181 | .PP |
| 182 | Options to be used with \fBBrotliEncoderSetParameter\fP\&. |
| 183 | .SS "typedef struct BrotliEncoderStateStruct \fBBrotliEncoderState\fP" |
| 184 | |
| 185 | .PP |
| 186 | Opaque 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 |
| 192 | Options for \fBBROTLI_PARAM_MODE\fP parameter\&. |
| 193 | .PP |
| 194 | \fBEnumerator\fP |
| 195 | .in +1c |
| 196 | .TP |
| 197 | \fB\fIBROTLI_MODE_GENERIC \fP\fP |
| 198 | Default 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 |
| 201 | Compression mode for UTF-8 formatted text input\&. |
| 202 | .TP |
| 203 | \fB\fIBROTLI_MODE_FONT \fP\fP |
| 204 | Compression mode used in WOFF 2\&.0\&. |
| 205 | .SS "enum \fBBrotliEncoderOperation\fP" |
| 206 | |
| 207 | .PP |
| 208 | Operations that can be performed by streaming encoder\&. |
| 209 | .PP |
| 210 | \fBEnumerator\fP |
| 211 | .in +1c |
| 212 | .TP |
| 213 | \fB\fIBROTLI_OPERATION_PROCESS \fP\fP |
| 214 | Process input\&. Encoder may postpone producing output, until it has processed enough input\&. |
| 215 | .TP |
| 216 | \fB\fIBROTLI_OPERATION_FLUSH \fP\fP |
Eugene Kliuchnikov | c605635 | 2017-09-20 15:02:01 +0200 | [diff] [blame] | 217 | Produce 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 Kliuchnikov | c931e57 | 2017-02-28 16:59:52 +0100 | [diff] [blame] | 218 | .PP |
| 219 | \fBWarning:\fP |
| 220 | .RS 4 |
| 221 | Until flush is complete, client \fBSHOULD\fP \fBNOT\fP swap, reduce or extend input stream\&. |
| 222 | .RE |
| 223 | .PP |
| 224 | When 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 Kliuchnikov | c605635 | 2017-09-20 15:02:01 +0200 | [diff] [blame] | 227 | Finalize 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 Kliuchnikov | c931e57 | 2017-02-28 16:59:52 +0100 | [diff] [blame] | 228 | .PP |
| 229 | \fBWarning:\fP |
| 230 | .RS 4 |
| 231 | Until finalization is complete, client \fBSHOULD\fP \fBNOT\fP swap, reduce or extend input stream\&. |
| 232 | .RE |
| 233 | .PP |
| 234 | Helper function \fBBrotliEncoderIsFinished\fP checks if stream is finalized and output fully dumped\&. |
| 235 | .PP |
| 236 | Adding more input data to finalized stream is impossible\&. |
| 237 | .TP |
| 238 | \fB\fIBROTLI_OPERATION_EMIT_METADATA \fP\fP |
| 239 | Emit 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 |
| 243 | Encoder may emit empty metadata blocks internally, to pad encoded stream to byte boundary\&. |
| 244 | .RE |
| 245 | .PP |
| 246 | \fBWarning:\fP |
| 247 | .RS 4 |
| 248 | Until emitting metadata is complete client \fBSHOULD\fP \fBNOT\fP swap, reduce or extend input stream\&. |
| 249 | .PP |
| 250 | The 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 |
| 253 | Stream 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 |
| 257 | Options to be used with \fBBrotliEncoderSetParameter\fP\&. |
| 258 | .PP |
| 259 | \fBEnumerator\fP |
| 260 | .in +1c |
| 261 | .TP |
| 262 | \fB\fIBROTLI_PARAM_MODE \fP\fP |
| 263 | Tune encoder for specific input\&. \fBBrotliEncoderMode\fP enumerates all available values\&. |
| 264 | .TP |
| 265 | \fB\fIBROTLI_PARAM_QUALITY \fP\fP |
| 266 | The 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 |
| 269 | Recommended sliding LZ77 window size\&. Encoder may reduce this value, e\&.g\&. if input is much smaller than window size\&. |
| 270 | .PP |
| 271 | Window size is \fC(1 << value) - 16\fP\&. |
| 272 | .PP |
| 273 | Range is from \fBBROTLI_MIN_WINDOW_BITS\fP to \fBBROTLI_MAX_WINDOW_BITS\fP\&. |
| 274 | .TP |
| 275 | \fB\fIBROTLI_PARAM_LGBLOCK \fP\fP |
| 276 | Recommended input block size\&. Encoder may reduce this value, e\&.g\&. if input is much smaller than input block size\&. |
| 277 | .PP |
| 278 | Range is from \fBBROTLI_MIN_INPUT_BLOCK_BITS\fP to \fBBROTLI_MAX_INPUT_BLOCK_BITS\fP\&. |
| 279 | .PP |
| 280 | \fBNote:\fP |
| 281 | .RS 4 |
| 282 | Bigger 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 |
| 290 | Flag 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 |
| 293 | Estimated total input size for all \fBBrotliEncoderCompressStream\fP calls\&. The default value is 0, which means that the total input size is unknown\&. |
Tianjie Xu | a5dcb7c | 2018-09-25 12:25:15 -0700 | [diff] [blame] | 294 | .TP |
| 295 | \fB\fIBROTLI_PARAM_LARGE_WINDOW \fP\fP |
| 296 | Flag that determines if 'Large Window Brotli' is used\&. |
| 297 | .TP |
| 298 | \fB\fIBROTLI_PARAM_NPOSTFIX \fP\fP |
| 299 | Recommended number of postfix bits (NPOSTFIX)\&. Encoder may change this value\&. |
| 300 | .PP |
| 301 | Range is from 0 to ::BROTLI_MAX_NPOSTFIX\&. |
| 302 | .TP |
| 303 | \fB\fIBROTLI_PARAM_NDIRECT \fP\fP |
| 304 | Recommended number of direct distance codes (NDIRECT)\&. Encoder may change this value\&. |
| 305 | .PP |
| 306 | Range is from 0 to (15 << NPOSTFIX) in steps of (1 << NPOSTFIX)\&. |
Eugene Kliuchnikov | c931e57 | 2017-02-28 16:59:52 +0100 | [diff] [blame] | 307 | .SH "Function Documentation" |
| 308 | .PP |
| 309 | .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])" |
| 310 | |
| 311 | .PP |
| 312 | Performs 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\&. |
| 313 | .PP |
| 314 | \fBNote:\fP |
| 315 | .RS 4 |
| 316 | If \fBBrotliEncoderMaxCompressedSize\fP(\fCinput_size\fP) returns non-zero value, then output is guaranteed to be no longer than that\&. |
| 317 | .RE |
| 318 | .PP |
| 319 | \fBParameters:\fP |
| 320 | .RS 4 |
| 321 | \fIquality\fP quality parameter value, e\&.g\&. \fBBROTLI_DEFAULT_QUALITY\fP |
| 322 | .br |
| 323 | \fIlgwin\fP lgwin parameter value, e\&.g\&. \fBBROTLI_DEFAULT_WINDOW\fP |
| 324 | .br |
| 325 | \fImode\fP mode parameter value, e\&.g\&. \fBBROTLI_DEFAULT_MODE\fP |
| 326 | .br |
| 327 | \fIinput_size\fP size of \fCinput_buffer\fP |
| 328 | .br |
| 329 | \fIinput_buffer\fP input data buffer with at least \fCinput_size\fP addressable bytes |
| 330 | .br |
| 331 | \fIencoded_size\fP \fBin:\fP size of \fCencoded_buffer\fP; |
| 332 | .br |
| 333 | \fBout:\fP length of compressed data written to \fCencoded_buffer\fP, or \fC0\fP if compression fails |
| 334 | .br |
| 335 | \fIencoded_buffer\fP compressed data destination buffer |
| 336 | .RE |
| 337 | .PP |
| 338 | \fBReturns:\fP |
| 339 | .RS 4 |
| 340 | \fBBROTLI_FALSE\fP in case of compression error |
| 341 | .PP |
| 342 | \fBBROTLI_FALSE\fP if output buffer is too small |
| 343 | .PP |
| 344 | \fBBROTLI_TRUE\fP otherwise |
| 345 | .RE |
| 346 | .PP |
| 347 | |
| 348 | .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)" |
| 349 | |
| 350 | .PP |
| 351 | Compresses 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\&. |
| 352 | .PP |
| 353 | After 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\&. |
| 354 | .PP |
Tianjie Xu | a5dcb7c | 2018-09-25 12:25:15 -0700 | [diff] [blame] | 355 | \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 Kliuchnikov | c931e57 | 2017-02-28 16:59:52 +0100 | [diff] [blame] | 356 | .PP |
| 357 | Internally workflow consists of 3 tasks: |
| 358 | .IP "1." 4 |
| 359 | (optionally) copy input data to internal buffer |
| 360 | .IP "2." 4 |
| 361 | actually compress data and (optionally) store it to internal buffer |
| 362 | .IP "3." 4 |
| 363 | (optionally) copy compressed bytes from internal buffer to output stream |
| 364 | .PP |
| 365 | .PP |
| 366 | Whenever all 3 tasks can't move forward anymore, or error occurs, this method returns the control flow to caller\&. |
| 367 | .PP |
| 368 | \fCop\fP is used to perform flush, finish the stream, or inject metadata block\&. See \fBBrotliEncoderOperation\fP for more information\&. |
| 369 | .PP |
| 370 | Flushing 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\&. |
| 371 | .PP |
| 372 | Finishing 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\&. |
| 373 | .PP |
| 374 | \fBWarning:\fP |
| 375 | .RS 4 |
| 376 | When flushing and finishing, \fCop\fP should not change until operation is complete; input stream should not be swapped, reduced or extended as well\&. |
| 377 | .RE |
| 378 | .PP |
| 379 | \fBParameters:\fP |
| 380 | .RS 4 |
| 381 | \fIstate\fP encoder instance |
| 382 | .br |
| 383 | \fIop\fP requested operation |
| 384 | .br |
| 385 | \fIavailable_in\fP \fBin:\fP amount of available input; |
| 386 | .br |
| 387 | \fBout:\fP amount of unused input |
| 388 | .br |
| 389 | \fInext_in\fP pointer to the next input byte |
| 390 | .br |
| 391 | \fIavailable_out\fP \fBin:\fP length of output buffer; |
| 392 | .br |
| 393 | \fBout:\fP remaining size of output buffer |
| 394 | .br |
| 395 | \fInext_out\fP compressed output buffer cursor; can be \fCNULL\fP if \fCavailable_out\fP is \fC0\fP |
| 396 | .br |
| 397 | \fItotal_out\fP number of bytes produced so far; can be \fCNULL\fP |
| 398 | .RE |
| 399 | .PP |
| 400 | \fBReturns:\fP |
| 401 | .RS 4 |
| 402 | \fBBROTLI_FALSE\fP if there was an error |
| 403 | .PP |
| 404 | \fBBROTLI_TRUE\fP otherwise |
| 405 | .RE |
| 406 | .PP |
| 407 | |
| 408 | .SS "\fBBrotliEncoderState\fP* BrotliEncoderCreateInstance (\fBbrotli_alloc_func\fP alloc_func, \fBbrotli_free_func\fP free_func, void * opaque)" |
| 409 | |
| 410 | .PP |
Tianjie Xu | a5dcb7c | 2018-09-25 12:25:15 -0700 | [diff] [blame] | 411 | Creates 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 Kliuchnikov | c931e57 | 2017-02-28 16:59:52 +0100 | [diff] [blame] | 412 | .PP |
| 413 | \fBParameters:\fP |
| 414 | .RS 4 |
| 415 | \fIalloc_func\fP custom memory allocation function |
| 416 | .br |
Tianjie Xu | a5dcb7c | 2018-09-25 12:25:15 -0700 | [diff] [blame] | 417 | \fIfree_func\fP custom memory free function |
Eugene Kliuchnikov | c931e57 | 2017-02-28 16:59:52 +0100 | [diff] [blame] | 418 | .br |
| 419 | \fIopaque\fP custom memory manager handle |
| 420 | .RE |
| 421 | .PP |
| 422 | \fBReturns:\fP |
| 423 | .RS 4 |
| 424 | \fC0\fP if instance can not be allocated or initialized |
| 425 | .PP |
| 426 | pointer to initialized \fBBrotliEncoderState\fP otherwise |
| 427 | .RE |
| 428 | .PP |
| 429 | |
| 430 | .SS "void BrotliEncoderDestroyInstance (\fBBrotliEncoderState\fP * state)" |
| 431 | |
| 432 | .PP |
| 433 | Deinitializes and frees \fBBrotliEncoderState\fP instance\&. |
| 434 | .PP |
| 435 | \fBParameters:\fP |
| 436 | .RS 4 |
| 437 | \fIstate\fP decoder instance to be cleaned up and deallocated |
| 438 | .RE |
| 439 | .PP |
| 440 | |
| 441 | .SS "\fBBROTLI_BOOL\fP BrotliEncoderHasMoreOutput (\fBBrotliEncoderState\fP * state)" |
| 442 | |
| 443 | .PP |
| 444 | Checks if encoder has more output\&. |
| 445 | .PP |
| 446 | \fBParameters:\fP |
| 447 | .RS 4 |
| 448 | \fIstate\fP encoder instance |
| 449 | .RE |
| 450 | .PP |
| 451 | \fBReturns:\fP |
| 452 | .RS 4 |
| 453 | \fBBROTLI_TRUE\fP, if encoder has some unconsumed output |
| 454 | .PP |
| 455 | \fBBROTLI_FALSE\fP otherwise |
| 456 | .RE |
| 457 | .PP |
| 458 | |
| 459 | .SS "\fBBROTLI_BOOL\fP BrotliEncoderIsFinished (\fBBrotliEncoderState\fP * state)" |
| 460 | |
| 461 | .PP |
| 462 | Checks if encoder instance reached the final state\&. |
| 463 | .PP |
| 464 | \fBParameters:\fP |
| 465 | .RS 4 |
| 466 | \fIstate\fP encoder instance |
| 467 | .RE |
| 468 | .PP |
| 469 | \fBReturns:\fP |
| 470 | .RS 4 |
| 471 | \fBBROTLI_TRUE\fP if encoder is in a state where it reached the end of the input and produced all of the output |
| 472 | .PP |
| 473 | \fBBROTLI_FALSE\fP otherwise |
| 474 | .RE |
| 475 | .PP |
| 476 | |
| 477 | .SS "size_t BrotliEncoderMaxCompressedSize (size_t input_size)" |
| 478 | |
| 479 | .PP |
| 480 | Calculates the output size bound for the given \fCinput_size\fP\&. |
| 481 | .PP |
| 482 | \fBWarning:\fP |
| 483 | .RS 4 |
Tianjie Xu | a5dcb7c | 2018-09-25 12:25:15 -0700 | [diff] [blame] | 484 | Result 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 Kliuchnikov | c931e57 | 2017-02-28 16:59:52 +0100 | [diff] [blame] | 485 | .RE |
| 486 | .PP |
| 487 | \fBParameters:\fP |
| 488 | .RS 4 |
| 489 | \fIinput_size\fP size of projected input |
| 490 | .RE |
| 491 | .PP |
| 492 | \fBReturns:\fP |
| 493 | .RS 4 |
| 494 | \fC0\fP if result does not fit \fCsize_t\fP |
| 495 | .RE |
| 496 | .PP |
| 497 | |
Eugene Kliuchnikov | c931e57 | 2017-02-28 16:59:52 +0100 | [diff] [blame] | 498 | .SS "\fBBROTLI_BOOL\fP BrotliEncoderSetParameter (\fBBrotliEncoderState\fP * state, \fBBrotliEncoderParameter\fP param, uint32_t value)" |
| 499 | |
| 500 | .PP |
| 501 | Sets the specified parameter to the given encoder instance\&. |
| 502 | .PP |
| 503 | \fBParameters:\fP |
| 504 | .RS 4 |
| 505 | \fIstate\fP encoder instance |
| 506 | .br |
| 507 | \fIparam\fP parameter to set |
| 508 | .br |
| 509 | \fIvalue\fP new parameter value |
| 510 | .RE |
| 511 | .PP |
| 512 | \fBReturns:\fP |
| 513 | .RS 4 |
| 514 | \fBBROTLI_FALSE\fP if parameter is unrecognized, or value is invalid |
| 515 | .PP |
| 516 | \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) |
| 517 | .PP |
| 518 | \fBBROTLI_TRUE\fP if value is accepted |
| 519 | .RE |
| 520 | .PP |
| 521 | \fBWarning:\fP |
| 522 | .RS 4 |
| 523 | invalid values might be accepted in case they would not break encoding process\&. |
| 524 | .RE |
| 525 | .PP |
| 526 | |
| 527 | .SS "const uint8_t* BrotliEncoderTakeOutput (\fBBrotliEncoderState\fP * state, size_t * size)" |
| 528 | |
| 529 | .PP |
| 530 | Acquires pointer to internal output buffer\&. This method is used to make language bindings easier and more efficient: |
| 531 | .IP "1." 4 |
| 532 | push data to \fBBrotliEncoderCompressStream\fP, until \fBBrotliEncoderHasMoreOutput\fP returns BROTL_TRUE |
| 533 | .IP "2." 4 |
| 534 | use \fBBrotliEncoderTakeOutput\fP to peek bytes and copy to language-specific entity |
| 535 | .PP |
| 536 | .PP |
| 537 | Also 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)\&. |
| 538 | .PP |
| 539 | \fBAttention:\fP |
| 540 | .RS 4 |
| 541 | After 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\&. |
| 542 | .RE |
| 543 | .PP |
| 544 | \fBNote:\fP |
| 545 | .RS 4 |
| 546 | Encoder 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\&. |
| 547 | .RE |
| 548 | .PP |
| 549 | \fBParameters:\fP |
| 550 | .RS 4 |
| 551 | \fIstate\fP encoder instance |
| 552 | .br |
| 553 | \fIsize\fP \fBin:\fP number of bytes caller is ready to take, \fC0\fP if any amount could be handled; |
| 554 | .br |
| 555 | \fBout:\fP amount of data pointed by returned pointer and considered consumed; |
| 556 | .br |
| 557 | out value is never greater than in value, unless it is \fC0\fP |
| 558 | .RE |
| 559 | .PP |
| 560 | \fBReturns:\fP |
| 561 | .RS 4 |
| 562 | pointer to output data |
| 563 | .RE |
| 564 | .PP |
| 565 | |
| 566 | .SS "uint32_t BrotliEncoderVersion (void)" |
| 567 | |
| 568 | .PP |
| 569 | Gets an encoder library version\&. Look at BROTLI_VERSION for more information\&. |
| 570 | .SH "Author" |
| 571 | .PP |
| 572 | Generated automatically by Doxygen for Brotli from the source code\&. |