Eugene Kliuchnikov | c605635 | 2017-09-20 15:02:01 +0200 | [diff] [blame] | 1 | .TH "encode.h" 3 "Wed Sep 20 2017" "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 |
| 26 | .RI "#define \fBBROTLI_MAX_INPUT_BLOCK_BITS\fP 24" |
| 27 | .br |
| 28 | .RI "\fIMaximal value for \fBBROTLI_PARAM_LGBLOCK\fP parameter\&. \fP" |
| 29 | .ti -1c |
| 30 | .RI "#define \fBBROTLI_MAX_QUALITY\fP 11" |
| 31 | .br |
| 32 | .RI "\fIMaximal value for \fBBROTLI_PARAM_QUALITY\fP parameter\&. \fP" |
| 33 | .ti -1c |
| 34 | .RI "#define \fBBROTLI_MAX_WINDOW_BITS\fP 24" |
| 35 | .br |
| 36 | .RI "\fIMaximal value for \fBBROTLI_PARAM_LGWIN\fP parameter\&. \fP" |
| 37 | .ti -1c |
| 38 | .RI "#define \fBBROTLI_MIN_INPUT_BLOCK_BITS\fP 16" |
| 39 | .br |
| 40 | .RI "\fIMinimal value for \fBBROTLI_PARAM_LGBLOCK\fP parameter\&. \fP" |
| 41 | .ti -1c |
| 42 | .RI "#define \fBBROTLI_MIN_QUALITY\fP 0" |
| 43 | .br |
| 44 | .RI "\fIMinimal value for \fBBROTLI_PARAM_QUALITY\fP parameter\&. \fP" |
| 45 | .ti -1c |
| 46 | .RI "#define \fBBROTLI_MIN_WINDOW_BITS\fP 10" |
| 47 | .br |
| 48 | .RI "\fIMinimal value for \fBBROTLI_PARAM_LGWIN\fP parameter\&. \fP" |
| 49 | .in -1c |
| 50 | .SS "Typedefs" |
| 51 | |
| 52 | .in +1c |
| 53 | .ti -1c |
| 54 | .RI "typedef enum \fBBrotliEncoderMode\fP \fBBrotliEncoderMode\fP" |
| 55 | .br |
| 56 | .RI "\fIOptions for \fBBROTLI_PARAM_MODE\fP parameter\&. \fP" |
| 57 | .ti -1c |
| 58 | .RI "typedef enum \fBBrotliEncoderOperation\fP \fBBrotliEncoderOperation\fP" |
| 59 | .br |
| 60 | .RI "\fIOperations that can be performed by streaming encoder\&. \fP" |
| 61 | .ti -1c |
| 62 | .RI "typedef enum \fBBrotliEncoderParameter\fP \fBBrotliEncoderParameter\fP" |
| 63 | .br |
| 64 | .RI "\fIOptions to be used with \fBBrotliEncoderSetParameter\fP\&. \fP" |
| 65 | .ti -1c |
| 66 | .RI "typedef struct BrotliEncoderStateStruct \fBBrotliEncoderState\fP" |
| 67 | .br |
| 68 | .RI "\fIOpaque structure that holds encoder state\&. \fP" |
| 69 | .in -1c |
| 70 | .SS "Enumerations" |
| 71 | .SS "Functions" |
| 72 | |
| 73 | .in +1c |
| 74 | .ti -1c |
| 75 | .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])" |
| 76 | .br |
| 77 | .RI "\fIPerforms one-shot memory-to-memory compression\&. \fP" |
| 78 | .ti -1c |
| 79 | .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)" |
| 80 | .br |
| 81 | .RI "\fICompresses input stream to output stream\&. \fP" |
| 82 | .ti -1c |
| 83 | .RI "\fBBrotliEncoderState\fP * \fBBrotliEncoderCreateInstance\fP (\fBbrotli_alloc_func\fP alloc_func, \fBbrotli_free_func\fP free_func, void *opaque)" |
| 84 | .br |
| 85 | .RI "\fICreates an instance of \fBBrotliEncoderState\fP and initializes it\&. \fP" |
| 86 | .ti -1c |
| 87 | .RI "void \fBBrotliEncoderDestroyInstance\fP (\fBBrotliEncoderState\fP *state)" |
| 88 | .br |
| 89 | .RI "\fIDeinitializes and frees \fBBrotliEncoderState\fP instance\&. \fP" |
| 90 | .ti -1c |
| 91 | .RI "\fBBROTLI_BOOL\fP \fBBrotliEncoderHasMoreOutput\fP (\fBBrotliEncoderState\fP *state)" |
| 92 | .br |
| 93 | .RI "\fIChecks if encoder has more output\&. \fP" |
| 94 | .ti -1c |
| 95 | .RI "\fBBROTLI_BOOL\fP \fBBrotliEncoderIsFinished\fP (\fBBrotliEncoderState\fP *state)" |
| 96 | .br |
| 97 | .RI "\fIChecks if encoder instance reached the final state\&. \fP" |
| 98 | .ti -1c |
| 99 | .RI "size_t \fBBrotliEncoderMaxCompressedSize\fP (size_t input_size)" |
| 100 | .br |
| 101 | .RI "\fICalculates the output size bound for the given \fCinput_size\fP\&. \fP" |
| 102 | .ti -1c |
Eugene Kliuchnikov | c931e57 | 2017-02-28 16:59:52 +0100 | [diff] [blame] | 103 | .RI "\fBBROTLI_BOOL\fP \fBBrotliEncoderSetParameter\fP (\fBBrotliEncoderState\fP *state, \fBBrotliEncoderParameter\fP param, uint32_t value)" |
| 104 | .br |
| 105 | .RI "\fISets the specified parameter to the given encoder instance\&. \fP" |
| 106 | .ti -1c |
| 107 | .RI "const uint8_t * \fBBrotliEncoderTakeOutput\fP (\fBBrotliEncoderState\fP *state, size_t *size)" |
| 108 | .br |
| 109 | .RI "\fIAcquires pointer to internal output buffer\&. \fP" |
| 110 | .ti -1c |
| 111 | .RI "uint32_t \fBBrotliEncoderVersion\fP (void)" |
| 112 | .br |
| 113 | .RI "\fIGets an encoder library version\&. \fP" |
| 114 | .in -1c |
| 115 | .SH "Detailed Description" |
| 116 | .PP |
| 117 | API for Brotli compression\&. |
| 118 | |
| 119 | |
| 120 | .SH "Macro Definition Documentation" |
| 121 | .PP |
| 122 | .SS "#define BROTLI_DEFAULT_MODE \fBBROTLI_MODE_GENERIC\fP" |
| 123 | |
| 124 | .PP |
| 125 | Default value for \fBBROTLI_PARAM_MODE\fP parameter\&. |
| 126 | .SS "#define BROTLI_DEFAULT_QUALITY 11" |
| 127 | |
| 128 | .PP |
| 129 | Default value for \fBBROTLI_PARAM_QUALITY\fP parameter\&. |
| 130 | .SS "#define BROTLI_DEFAULT_WINDOW 22" |
| 131 | |
| 132 | .PP |
| 133 | Default value for \fBBROTLI_PARAM_LGWIN\fP parameter\&. |
| 134 | .SS "#define BROTLI_MAX_INPUT_BLOCK_BITS 24" |
| 135 | |
| 136 | .PP |
| 137 | Maximal value for \fBBROTLI_PARAM_LGBLOCK\fP parameter\&. |
| 138 | .SS "#define BROTLI_MAX_QUALITY 11" |
| 139 | |
| 140 | .PP |
| 141 | Maximal value for \fBBROTLI_PARAM_QUALITY\fP parameter\&. |
| 142 | .SS "#define BROTLI_MAX_WINDOW_BITS 24" |
| 143 | |
| 144 | .PP |
| 145 | Maximal value for \fBBROTLI_PARAM_LGWIN\fP parameter\&. |
| 146 | .PP |
| 147 | \fBNote:\fP |
| 148 | .RS 4 |
| 149 | equal to \fCBROTLI_MAX_DISTANCE_BITS\fP constant\&. |
| 150 | .RE |
| 151 | .PP |
| 152 | |
| 153 | .SS "#define BROTLI_MIN_INPUT_BLOCK_BITS 16" |
| 154 | |
| 155 | .PP |
| 156 | Minimal value for \fBBROTLI_PARAM_LGBLOCK\fP parameter\&. |
| 157 | .SS "#define BROTLI_MIN_QUALITY 0" |
| 158 | |
| 159 | .PP |
| 160 | Minimal value for \fBBROTLI_PARAM_QUALITY\fP parameter\&. |
| 161 | .SS "#define BROTLI_MIN_WINDOW_BITS 10" |
| 162 | |
| 163 | .PP |
| 164 | Minimal value for \fBBROTLI_PARAM_LGWIN\fP parameter\&. |
| 165 | .SH "Typedef Documentation" |
| 166 | .PP |
| 167 | .SS "typedef enum \fBBrotliEncoderMode\fP \fBBrotliEncoderMode\fP" |
| 168 | |
| 169 | .PP |
| 170 | Options for \fBBROTLI_PARAM_MODE\fP parameter\&. |
| 171 | .SS "typedef enum \fBBrotliEncoderOperation\fP \fBBrotliEncoderOperation\fP" |
| 172 | |
| 173 | .PP |
| 174 | Operations that can be performed by streaming encoder\&. |
| 175 | .SS "typedef enum \fBBrotliEncoderParameter\fP \fBBrotliEncoderParameter\fP" |
| 176 | |
| 177 | .PP |
| 178 | Options to be used with \fBBrotliEncoderSetParameter\fP\&. |
| 179 | .SS "typedef struct BrotliEncoderStateStruct \fBBrotliEncoderState\fP" |
| 180 | |
| 181 | .PP |
| 182 | Opaque structure that holds encoder state\&. Allocated and initialized with \fBBrotliEncoderCreateInstance\fP\&. Cleaned up and deallocated with \fBBrotliEncoderDestroyInstance\fP\&. |
| 183 | .SH "Enumeration Type Documentation" |
| 184 | .PP |
| 185 | .SS "enum \fBBrotliEncoderMode\fP" |
| 186 | |
| 187 | .PP |
| 188 | Options for \fBBROTLI_PARAM_MODE\fP parameter\&. |
| 189 | .PP |
| 190 | \fBEnumerator\fP |
| 191 | .in +1c |
| 192 | .TP |
| 193 | \fB\fIBROTLI_MODE_GENERIC \fP\fP |
| 194 | Default compression mode\&. In this mode compressor does not know anything in advance about the properties of the input\&. |
| 195 | .TP |
| 196 | \fB\fIBROTLI_MODE_TEXT \fP\fP |
| 197 | Compression mode for UTF-8 formatted text input\&. |
| 198 | .TP |
| 199 | \fB\fIBROTLI_MODE_FONT \fP\fP |
| 200 | Compression mode used in WOFF 2\&.0\&. |
| 201 | .SS "enum \fBBrotliEncoderOperation\fP" |
| 202 | |
| 203 | .PP |
| 204 | Operations that can be performed by streaming encoder\&. |
| 205 | .PP |
| 206 | \fBEnumerator\fP |
| 207 | .in +1c |
| 208 | .TP |
| 209 | \fB\fIBROTLI_OPERATION_PROCESS \fP\fP |
| 210 | Process input\&. Encoder may postpone producing output, until it has processed enough input\&. |
| 211 | .TP |
| 212 | \fB\fIBROTLI_OPERATION_FLUSH \fP\fP |
Eugene Kliuchnikov | c605635 | 2017-09-20 15:02:01 +0200 | [diff] [blame] | 213 | 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] | 214 | .PP |
| 215 | \fBWarning:\fP |
| 216 | .RS 4 |
| 217 | Until flush is complete, client \fBSHOULD\fP \fBNOT\fP swap, reduce or extend input stream\&. |
| 218 | .RE |
| 219 | .PP |
| 220 | When flush is complete, output data will be sufficient for decoder to reproduce all the given input\&. |
| 221 | .TP |
| 222 | \fB\fIBROTLI_OPERATION_FINISH \fP\fP |
Eugene Kliuchnikov | c605635 | 2017-09-20 15:02:01 +0200 | [diff] [blame] | 223 | 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] | 224 | .PP |
| 225 | \fBWarning:\fP |
| 226 | .RS 4 |
| 227 | Until finalization is complete, client \fBSHOULD\fP \fBNOT\fP swap, reduce or extend input stream\&. |
| 228 | .RE |
| 229 | .PP |
| 230 | Helper function \fBBrotliEncoderIsFinished\fP checks if stream is finalized and output fully dumped\&. |
| 231 | .PP |
| 232 | Adding more input data to finalized stream is impossible\&. |
| 233 | .TP |
| 234 | \fB\fIBROTLI_OPERATION_EMIT_METADATA \fP\fP |
| 235 | 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\&. |
| 236 | .PP |
| 237 | \fBNote:\fP |
| 238 | .RS 4 |
| 239 | Encoder may emit empty metadata blocks internally, to pad encoded stream to byte boundary\&. |
| 240 | .RE |
| 241 | .PP |
| 242 | \fBWarning:\fP |
| 243 | .RS 4 |
| 244 | Until emitting metadata is complete client \fBSHOULD\fP \fBNOT\fP swap, reduce or extend input stream\&. |
| 245 | .PP |
| 246 | 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\&. |
| 247 | .RE |
| 248 | .PP |
| 249 | Stream is soft-flushed before metadata block is emitted\&. Metadata block \fBMUST\fP be no longer than than 16MiB\&. |
| 250 | .SS "enum \fBBrotliEncoderParameter\fP" |
| 251 | |
| 252 | .PP |
| 253 | Options to be used with \fBBrotliEncoderSetParameter\fP\&. |
| 254 | .PP |
| 255 | \fBEnumerator\fP |
| 256 | .in +1c |
| 257 | .TP |
| 258 | \fB\fIBROTLI_PARAM_MODE \fP\fP |
| 259 | Tune encoder for specific input\&. \fBBrotliEncoderMode\fP enumerates all available values\&. |
| 260 | .TP |
| 261 | \fB\fIBROTLI_PARAM_QUALITY \fP\fP |
| 262 | 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\&. |
| 263 | .TP |
| 264 | \fB\fIBROTLI_PARAM_LGWIN \fP\fP |
| 265 | Recommended sliding LZ77 window size\&. Encoder may reduce this value, e\&.g\&. if input is much smaller than window size\&. |
| 266 | .PP |
| 267 | Window size is \fC(1 << value) - 16\fP\&. |
| 268 | .PP |
| 269 | Range is from \fBBROTLI_MIN_WINDOW_BITS\fP to \fBBROTLI_MAX_WINDOW_BITS\fP\&. |
| 270 | .TP |
| 271 | \fB\fIBROTLI_PARAM_LGBLOCK \fP\fP |
| 272 | Recommended input block size\&. Encoder may reduce this value, e\&.g\&. if input is much smaller than input block size\&. |
| 273 | .PP |
| 274 | Range is from \fBBROTLI_MIN_INPUT_BLOCK_BITS\fP to \fBBROTLI_MAX_INPUT_BLOCK_BITS\fP\&. |
| 275 | .PP |
| 276 | \fBNote:\fP |
| 277 | .RS 4 |
| 278 | Bigger input block size allows better compression, but consumes more memory\&. |
| 279 | .br |
| 280 | The rough formula of memory used for temporary input storage is \fC3 << lgBlock\fP\&. |
| 281 | .RE |
| 282 | .PP |
| 283 | |
| 284 | .TP |
| 285 | \fB\fIBROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING \fP\fP |
| 286 | Flag that affects usage of 'literal context modeling' format feature\&. This flag is a 'decoding-speed vs compression ratio' trade-off\&. |
| 287 | .TP |
| 288 | \fB\fIBROTLI_PARAM_SIZE_HINT \fP\fP |
| 289 | Estimated total input size for all \fBBrotliEncoderCompressStream\fP calls\&. The default value is 0, which means that the total input size is unknown\&. |
| 290 | .SH "Function Documentation" |
| 291 | .PP |
| 292 | .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])" |
| 293 | |
| 294 | .PP |
| 295 | 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\&. |
| 296 | .PP |
| 297 | \fBNote:\fP |
| 298 | .RS 4 |
| 299 | If \fBBrotliEncoderMaxCompressedSize\fP(\fCinput_size\fP) returns non-zero value, then output is guaranteed to be no longer than that\&. |
| 300 | .RE |
| 301 | .PP |
| 302 | \fBParameters:\fP |
| 303 | .RS 4 |
| 304 | \fIquality\fP quality parameter value, e\&.g\&. \fBBROTLI_DEFAULT_QUALITY\fP |
| 305 | .br |
| 306 | \fIlgwin\fP lgwin parameter value, e\&.g\&. \fBBROTLI_DEFAULT_WINDOW\fP |
| 307 | .br |
| 308 | \fImode\fP mode parameter value, e\&.g\&. \fBBROTLI_DEFAULT_MODE\fP |
| 309 | .br |
| 310 | \fIinput_size\fP size of \fCinput_buffer\fP |
| 311 | .br |
| 312 | \fIinput_buffer\fP input data buffer with at least \fCinput_size\fP addressable bytes |
| 313 | .br |
| 314 | \fIencoded_size\fP \fBin:\fP size of \fCencoded_buffer\fP; |
| 315 | .br |
| 316 | \fBout:\fP length of compressed data written to \fCencoded_buffer\fP, or \fC0\fP if compression fails |
| 317 | .br |
| 318 | \fIencoded_buffer\fP compressed data destination buffer |
| 319 | .RE |
| 320 | .PP |
| 321 | \fBReturns:\fP |
| 322 | .RS 4 |
| 323 | \fBBROTLI_FALSE\fP in case of compression error |
| 324 | .PP |
| 325 | \fBBROTLI_FALSE\fP if output buffer is too small |
| 326 | .PP |
| 327 | \fBBROTLI_TRUE\fP otherwise |
| 328 | .RE |
| 329 | .PP |
| 330 | |
| 331 | .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)" |
| 332 | |
| 333 | .PP |
| 334 | 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\&. |
| 335 | .PP |
| 336 | 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\&. |
| 337 | .PP |
| 338 | \fCtotal_out\fP, if it is not a null-pointer, will be set to the number of bytes decompressed since the last \fCstate\fP initialization\&. |
| 339 | .PP |
| 340 | Internally workflow consists of 3 tasks: |
| 341 | .IP "1." 4 |
| 342 | (optionally) copy input data to internal buffer |
| 343 | .IP "2." 4 |
| 344 | actually compress data and (optionally) store it to internal buffer |
| 345 | .IP "3." 4 |
| 346 | (optionally) copy compressed bytes from internal buffer to output stream |
| 347 | .PP |
| 348 | .PP |
| 349 | Whenever all 3 tasks can't move forward anymore, or error occurs, this method returns the control flow to caller\&. |
| 350 | .PP |
| 351 | \fCop\fP is used to perform flush, finish the stream, or inject metadata block\&. See \fBBrotliEncoderOperation\fP for more information\&. |
| 352 | .PP |
| 353 | 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\&. |
| 354 | .PP |
| 355 | 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\&. |
| 356 | .PP |
| 357 | \fBWarning:\fP |
| 358 | .RS 4 |
| 359 | When flushing and finishing, \fCop\fP should not change until operation is complete; input stream should not be swapped, reduced or extended as well\&. |
| 360 | .RE |
| 361 | .PP |
| 362 | \fBParameters:\fP |
| 363 | .RS 4 |
| 364 | \fIstate\fP encoder instance |
| 365 | .br |
| 366 | \fIop\fP requested operation |
| 367 | .br |
| 368 | \fIavailable_in\fP \fBin:\fP amount of available input; |
| 369 | .br |
| 370 | \fBout:\fP amount of unused input |
| 371 | .br |
| 372 | \fInext_in\fP pointer to the next input byte |
| 373 | .br |
| 374 | \fIavailable_out\fP \fBin:\fP length of output buffer; |
| 375 | .br |
| 376 | \fBout:\fP remaining size of output buffer |
| 377 | .br |
| 378 | \fInext_out\fP compressed output buffer cursor; can be \fCNULL\fP if \fCavailable_out\fP is \fC0\fP |
| 379 | .br |
| 380 | \fItotal_out\fP number of bytes produced so far; can be \fCNULL\fP |
| 381 | .RE |
| 382 | .PP |
| 383 | \fBReturns:\fP |
| 384 | .RS 4 |
| 385 | \fBBROTLI_FALSE\fP if there was an error |
| 386 | .PP |
| 387 | \fBBROTLI_TRUE\fP otherwise |
| 388 | .RE |
| 389 | .PP |
| 390 | |
| 391 | .SS "\fBBrotliEncoderState\fP* BrotliEncoderCreateInstance (\fBbrotli_alloc_func\fP alloc_func, \fBbrotli_free_func\fP free_func, void * opaque)" |
| 392 | |
| 393 | .PP |
| 394 | 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\&. |
| 395 | .PP |
| 396 | \fBParameters:\fP |
| 397 | .RS 4 |
| 398 | \fIalloc_func\fP custom memory allocation function |
| 399 | .br |
| 400 | \fIfree_func\fP custom memory fee function |
| 401 | .br |
| 402 | \fIopaque\fP custom memory manager handle |
| 403 | .RE |
| 404 | .PP |
| 405 | \fBReturns:\fP |
| 406 | .RS 4 |
| 407 | \fC0\fP if instance can not be allocated or initialized |
| 408 | .PP |
| 409 | pointer to initialized \fBBrotliEncoderState\fP otherwise |
| 410 | .RE |
| 411 | .PP |
| 412 | |
| 413 | .SS "void BrotliEncoderDestroyInstance (\fBBrotliEncoderState\fP * state)" |
| 414 | |
| 415 | .PP |
| 416 | Deinitializes and frees \fBBrotliEncoderState\fP instance\&. |
| 417 | .PP |
| 418 | \fBParameters:\fP |
| 419 | .RS 4 |
| 420 | \fIstate\fP decoder instance to be cleaned up and deallocated |
| 421 | .RE |
| 422 | .PP |
| 423 | |
| 424 | .SS "\fBBROTLI_BOOL\fP BrotliEncoderHasMoreOutput (\fBBrotliEncoderState\fP * state)" |
| 425 | |
| 426 | .PP |
| 427 | Checks if encoder has more output\&. |
| 428 | .PP |
| 429 | \fBParameters:\fP |
| 430 | .RS 4 |
| 431 | \fIstate\fP encoder instance |
| 432 | .RE |
| 433 | .PP |
| 434 | \fBReturns:\fP |
| 435 | .RS 4 |
| 436 | \fBBROTLI_TRUE\fP, if encoder has some unconsumed output |
| 437 | .PP |
| 438 | \fBBROTLI_FALSE\fP otherwise |
| 439 | .RE |
| 440 | .PP |
| 441 | |
| 442 | .SS "\fBBROTLI_BOOL\fP BrotliEncoderIsFinished (\fBBrotliEncoderState\fP * state)" |
| 443 | |
| 444 | .PP |
| 445 | Checks if encoder instance reached the final state\&. |
| 446 | .PP |
| 447 | \fBParameters:\fP |
| 448 | .RS 4 |
| 449 | \fIstate\fP encoder instance |
| 450 | .RE |
| 451 | .PP |
| 452 | \fBReturns:\fP |
| 453 | .RS 4 |
| 454 | \fBBROTLI_TRUE\fP if encoder is in a state where it reached the end of the input and produced all of the output |
| 455 | .PP |
| 456 | \fBBROTLI_FALSE\fP otherwise |
| 457 | .RE |
| 458 | .PP |
| 459 | |
| 460 | .SS "size_t BrotliEncoderMaxCompressedSize (size_t input_size)" |
| 461 | |
| 462 | .PP |
| 463 | Calculates the output size bound for the given \fCinput_size\fP\&. |
| 464 | .PP |
| 465 | \fBWarning:\fP |
| 466 | .RS 4 |
| 467 | Result is not applicable to \fBBrotliEncoderCompressStream\fP output, because every 'flush' adds extra overhead bytes, and some encoder settings (e\&.g\&. quality \fC0\fP and \fC1\fP) might imply a 'soft flush' after every chunk of input\&. |
| 468 | .RE |
| 469 | .PP |
| 470 | \fBParameters:\fP |
| 471 | .RS 4 |
| 472 | \fIinput_size\fP size of projected input |
| 473 | .RE |
| 474 | .PP |
| 475 | \fBReturns:\fP |
| 476 | .RS 4 |
| 477 | \fC0\fP if result does not fit \fCsize_t\fP |
| 478 | .RE |
| 479 | .PP |
| 480 | |
Eugene Kliuchnikov | c931e57 | 2017-02-28 16:59:52 +0100 | [diff] [blame] | 481 | .SS "\fBBROTLI_BOOL\fP BrotliEncoderSetParameter (\fBBrotliEncoderState\fP * state, \fBBrotliEncoderParameter\fP param, uint32_t value)" |
| 482 | |
| 483 | .PP |
| 484 | Sets the specified parameter to the given encoder instance\&. |
| 485 | .PP |
| 486 | \fBParameters:\fP |
| 487 | .RS 4 |
| 488 | \fIstate\fP encoder instance |
| 489 | .br |
| 490 | \fIparam\fP parameter to set |
| 491 | .br |
| 492 | \fIvalue\fP new parameter value |
| 493 | .RE |
| 494 | .PP |
| 495 | \fBReturns:\fP |
| 496 | .RS 4 |
| 497 | \fBBROTLI_FALSE\fP if parameter is unrecognized, or value is invalid |
| 498 | .PP |
| 499 | \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) |
| 500 | .PP |
| 501 | \fBBROTLI_TRUE\fP if value is accepted |
| 502 | .RE |
| 503 | .PP |
| 504 | \fBWarning:\fP |
| 505 | .RS 4 |
| 506 | invalid values might be accepted in case they would not break encoding process\&. |
| 507 | .RE |
| 508 | .PP |
| 509 | |
| 510 | .SS "const uint8_t* BrotliEncoderTakeOutput (\fBBrotliEncoderState\fP * state, size_t * size)" |
| 511 | |
| 512 | .PP |
| 513 | Acquires pointer to internal output buffer\&. This method is used to make language bindings easier and more efficient: |
| 514 | .IP "1." 4 |
| 515 | push data to \fBBrotliEncoderCompressStream\fP, until \fBBrotliEncoderHasMoreOutput\fP returns BROTL_TRUE |
| 516 | .IP "2." 4 |
| 517 | use \fBBrotliEncoderTakeOutput\fP to peek bytes and copy to language-specific entity |
| 518 | .PP |
| 519 | .PP |
| 520 | 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)\&. |
| 521 | .PP |
| 522 | \fBAttention:\fP |
| 523 | .RS 4 |
| 524 | 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\&. |
| 525 | .RE |
| 526 | .PP |
| 527 | \fBNote:\fP |
| 528 | .RS 4 |
| 529 | 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\&. |
| 530 | .RE |
| 531 | .PP |
| 532 | \fBParameters:\fP |
| 533 | .RS 4 |
| 534 | \fIstate\fP encoder instance |
| 535 | .br |
| 536 | \fIsize\fP \fBin:\fP number of bytes caller is ready to take, \fC0\fP if any amount could be handled; |
| 537 | .br |
| 538 | \fBout:\fP amount of data pointed by returned pointer and considered consumed; |
| 539 | .br |
| 540 | out value is never greater than in value, unless it is \fC0\fP |
| 541 | .RE |
| 542 | .PP |
| 543 | \fBReturns:\fP |
| 544 | .RS 4 |
| 545 | pointer to output data |
| 546 | .RE |
| 547 | .PP |
| 548 | |
| 549 | .SS "uint32_t BrotliEncoderVersion (void)" |
| 550 | |
| 551 | .PP |
| 552 | Gets an encoder library version\&. Look at BROTLI_VERSION for more information\&. |
| 553 | .SH "Author" |
| 554 | .PP |
| 555 | Generated automatically by Doxygen for Brotli from the source code\&. |