mirror of
https://github.com/chylex/Brotli-Builder.git
synced 2025-01-09 23:42:50 +01:00
34 lines
1.2 KiB
C#
34 lines
1.2 KiB
C#
using System.Linq;
|
|
using BrotliLib.Brotli;
|
|
using BrotliLib.Brotli.Components;
|
|
using BrotliLib.Brotli.Components.Compressed;
|
|
using BrotliLib.Brotli.Components.Utils;
|
|
using BrotliLib.Brotli.Encode;
|
|
using BrotliLib.Brotli.Encode.Build;
|
|
using BrotliLib.Brotli.Parameters;
|
|
|
|
namespace BrotliImpl.Transformers{
|
|
public class TransformSplitInsertCopyLengths : BrotliTransformerCompressed{
|
|
protected override (MetaBlock, BrotliGlobalState) Transform(MetaBlock.Compressed original, BrotliGlobalState state, BrotliCompressionParameters parameters){
|
|
var builder = new CompressedMetaBlockBuilder(original, state);
|
|
var blockTypes = builder.BlockTypes[Category.InsertCopy];
|
|
|
|
if (blockTypes.Commands.Any()){
|
|
return (original, state);
|
|
}
|
|
|
|
var icCommands = builder.InsertCopyCommands.Count();
|
|
var icSwitchAt = icCommands / 2;
|
|
|
|
if (icCommands <= 1){
|
|
return (original, state);
|
|
}
|
|
|
|
blockTypes.SetInitialLength(icSwitchAt)
|
|
.AddBlockSwitch(new BlockSwitchCommand(1, icCommands - icSwitchAt));
|
|
|
|
return builder.Build(parameters);
|
|
}
|
|
}
|
|
}
|