diff options
author | Norbert Preining <norbert@preining.info> | 2023-11-16 03:01:15 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2023-11-16 03:01:15 +0000 |
commit | e0db3f0709a737e7258fd40a7cbfe9a461ea0756 (patch) | |
tree | e81cfc35b6602ffceefa73b8971ce3b94312820a /dviware/dvisvgm/libs/brotli/enc/block_splitter.c | |
parent | f5460c92605f1b3b17448b27ce53375157c3e4b1 (diff) |
CTAN sync 202311160301
Diffstat (limited to 'dviware/dvisvgm/libs/brotli/enc/block_splitter.c')
-rw-r--r-- | dviware/dvisvgm/libs/brotli/enc/block_splitter.c | 51 |
1 files changed, 37 insertions, 14 deletions
diff --git a/dviware/dvisvgm/libs/brotli/enc/block_splitter.c b/dviware/dvisvgm/libs/brotli/enc/block_splitter.c index deb7c2e151..eba1b691e5 100644 --- a/dviware/dvisvgm/libs/brotli/enc/block_splitter.c +++ b/dviware/dvisvgm/libs/brotli/enc/block_splitter.c @@ -6,18 +6,18 @@ /* Block split point selection utilities. */ -#include "./block_splitter.h" +#include "block_splitter.h" #include <string.h> /* memcpy, memset */ #include "../common/platform.h" -#include "./bit_cost.h" -#include "./cluster.h" -#include "./command.h" -#include "./fast_log.h" -#include "./histogram.h" -#include "./memory.h" -#include "./quality.h" +#include "bit_cost.h" +#include "cluster.h" +#include "command.h" +#include "fast_log.h" +#include "histogram.h" +#include "memory.h" +#include "quality.h" #if defined(__cplusplus) || defined(c_plusplus) extern "C" { @@ -30,6 +30,7 @@ static const double kCommandBlockSwitchCost = 13.5; static const double kDistanceBlockSwitchCost = 14.6; static const size_t kLiteralStrideLength = 70; static const size_t kCommandStrideLength = 40; +static const size_t kDistanceStrideLength = 40; static const size_t kSymbolsPerLiteralHistogram = 544; static const size_t kSymbolsPerCommandHistogram = 530; static const size_t kSymbolsPerDistanceHistogram = 544; @@ -89,19 +90,19 @@ static BROTLI_INLINE double BitCost(size_t count) { #define FN(X) X ## Literal #define DataType uint8_t /* NOLINTNEXTLINE(build/include) */ -#include "./block_splitter_inc.h" +#include "block_splitter_inc.h" #undef DataType #undef FN #define FN(X) X ## Command #define DataType uint16_t /* NOLINTNEXTLINE(build/include) */ -#include "./block_splitter_inc.h" +#include "block_splitter_inc.h" #undef FN #define FN(X) X ## Distance /* NOLINTNEXTLINE(build/include) */ -#include "./block_splitter_inc.h" +#include "block_splitter_inc.h" #undef DataType #undef FN @@ -119,6 +120,8 @@ void BrotliDestroyBlockSplit(MemoryManager* m, BlockSplit* self) { BROTLI_FREE(m, self->lengths); } +/* Extracts literals, command distance and prefix codes, then applies + * SplitByteVector to create partitioning. */ void BrotliSplitBlock(MemoryManager* m, const Command* cmds, const size_t num_commands, @@ -136,7 +139,9 @@ void BrotliSplitBlock(MemoryManager* m, /* Create a continuous array of literals. */ CopyLiteralsToByteArray(cmds, num_commands, data, pos, mask, literals); /* Create the block split on the array of literals. - Literal histograms have alphabet size 256. */ + * Literal histograms can have alphabet size up to 256. + * Though, to accomodate context modeling, less than half of maximum size + * is allowed. */ SplitByteVectorLiteral( m, literals, literals_count, kSymbolsPerLiteralHistogram, kMaxLiteralHistograms, @@ -144,6 +149,10 @@ void BrotliSplitBlock(MemoryManager* m, literal_split); if (BROTLI_IS_OOM(m)) return; BROTLI_FREE(m, literals); + /* NB: this might be a good place for injecting extra splitting without + * increasing encoder complexity; however, output parition would be less + * optimal than one produced with forced splitting inside + * SplitByteVector (FindBlocks / ClusterBlocks). */ } { @@ -161,7 +170,7 @@ void BrotliSplitBlock(MemoryManager* m, kCommandStrideLength, kCommandBlockSwitchCost, params, insert_and_copy_split); if (BROTLI_IS_OOM(m)) return; - /* TODO: reuse for distances? */ + /* TODO(eustas): reuse for distances? */ BROTLI_FREE(m, insert_and_copy_codes); } @@ -181,13 +190,27 @@ void BrotliSplitBlock(MemoryManager* m, SplitByteVectorDistance( m, distance_prefixes, j, kSymbolsPerDistanceHistogram, kMaxCommandHistograms, - kCommandStrideLength, kDistanceBlockSwitchCost, params, + kDistanceStrideLength, kDistanceBlockSwitchCost, params, dist_split); if (BROTLI_IS_OOM(m)) return; BROTLI_FREE(m, distance_prefixes); } } +#if defined(BROTLI_TEST) +size_t CountLiteralsForTest(const Command*, const size_t); +size_t CountLiteralsForTest(const Command* cmds, const size_t num_commands) { + return CountLiterals(cmds, num_commands); +} + +void CopyLiteralsToByteArrayForTest(const Command*, + const size_t, const uint8_t*, const size_t, const size_t, uint8_t*); +void CopyLiteralsToByteArrayForTest(const Command* cmds, + const size_t num_commands, const uint8_t* data, const size_t offset, + const size_t mask, uint8_t* literals) { + CopyLiteralsToByteArray(cmds, num_commands, data, offset, mask, literals); +} +#endif #if defined(__cplusplus) || defined(c_plusplus) } /* extern "C" */ |