xref: /aosp_15_r20/external/brotli/c/enc/compress_fragment.h (revision f4ee7fba7774faf2a30f13154332c0a06550dbc4)
1*f4ee7fbaSAndroid Build Coastguard Worker /* Copyright 2015 Google Inc. All Rights Reserved.
2*f4ee7fbaSAndroid Build Coastguard Worker 
3*f4ee7fbaSAndroid Build Coastguard Worker    Distributed under MIT license.
4*f4ee7fbaSAndroid Build Coastguard Worker    See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5*f4ee7fbaSAndroid Build Coastguard Worker */
6*f4ee7fbaSAndroid Build Coastguard Worker 
7*f4ee7fbaSAndroid Build Coastguard Worker /* Function for fast encoding of an input fragment, independently from the input
8*f4ee7fbaSAndroid Build Coastguard Worker    history. This function uses one-pass processing: when we find a backward
9*f4ee7fbaSAndroid Build Coastguard Worker    match, we immediately emit the corresponding command and literal codes to
10*f4ee7fbaSAndroid Build Coastguard Worker    the bit stream. */
11*f4ee7fbaSAndroid Build Coastguard Worker 
12*f4ee7fbaSAndroid Build Coastguard Worker #ifndef BROTLI_ENC_COMPRESS_FRAGMENT_H_
13*f4ee7fbaSAndroid Build Coastguard Worker #define BROTLI_ENC_COMPRESS_FRAGMENT_H_
14*f4ee7fbaSAndroid Build Coastguard Worker 
15*f4ee7fbaSAndroid Build Coastguard Worker #include "../common/platform.h"
16*f4ee7fbaSAndroid Build Coastguard Worker #include <brotli/types.h>
17*f4ee7fbaSAndroid Build Coastguard Worker #include "./memory.h"
18*f4ee7fbaSAndroid Build Coastguard Worker 
19*f4ee7fbaSAndroid Build Coastguard Worker #if defined(__cplusplus) || defined(c_plusplus)
20*f4ee7fbaSAndroid Build Coastguard Worker extern "C" {
21*f4ee7fbaSAndroid Build Coastguard Worker #endif
22*f4ee7fbaSAndroid Build Coastguard Worker 
23*f4ee7fbaSAndroid Build Coastguard Worker /* Compresses "input" string to the "*storage" buffer as one or more complete
24*f4ee7fbaSAndroid Build Coastguard Worker    meta-blocks, and updates the "*storage_ix" bit position.
25*f4ee7fbaSAndroid Build Coastguard Worker 
26*f4ee7fbaSAndroid Build Coastguard Worker    If "is_last" is 1, emits an additional empty last meta-block.
27*f4ee7fbaSAndroid Build Coastguard Worker 
28*f4ee7fbaSAndroid Build Coastguard Worker    "cmd_depth" and "cmd_bits" contain the command and distance prefix codes
29*f4ee7fbaSAndroid Build Coastguard Worker    (see comment in encode.h) used for the encoding of this input fragment.
30*f4ee7fbaSAndroid Build Coastguard Worker    If "is_last" is 0, they are updated to reflect the statistics
31*f4ee7fbaSAndroid Build Coastguard Worker    of this input fragment, to be used for the encoding of the next fragment.
32*f4ee7fbaSAndroid Build Coastguard Worker 
33*f4ee7fbaSAndroid Build Coastguard Worker    "*cmd_code_numbits" is the number of bits of the compressed representation
34*f4ee7fbaSAndroid Build Coastguard Worker    of the command and distance prefix codes, and "cmd_code" is an array of
35*f4ee7fbaSAndroid Build Coastguard Worker    at least "(*cmd_code_numbits + 7) >> 3" size that contains the compressed
36*f4ee7fbaSAndroid Build Coastguard Worker    command and distance prefix codes. If "is_last" is 0, these are also
37*f4ee7fbaSAndroid Build Coastguard Worker    updated to represent the updated "cmd_depth" and "cmd_bits".
38*f4ee7fbaSAndroid Build Coastguard Worker 
39*f4ee7fbaSAndroid Build Coastguard Worker    REQUIRES: "input_size" is greater than zero, or "is_last" is 1.
40*f4ee7fbaSAndroid Build Coastguard Worker    REQUIRES: "input_size" is less or equal to maximal metablock size (1 << 24).
41*f4ee7fbaSAndroid Build Coastguard Worker    REQUIRES: All elements in "table[0..table_size-1]" are initialized to zero.
42*f4ee7fbaSAndroid Build Coastguard Worker    REQUIRES: "table_size" is an odd (9, 11, 13, 15) power of two
43*f4ee7fbaSAndroid Build Coastguard Worker    OUTPUT: maximal copy distance <= |input_size|
44*f4ee7fbaSAndroid Build Coastguard Worker    OUTPUT: maximal copy distance <= BROTLI_MAX_BACKWARD_LIMIT(18) */
45*f4ee7fbaSAndroid Build Coastguard Worker BROTLI_INTERNAL void BrotliCompressFragmentFast(MemoryManager* m,
46*f4ee7fbaSAndroid Build Coastguard Worker                                                 const uint8_t* input,
47*f4ee7fbaSAndroid Build Coastguard Worker                                                 size_t input_size,
48*f4ee7fbaSAndroid Build Coastguard Worker                                                 BROTLI_BOOL is_last,
49*f4ee7fbaSAndroid Build Coastguard Worker                                                 int* table, size_t table_size,
50*f4ee7fbaSAndroid Build Coastguard Worker                                                 uint8_t cmd_depth[128],
51*f4ee7fbaSAndroid Build Coastguard Worker                                                 uint16_t cmd_bits[128],
52*f4ee7fbaSAndroid Build Coastguard Worker                                                 size_t* cmd_code_numbits,
53*f4ee7fbaSAndroid Build Coastguard Worker                                                 uint8_t* cmd_code,
54*f4ee7fbaSAndroid Build Coastguard Worker                                                 size_t* storage_ix,
55*f4ee7fbaSAndroid Build Coastguard Worker                                                 uint8_t* storage);
56*f4ee7fbaSAndroid Build Coastguard Worker 
57*f4ee7fbaSAndroid Build Coastguard Worker #if defined(__cplusplus) || defined(c_plusplus)
58*f4ee7fbaSAndroid Build Coastguard Worker }  /* extern "C" */
59*f4ee7fbaSAndroid Build Coastguard Worker #endif
60*f4ee7fbaSAndroid Build Coastguard Worker 
61*f4ee7fbaSAndroid Build Coastguard Worker #endif  /* BROTLI_ENC_COMPRESS_FRAGMENT_H_ */
62