/// <summary> /// Readjusts the numbers so that they are easier to compress. Loses some precision (of course) /// </summary> /// <param name="numbers"></param> /// <param name="config"></param> public static void Round([NotNull] List <OfcNumber> numbers, [NotNull] IConfiguaration config) { if (numbers.Count < 2) { return; } if (!config.Has("RoundingMin") || !config.Has("RoundingMax") || !config.Has("RoundingEpsilon")) { throw new ArgumentException("Invalid config numbers (Rounding)"); } var min = config.Get <double>("RoundingMin"); var max = config.Get <double>("RoundingMax"); if (min >= max) { throw new ArgumentException("Invalid config numbers"); } var minOfc = OfcNumber.Parse(min.ToString(CultureInfo.InvariantCulture)); var maxOfc = OfcNumber.Parse(max.ToString(CultureInfo.InvariantCulture)); var epsilon = config.Get <double>("RoundingEpsilon"); var epsilonTwice = epsilon * 2d; var epsilonOfc = OfcNumber.Parse(epsilon.ToString(CultureInfo.InvariantCulture)); var currentStart = 0; var currentMin = numbers[0].Reconstructed; var currentMax = currentMin; var currentMaxOfc = numbers[0]; for (var i = 1; i < numbers.Count; i++) { var number = numbers[i]; var numberRec = number.Reconstructed; if (numberRec < min) { numbers[i] = minOfc; } else if (numberRec > max) { numbers[i] = maxOfc; } if (numberRec > currentMax) { currentMax = numberRec; if (numberRec - currentMin > epsilonTwice) { if (currentStart != i - 1) { AdjustNumbers(numbers, currentStart, i, currentMaxOfc, epsilonOfc); } currentStart = i; currentMin = numberRec; currentMaxOfc = number; } } if (numberRec < currentMin) { currentMin = numberRec; if (currentMax - numberRec > epsilonTwice) { if (currentStart != i - 1) { AdjustNumbers(numbers, currentStart, i, currentMaxOfc, epsilonOfc); } currentStart = i; currentMax = numberRec; currentMaxOfc = number; } } } //using (var writer = new StreamWriter(new FileStream(new Random().Next(0, 100) + "raw123.txt", FileMode.OpenOrCreate))) //{ // for (var i = 0; i < numbers.Count; i++) // { // writer.WriteLine(numbers[i].Reconstructed); // } //} }
public CompressAction(IAlgorithm <TAlgorithm> algorithm, IConverter <TAlgorithm> converter, IConfiguaration config, string basePath, string sourcePath, string dataPath, string metaPath, string lzmaPath) { _algorithm = algorithm; _converter = converter; _sourcePath = sourcePath; _dataPath = dataPath; _metaPath = metaPath; _lzmaPath = lzmaPath; _relativePath = basePath != null && _sourcePath.StartsWith(basePath) ? _sourcePath.Substring(basePath.Length) : _sourcePath; _configuaration = config; }
public static void AddDecompressDirectoryActionWithAlgorithm(this OfcActionManager manager, [CanBeNull] string algorithmName, IConfiguaration configuaration, string baseInputDirectory, string baseOutputDirectory, bool recursive) { var container = GetDataFromName(algorithmName); var algorithm = container.Creator(configuaration); var converter = container.Converter; var type = typeof(ActionUtils); var method = type.GetMethod(nameof(ActionUtils.AddDecompressDirectoryAction), BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static); if (method == null) { throw new InvalidOperationException("Could not link to the internal method"); } var genericMethod = method.MakeGenericMethod(container.AlgorithmType); genericMethod.Invoke(null, new object[] { manager, algorithm, converter, configuaration, baseInputDirectory, baseOutputDirectory, recursive }); }
public AlgorithmHookOfcNumber(IAlgorithm <OfcNumber> algorithm, Stream output, IConfiguaration config) { _algorithm = algorithm; _output = output; _config = config; }
public ZettyAlgorithm(IConfiguaration config) { _config = config; }
public IReporter <string> Compress(IFile target, IConfiguaration configuaration, Stream output, int width, int height) { return(new ZettyCompression(output)); }
public void Decompress(IFile target, IConfiguaration configuaration, Stream input, IReporter <string> reporter, int width) { _next.Decompress(target, configuaration, input, reporter, width); }
public AlgorithmHookDouble(IAlgorithm <double> algorithm, Stream output, IConfiguaration config) { _algorithm = algorithm; _output = output; _config = config; }
public RounderReporter([NotNull] Stream outStream, [NotNull] IConfiguaration config) { _outStream = outStream; Configuaration = config; _routeMode = false; }
public IReporter <string> Compress(IFile target, IConfiguaration configuaration, Stream output, int width, int height) { var nextReporter = _next.Compress(target, configuaration, output, width, height); return(new RoundingDigitsReporter(configuaration.Get <int>("roundingdecimals"), nextReporter)); }
public RounderReporter([NotNull] IReporter <OfcNumber> nextReporter, [NotNull] IConfiguaration config) { _nextReporter = nextReporter; Configuaration = config; _routeMode = true; }
public AlgorithmHookString(IAlgorithm <string> algorithm, Stream output, IConfiguaration config) { _algorithm = algorithm; _output = output; _config = config; }
public void Decompress(IFile target, IConfiguaration configuaration, Stream input, IReporter <string> reporter, int width) { _algorithm.Decompress(target, configuaration, input, new ReverseConvertingReporter <T>(reporter, _converter), width); }
public IReporter <string> Compress(IFile target, IConfiguaration configuaration, Stream output, int width, int height) { return(new ConvertingReporter <T>(_algorithm.Compress(target, configuaration, output, width, height), _converter)); }
public DecompressAction(IAlgorithm <TAlgorithm> algorithm, IConverter <TAlgorithm> converter, IConfiguaration configuaration, [CanBeNull] string basePath, [NotNull] string metaPath, [CanBeNull] string dataPath, bool isLzma, [NotNull] string destination) { if (metaPath == null) { throw new ArgumentNullException(nameof(metaPath)); } if (dataPath == null && !isLzma) { throw new ArgumentNullException(nameof(dataPath)); } if (destination == null) { throw new ArgumentNullException(nameof(destination)); } _metaPath = System.IO.Path.GetFullPath(metaPath); _dataPath = isLzma ? null : System.IO.Path.GetFullPath(dataPath); _algorithm = algorithm; _converter = converter; _configuaration = configuaration; _isLzma = isLzma; _destination = System.IO.Path.GetFullPath(destination); _relativePath = basePath != null && _metaPath.StartsWith(basePath) ? _metaPath.Substring(basePath.Length) : _metaPath; }