transform.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* transforms is a part of ABI, but not API.
  2. It means that there are some functions that are supposed to be in "common"
  3. library, but header itself is not placed into include/brotli. This way,
  4. aforementioned functions will be available only to brotli internals.
  5. */
  6. #ifndef BROTLI_COMMON_TRANSFORM_H_
  7. #define BROTLI_COMMON_TRANSFORM_H_
  8. #include <brotli/port.h>
  9. #include <brotli/types.h>
  10. #if defined(__cplusplus) || defined(c_plusplus)
  11. extern "C" {
  12. #endif
  13. enum BrotliWordTransformType {
  14. BROTLI_TRANSFORM_IDENTITY = 0,
  15. BROTLI_TRANSFORM_OMIT_LAST_1 = 1,
  16. BROTLI_TRANSFORM_OMIT_LAST_2 = 2,
  17. BROTLI_TRANSFORM_OMIT_LAST_3 = 3,
  18. BROTLI_TRANSFORM_OMIT_LAST_4 = 4,
  19. BROTLI_TRANSFORM_OMIT_LAST_5 = 5,
  20. BROTLI_TRANSFORM_OMIT_LAST_6 = 6,
  21. BROTLI_TRANSFORM_OMIT_LAST_7 = 7,
  22. BROTLI_TRANSFORM_OMIT_LAST_8 = 8,
  23. BROTLI_TRANSFORM_OMIT_LAST_9 = 9,
  24. BROTLI_TRANSFORM_UPPERCASE_FIRST = 10,
  25. BROTLI_TRANSFORM_UPPERCASE_ALL = 11,
  26. BROTLI_TRANSFORM_OMIT_FIRST_1 = 12,
  27. BROTLI_TRANSFORM_OMIT_FIRST_2 = 13,
  28. BROTLI_TRANSFORM_OMIT_FIRST_3 = 14,
  29. BROTLI_TRANSFORM_OMIT_FIRST_4 = 15,
  30. BROTLI_TRANSFORM_OMIT_FIRST_5 = 16,
  31. BROTLI_TRANSFORM_OMIT_FIRST_6 = 17,
  32. BROTLI_TRANSFORM_OMIT_FIRST_7 = 18,
  33. BROTLI_TRANSFORM_OMIT_FIRST_8 = 19,
  34. BROTLI_TRANSFORM_OMIT_FIRST_9 = 20,
  35. BROTLI_NUM_TRANSFORM_TYPES /* Counts transforms, not a transform itself. */
  36. };
  37. #define BROTLI_TRANSFORMS_MAX_CUT_OFF BROTLI_TRANSFORM_OMIT_LAST_9
  38. typedef struct BrotliTransforms {
  39. uint16_t prefix_suffix_size;
  40. /* Last character must be null, so prefix_suffix_size must be at least 1. */
  41. const uint8_t* prefix_suffix;
  42. const uint16_t* prefix_suffix_map;
  43. uint32_t num_transforms;
  44. /* Each entry is a [prefix_id, transform, suffix_id] triplet. */
  45. const uint8_t* transforms;
  46. /* Indices of transforms like ["", BROTLI_TRANSFORM_OMIT_LAST_#, ""].
  47. 0-th element corresponds to ["", BROTLI_TRANSFORM_IDENTITY, ""].
  48. -1, if cut-off transform does not exist. */
  49. int16_t cutOffTransforms[BROTLI_TRANSFORMS_MAX_CUT_OFF + 1];
  50. } BrotliTransforms;
  51. /* T is BrotliTransforms*; result is uint8_t. */
  52. #define BROTLI_TRANSFORM_PREFIX_ID(T, I) ((T)->transforms[((I) * 3) + 0])
  53. #define BROTLI_TRANSFORM_TYPE(T, I) ((T)->transforms[((I) * 3) + 1])
  54. #define BROTLI_TRANSFORM_SUFFIX_ID(T, I) ((T)->transforms[((I) * 3) + 2])
  55. /* T is BrotliTransforms*; result is const uint8_t*. */
  56. #define BROTLI_TRANSFORM_PREFIX(T, I) (&(T)->prefix_suffix[ \
  57. (T)->prefix_suffix_map[BROTLI_TRANSFORM_PREFIX_ID(T, I)]])
  58. #define BROTLI_TRANSFORM_SUFFIX(T, I) (&(T)->prefix_suffix[ \
  59. (T)->prefix_suffix_map[BROTLI_TRANSFORM_SUFFIX_ID(T, I)]])
  60. BROTLI_COMMON_API const BrotliTransforms* BrotliGetTransforms(void);
  61. BROTLI_COMMON_API int BrotliTransformDictionaryWord(
  62. uint8_t* dst, const uint8_t* word, int len,
  63. const BrotliTransforms* transforms, int transform_idx);
  64. #if defined(__cplusplus) || defined(c_plusplus)
  65. } /* extern "C" */
  66. #endif
  67. #endif /* BROTLI_COMMON_TRANSFORM_H_ */