compress_fragment.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* Copyright 2015 Google Inc. All Rights Reserved.
  2. Distributed under MIT license.
  3. See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
  4. */
  5. /* Function for fast encoding of an input fragment, independently from the input
  6. history. This function uses one-pass processing: when we find a backward
  7. match, we immediately emit the corresponding command and literal codes to
  8. the bit stream. */
  9. #ifndef BROTLI_ENC_COMPRESS_FRAGMENT_H_
  10. #define BROTLI_ENC_COMPRESS_FRAGMENT_H_
  11. #include <brotli/types.h>
  12. #include "../common/constants.h"
  13. #include "../common/platform.h"
  14. #include "entropy_encode.h"
  15. #if defined(__cplusplus) || defined(c_plusplus)
  16. extern "C" {
  17. #endif
  18. typedef struct BrotliOnePassArena {
  19. uint8_t lit_depth[256];
  20. uint16_t lit_bits[256];
  21. /* Command and distance prefix codes (each 64 symbols, stored back-to-back)
  22. used for the next block. The command prefix code is over a smaller alphabet
  23. with the following 64 symbols:
  24. 0 - 15: insert length code 0, copy length code 0 - 15, same distance
  25. 16 - 39: insert length code 0, copy length code 0 - 23
  26. 40 - 63: insert length code 0 - 23, copy length code 0
  27. Note that symbols 16 and 40 represent the same code in the full alphabet,
  28. but we do not use either of them. */
  29. uint8_t cmd_depth[128];
  30. uint16_t cmd_bits[128];
  31. uint32_t cmd_histo[128];
  32. /* The compressed form of the command and distance prefix codes for the next
  33. block. */
  34. uint8_t cmd_code[512];
  35. size_t cmd_code_numbits;
  36. HuffmanTree tree[2 * BROTLI_NUM_LITERAL_SYMBOLS + 1];
  37. uint32_t histogram[256];
  38. uint8_t tmp_depth[BROTLI_NUM_COMMAND_SYMBOLS];
  39. uint16_t tmp_bits[64];
  40. } BrotliOnePassArena;
  41. /* Compresses "input" string to the "*storage" buffer as one or more complete
  42. meta-blocks, and updates the "*storage_ix" bit position.
  43. If "is_last" is 1, emits an additional empty last meta-block.
  44. "cmd_depth" and "cmd_bits" contain the command and distance prefix codes
  45. (see comment in encode.h) used for the encoding of this input fragment.
  46. If "is_last" is 0, they are updated to reflect the statistics
  47. of this input fragment, to be used for the encoding of the next fragment.
  48. "*cmd_code_numbits" is the number of bits of the compressed representation
  49. of the command and distance prefix codes, and "cmd_code" is an array of
  50. at least "(*cmd_code_numbits + 7) >> 3" size that contains the compressed
  51. command and distance prefix codes. If "is_last" is 0, these are also
  52. updated to represent the updated "cmd_depth" and "cmd_bits".
  53. REQUIRES: "input_size" is greater than zero, or "is_last" is 1.
  54. REQUIRES: "input_size" is less or equal to maximal metablock size (1 << 24).
  55. REQUIRES: All elements in "table[0..table_size-1]" are initialized to zero.
  56. REQUIRES: "table_size" is an odd (9, 11, 13, 15) power of two
  57. OUTPUT: maximal copy distance <= |input_size|
  58. OUTPUT: maximal copy distance <= BROTLI_MAX_BACKWARD_LIMIT(18) */
  59. BROTLI_INTERNAL void BrotliCompressFragmentFast(BrotliOnePassArena* s,
  60. const uint8_t* input,
  61. size_t input_size,
  62. BROTLI_BOOL is_last,
  63. int* table, size_t table_size,
  64. size_t* storage_ix,
  65. uint8_t* storage);
  66. #if defined(__cplusplus) || defined(c_plusplus)
  67. } /* extern "C" */
  68. #endif
  69. #endif /* BROTLI_ENC_COMPRESS_FRAGMENT_H_ */