summaryrefslogtreecommitdiff
path: root/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/block_splitter.c
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2024-01-16 18:32:08 +0000
committerKarl Berry <karl@freefriends.org>2024-01-16 18:32:08 +0000
commit84b532c711d3e644d6ba05e8118356310fd68fbf (patch)
tree33d34c031bb6342b29a3801d2cc1f9208f637920 /Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/block_splitter.c
parent32d816973b284f3e5a0bd28a7ad5ef73e3102b34 (diff)
dvisvgm 3.2
git-svn-id: svn://tug.org/texlive/trunk@69453 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/block_splitter.c')
-rw-r--r--Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/block_splitter.c51
1 files changed, 37 insertions, 14 deletions
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/block_splitter.c b/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/block_splitter.c
index deb7c2e151a..eba1b691e51 100644
--- a/Build/source/texk/dvisvgm/dvisvgm-src/libs/brotli/enc/block_splitter.c
+++ b/Build/source/texk/dvisvgm/dvisvgm-src/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" */