encode.h.3 24 KB

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