Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/brotli/c/enc/backward_references.c @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 /* Copyright 2013 Google Inc. All Rights Reserved. | |
| 2 | |
| 3 Distributed under MIT license. | |
| 4 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT | |
| 5 */ | |
| 6 | |
| 7 /* Function to find backward reference copies. */ | |
| 8 | |
| 9 #include "backward_references.h" | |
| 10 | |
| 11 #include <brotli/types.h> | |
| 12 | |
| 13 #include "../common/constants.h" | |
| 14 #include "../common/dictionary.h" | |
| 15 #include "../common/platform.h" | |
| 16 #include "command.h" | |
| 17 #include "compound_dictionary.h" | |
| 18 #include "dictionary_hash.h" | |
| 19 #include "encoder_dict.h" | |
| 20 #include "memory.h" | |
| 21 #include "quality.h" | |
| 22 | |
| 23 #if defined(__cplusplus) || defined(c_plusplus) | |
| 24 extern "C" { | |
| 25 #endif | |
| 26 | |
| 27 static BROTLI_INLINE size_t ComputeDistanceCode(size_t distance, | |
| 28 size_t max_distance, | |
| 29 const int* dist_cache) { | |
| 30 if (distance <= max_distance) { | |
| 31 size_t distance_plus_3 = distance + 3; | |
| 32 size_t offset0 = distance_plus_3 - (size_t)dist_cache[0]; | |
| 33 size_t offset1 = distance_plus_3 - (size_t)dist_cache[1]; | |
| 34 if (distance == (size_t)dist_cache[0]) { | |
| 35 return 0; | |
| 36 } else if (distance == (size_t)dist_cache[1]) { | |
| 37 return 1; | |
| 38 } else if (offset0 < 7) { | |
| 39 return (0x9750468 >> (4 * offset0)) & 0xF; | |
| 40 } else if (offset1 < 7) { | |
| 41 return (0xFDB1ACE >> (4 * offset1)) & 0xF; | |
| 42 } else if (distance == (size_t)dist_cache[2]) { | |
| 43 return 2; | |
| 44 } else if (distance == (size_t)dist_cache[3]) { | |
| 45 return 3; | |
| 46 } | |
| 47 } | |
| 48 return distance + BROTLI_NUM_DISTANCE_SHORT_CODES - 1; | |
| 49 } | |
| 50 | |
| 51 #define EXPAND_CAT(a, b) CAT(a, b) | |
| 52 #define CAT(a, b) a ## b | |
| 53 #define FN(X) EXPAND_CAT(X, HASHER()) | |
| 54 #define EXPORT_FN(X) EXPAND_CAT(X, EXPAND_CAT(PREFIX(), HASHER())) | |
| 55 | |
| 56 #define PREFIX() N | |
| 57 #define ENABLE_COMPOUND_DICTIONARY 0 | |
| 58 | |
| 59 #define HASHER() H2 | |
| 60 /* NOLINTNEXTLINE(build/include) */ | |
| 61 #include "backward_references_inc.h" | |
| 62 #undef HASHER | |
| 63 | |
| 64 #define HASHER() H3 | |
| 65 /* NOLINTNEXTLINE(build/include) */ | |
| 66 #include "backward_references_inc.h" | |
| 67 #undef HASHER | |
| 68 | |
| 69 #define HASHER() H4 | |
| 70 /* NOLINTNEXTLINE(build/include) */ | |
| 71 #include "backward_references_inc.h" | |
| 72 #undef HASHER | |
| 73 | |
| 74 #define HASHER() H5 | |
| 75 /* NOLINTNEXTLINE(build/include) */ | |
| 76 #include "backward_references_inc.h" | |
| 77 #undef HASHER | |
| 78 | |
| 79 #define HASHER() H6 | |
| 80 /* NOLINTNEXTLINE(build/include) */ | |
| 81 #include "backward_references_inc.h" | |
| 82 #undef HASHER | |
| 83 | |
| 84 #define HASHER() H40 | |
| 85 /* NOLINTNEXTLINE(build/include) */ | |
| 86 #include "backward_references_inc.h" | |
| 87 #undef HASHER | |
| 88 | |
| 89 #define HASHER() H41 | |
| 90 /* NOLINTNEXTLINE(build/include) */ | |
| 91 #include "backward_references_inc.h" | |
| 92 #undef HASHER | |
| 93 | |
| 94 #define HASHER() H42 | |
| 95 /* NOLINTNEXTLINE(build/include) */ | |
| 96 #include "backward_references_inc.h" | |
| 97 #undef HASHER | |
| 98 | |
| 99 #define HASHER() H54 | |
| 100 /* NOLINTNEXTLINE(build/include) */ | |
| 101 #include "backward_references_inc.h" | |
| 102 #undef HASHER | |
| 103 | |
| 104 #define HASHER() H35 | |
| 105 /* NOLINTNEXTLINE(build/include) */ | |
| 106 #include "backward_references_inc.h" | |
| 107 #undef HASHER | |
| 108 | |
| 109 #define HASHER() H55 | |
| 110 /* NOLINTNEXTLINE(build/include) */ | |
| 111 #include "backward_references_inc.h" | |
| 112 #undef HASHER | |
| 113 | |
| 114 #define HASHER() H65 | |
| 115 /* NOLINTNEXTLINE(build/include) */ | |
| 116 #include "backward_references_inc.h" | |
| 117 #undef HASHER | |
| 118 | |
| 119 #if defined(BROTLI_MAX_SIMD_QUALITY) | |
| 120 #define HASHER() H58 | |
| 121 /* NOLINTNEXTLINE(build/include) */ | |
| 122 #include "backward_references_inc.h" | |
| 123 #undef HASHER | |
| 124 | |
| 125 #define HASHER() H68 | |
| 126 /* NOLINTNEXTLINE(build/include) */ | |
| 127 #include "backward_references_inc.h" | |
| 128 #undef HASHER | |
| 129 #endif | |
| 130 | |
| 131 #undef ENABLE_COMPOUND_DICTIONARY | |
| 132 #undef PREFIX | |
| 133 #define PREFIX() D | |
| 134 #define ENABLE_COMPOUND_DICTIONARY 1 | |
| 135 | |
| 136 #define HASHER() H5 | |
| 137 /* NOLINTNEXTLINE(build/include) */ | |
| 138 #include "backward_references_inc.h" | |
| 139 #undef HASHER | |
| 140 #define HASHER() H6 | |
| 141 /* NOLINTNEXTLINE(build/include) */ | |
| 142 #include "backward_references_inc.h" | |
| 143 #undef HASHER | |
| 144 #define HASHER() H40 | |
| 145 /* NOLINTNEXTLINE(build/include) */ | |
| 146 #include "backward_references_inc.h" | |
| 147 #undef HASHER | |
| 148 #define HASHER() H41 | |
| 149 /* NOLINTNEXTLINE(build/include) */ | |
| 150 #include "backward_references_inc.h" | |
| 151 #undef HASHER | |
| 152 #define HASHER() H42 | |
| 153 /* NOLINTNEXTLINE(build/include) */ | |
| 154 #include "backward_references_inc.h" | |
| 155 #undef HASHER | |
| 156 #define HASHER() H55 | |
| 157 /* NOLINTNEXTLINE(build/include) */ | |
| 158 #include "backward_references_inc.h" | |
| 159 #undef HASHER | |
| 160 #define HASHER() H65 | |
| 161 /* NOLINTNEXTLINE(build/include) */ | |
| 162 #include "backward_references_inc.h" | |
| 163 #undef HASHER | |
| 164 #if defined(BROTLI_MAX_SIMD_QUALITY) | |
| 165 #define HASHER() H58 | |
| 166 /* NOLINTNEXTLINE(build/include) */ | |
| 167 #include "backward_references_inc.h" | |
| 168 #undef HASHER | |
| 169 #define HASHER() H68 | |
| 170 /* NOLINTNEXTLINE(build/include) */ | |
| 171 #include "backward_references_inc.h" | |
| 172 #undef HASHER | |
| 173 #endif | |
| 174 | |
| 175 #undef ENABLE_COMPOUND_DICTIONARY | |
| 176 #undef PREFIX | |
| 177 | |
| 178 #undef EXPORT_FN | |
| 179 #undef FN | |
| 180 #undef CAT | |
| 181 #undef EXPAND_CAT | |
| 182 | |
| 183 void BrotliCreateBackwardReferences(size_t num_bytes, | |
| 184 size_t position, const uint8_t* ringbuffer, size_t ringbuffer_mask, | |
| 185 ContextLut literal_context_lut, const BrotliEncoderParams* params, | |
| 186 Hasher* hasher, int* dist_cache, size_t* last_insert_len, | |
| 187 Command* commands, size_t* num_commands, size_t* num_literals) { | |
| 188 if (params->dictionary.compound.num_chunks != 0) { | |
| 189 switch (params->hasher.type) { | |
| 190 #define CASE_(N) \ | |
| 191 case N: \ | |
| 192 CreateBackwardReferencesDH ## N(num_bytes, \ | |
| 193 position, ringbuffer, ringbuffer_mask, \ | |
| 194 literal_context_lut, params, hasher, dist_cache, \ | |
| 195 last_insert_len, commands, num_commands, num_literals); \ | |
| 196 return; | |
| 197 CASE_(5) | |
| 198 CASE_(6) | |
| 199 #if defined(BROTLI_MAX_SIMD_QUALITY) | |
| 200 CASE_(58) | |
| 201 CASE_(68) | |
| 202 #endif | |
| 203 CASE_(40) | |
| 204 CASE_(41) | |
| 205 CASE_(42) | |
| 206 CASE_(55) | |
| 207 CASE_(65) | |
| 208 #undef CASE_ | |
| 209 default: | |
| 210 BROTLI_DCHECK(false); | |
| 211 break; | |
| 212 } | |
| 213 } | |
| 214 | |
| 215 switch (params->hasher.type) { | |
| 216 #define CASE_(N) \ | |
| 217 case N: \ | |
| 218 CreateBackwardReferencesNH ## N(num_bytes, \ | |
| 219 position, ringbuffer, ringbuffer_mask, \ | |
| 220 literal_context_lut, params, hasher, dist_cache, \ | |
| 221 last_insert_len, commands, num_commands, num_literals); \ | |
| 222 return; | |
| 223 FOR_GENERIC_HASHERS(CASE_) | |
| 224 #undef CASE_ | |
| 225 default: | |
| 226 BROTLI_DCHECK(false); | |
| 227 break; | |
| 228 } | |
| 229 } | |
| 230 | |
| 231 #if defined(__cplusplus) || defined(c_plusplus) | |
| 232 } /* extern "C" */ | |
| 233 #endif |
