backward_references_hq.h 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* Copyright 2013 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 to find backward reference copies. */
  6. #ifndef BROTLI_ENC_BACKWARD_REFERENCES_HQ_H_
  7. #define BROTLI_ENC_BACKWARD_REFERENCES_HQ_H_
  8. #include "../common/constants.h"
  9. #include "../common/dictionary.h"
  10. #include "../common/platform.h"
  11. #include <brotli/types.h>
  12. #include "./command.h"
  13. #include "./hash.h"
  14. #include "./memory.h"
  15. #include "./quality.h"
  16. #if defined(__cplusplus) || defined(c_plusplus)
  17. extern "C" {
  18. #endif
  19. BROTLI_INTERNAL void BrotliCreateZopfliBackwardReferences(MemoryManager* m,
  20. size_t num_bytes, size_t position, const uint8_t* ringbuffer,
  21. size_t ringbuffer_mask, const BrotliEncoderParams* params,
  22. HasherHandle hasher, int* dist_cache, size_t* last_insert_len,
  23. Command* commands, size_t* num_commands, size_t* num_literals);
  24. BROTLI_INTERNAL void BrotliCreateHqZopfliBackwardReferences(MemoryManager* m,
  25. size_t num_bytes, size_t position, const uint8_t* ringbuffer,
  26. size_t ringbuffer_mask, const BrotliEncoderParams* params,
  27. HasherHandle hasher, int* dist_cache, size_t* last_insert_len,
  28. Command* commands, size_t* num_commands, size_t* num_literals);
  29. typedef struct ZopfliNode {
  30. /* Best length to get up to this byte (not including this byte itself)
  31. highest 7 bit is used to reconstruct the length code. */
  32. uint32_t length;
  33. /* Distance associated with the length. */
  34. uint32_t distance;
  35. /* Number of literal inserts before this copy; highest 5 bits contain
  36. distance short code + 1 (or zero if no short code). */
  37. uint32_t dcode_insert_length;
  38. /* This union holds information used by dynamic-programming. During forward
  39. pass |cost| it used to store the goal function. When node is processed its
  40. |cost| is invalidated in favor of |shortcut|. On path back-tracing pass
  41. |next| is assigned the offset to next node on the path. */
  42. union {
  43. /* Smallest cost to get to this byte from the beginning, as found so far. */
  44. float cost;
  45. /* Offset to the next node on the path. Equals to command_length() of the
  46. next node on the path. For last node equals to BROTLI_UINT32_MAX */
  47. uint32_t next;
  48. /* Node position that provides next distance for distance cache. */
  49. uint32_t shortcut;
  50. } u;
  51. } ZopfliNode;
  52. BROTLI_INTERNAL void BrotliInitZopfliNodes(ZopfliNode* array, size_t length);
  53. /* Computes the shortest path of commands from position to at most
  54. position + num_bytes.
  55. On return, path->size() is the number of commands found and path[i] is the
  56. length of the i-th command (copy length plus insert length).
  57. Note that the sum of the lengths of all commands can be less than num_bytes.
  58. On return, the nodes[0..num_bytes] array will have the following
  59. "ZopfliNode array invariant":
  60. For each i in [1..num_bytes], if nodes[i].cost < kInfinity, then
  61. (1) nodes[i].copy_length() >= 2
  62. (2) nodes[i].command_length() <= i and
  63. (3) nodes[i - nodes[i].command_length()].cost < kInfinity */
  64. BROTLI_INTERNAL size_t BrotliZopfliComputeShortestPath(
  65. MemoryManager* m, size_t num_bytes,
  66. size_t position, const uint8_t* ringbuffer, size_t ringbuffer_mask,
  67. const BrotliEncoderParams* params,
  68. const int* dist_cache, HasherHandle hasher, ZopfliNode* nodes);
  69. BROTLI_INTERNAL void BrotliZopfliCreateCommands(
  70. const size_t num_bytes, const size_t block_start, const ZopfliNode* nodes,
  71. int* dist_cache, size_t* last_insert_len, const BrotliEncoderParams* params,
  72. Command* commands, size_t* num_literals);
  73. #if defined(__cplusplus) || defined(c_plusplus)
  74. } /* extern "C" */
  75. #endif
  76. #endif /* BROTLI_ENC_BACKWARD_REFERENCES_HQ_H_ */