Revert of ui: Clean up damaged rects and clear them after painting. (patchset #2...
[chromium-blink-merge.git] / third_party / brotli / dec / decode.h
blob9efd34a65306e4d0a28542605668339f5d38ecef
1 /* Copyright 2013 Google Inc. All Rights Reserved.
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
7 http://www.apache.org/licenses/LICENSE-2.0
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
16 /* API for Brotli decompression */
18 #ifndef BROTLI_DEC_DECODE_H_
19 #define BROTLI_DEC_DECODE_H_
21 #include "./state.h"
22 #include "./streams.h"
23 #include "./types.h"
25 #if defined(__cplusplus) || defined(c_plusplus)
26 extern "C" {
27 #endif
29 typedef enum {
30 /* Decoding error, e.g. corrupt input or no memory */
31 BROTLI_RESULT_ERROR = 0,
32 /* Successfully completely done */
33 BROTLI_RESULT_SUCCESS = 1,
34 /* Partially done, but must be called again with more input */
35 BROTLI_RESULT_PARTIAL = 2
36 } BrotliResult;
38 /* Sets *decoded_size to the decompressed size of the given encoded stream. */
39 /* This function only works if the encoded buffer has a single meta block, */
40 /* or if it has two meta-blocks, where the first is uncompressed and the */
41 /* second is empty. */
42 /* Returns 1 on success, 0 on failure. */
43 BrotliResult BrotliDecompressedSize(size_t encoded_size,
44 const uint8_t* encoded_buffer,
45 size_t* decoded_size);
47 /* Decompresses the data in encoded_buffer into decoded_buffer, and sets */
48 /* *decoded_size to the decompressed length. */
49 /* Returns 0 if there was either a bit stream error or memory allocation */
50 /* error, and 1 otherwise. */
51 /* If decoded size is zero, returns 1 and keeps decoded_buffer unchanged. */
52 BrotliResult BrotliDecompressBuffer(size_t encoded_size,
53 const uint8_t* encoded_buffer,
54 size_t* decoded_size,
55 uint8_t* decoded_buffer);
57 /* Same as above, but uses the specified input and output callbacks instead */
58 /* of reading from and writing to pre-allocated memory buffers. */
59 BrotliResult BrotliDecompress(BrotliInput input, BrotliOutput output);
61 /* Same as above, but supports the caller to call the decoder repeatedly with
62 partial data to support streaming. The state must be initialized with
63 BrotliStateInit and reused with every call for the same stream.
64 Return values:
65 0: failure.
66 1: success, and done.
67 2: success so far, end not reached so should call again with more input.
68 The finish parameter is used as follows, for a series of calls with the
69 same state:
70 0: Every call except the last one must be called with finish set to 0. The
71 last call may have finish set to either 0 or 1. Only if finish is 0, can
72 the function return 2. It may also return 0 or 1, in that case no more
73 calls (even with finish 1) may be made.
74 1: Only the last call may have finish set to 1. It's ok to give empty input
75 if all input was already given to previous calls. It is also ok to have
76 only one single call in total, with finish 1, and with all input
77 available immediately. That matches the non-streaming case. If finish is
78 1, the function can only return 0 or 1, never 2. After a finish, no more
79 calls may be done.
80 After everything is done, the state must be cleaned with BrotliStateCleanup
81 to free allocated resources.
82 The given BrotliOutput must always accept all output and make enough space,
83 it returning a smaller value than the amount of bytes to write always results
84 in an error.
86 BrotliResult BrotliDecompressStreaming(BrotliInput input, BrotliOutput output,
87 int finish, BrotliState* s);
89 /* Same as above, but with memory buffers.
90 Must be called with an allocated input buffer in *next_in and an allocated
91 output buffer in *next_out. The values *available_in and *available_out
92 must specify the allocated size in *next_in and *next_out respectively.
93 The value *total_out must be 0 initially, and will be summed with the
94 amount of output bytes written after each call, so that at the end it
95 gives the complete decoded size.
96 After each call, *available_in will be decremented by the amount of input
97 bytes consumed, and the *next_in pointer will be incremented by that amount.
98 Similarly, *available_out will be decremented by the amount of output
99 bytes written, and the *next_out pointer will be incremented by that
100 amount.
102 The input may be partial. With each next function call, *next_in and
103 *available_in must be updated to point to a next part of the compressed
104 input. The current implementation will always consume all input unless
105 an error occurs, so normally *available_in will always be 0 after
106 calling this function and the next adjacent part of input is desired.
108 In the current implementation, the function requires that there is enough
109 output buffer size to write all currently processed input, so
110 *available_out must be large enough. Since the function updates *next_out
111 each time, as long as the output buffer is large enough you can keep
112 reusing this variable. It is also possible to update *next_out and
113 *available_out yourself before a next call, e.g. to point to a new larger
114 buffer.
116 BrotliResult BrotliDecompressBufferStreaming(size_t* available_in,
117 const uint8_t** next_in,
118 int finish,
119 size_t* available_out,
120 uint8_t** next_out,
121 size_t* total_out,
122 BrotliState* s);
124 #if defined(__cplusplus) || defined(c_plusplus)
125 } /* extern "C" */
126 #endif
128 #endif /* BROTLI_DEC_DECODE_H_ */