Skip to content

Commit

Permalink
Re-add ability to generate multiple barcode versions from the CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
mlaily committed Jan 20, 2021
1 parent d85eb2e commit b27a152
Showing 1 changed file with 41 additions and 7 deletions.
48 changes: 41 additions & 7 deletions MovieBarCodeGenerator/CLI/CLIBatchProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

using Mono.Options;
using MovieBarCodeGenerator.Core;
using PhotoSauce.MagicScaler;
using System;
using System.Collections.Generic;
using System.Drawing;
Expand Down Expand Up @@ -82,10 +83,21 @@ public void Process(string[] args)
$"Width of each bar in the output image. Default: {RawArguments.DefaultBarWidth}",
x => arguments.RawBarWidth = x);

// TODO
//options.Add("s|smooth",
// "Also generate a smooth version of the output, suffixed with '_smoothed'.",
// x => arguments.Smooth = true);
options.Add("normal",
"Generate a normal barcode.\nDefaults to True.\n(Use --normal- to set it to False)",
x => arguments.GenerateNormal = x != null);

options.Add("normal-smoothed",
"Generate a normal smoothed barcode.\nDefaults to False.",
x => arguments.GenerateNormalSmoothed = x != null);

options.Add("legacy",
"Generate a legacy barcode.\nDefaults to False.",
x => arguments.GenerateLegacy = x != null);

options.Add("legacy-smoothed",
"Generate a legacy smoothed barcode.\nDefaults to False.",
x => arguments.GenerateLegacySmoothed = x != null);

try
{
Expand Down Expand Up @@ -126,8 +138,25 @@ private void DealWithOneInputFile(RawArguments arguments)
{
Console.WriteLine($"Processing file '{arguments.RawInput}':");

// TODO
var generators = new[] { new MagicScalerBarGenerator("Normal") };
var generators = new List<IBarGenerator>();

if (arguments.GenerateNormal)
generators.Add(new MagicScalerBarGenerator("Normal"));

if (arguments.GenerateNormalSmoothed)
generators.Add(new MagicScalerBarGenerator("Normal (smoothed)", "_smoothed", average: true, interpolation: InterpolationSettings.CubicSmoother));

if (arguments.GenerateLegacy)
generators.Add(GdiBarGenerator.CreateLegacy(average: false));

if (arguments.GenerateLegacySmoothed)
generators.Add(GdiBarGenerator.CreateLegacy(average: true));

if (!generators.Any())
{
Console.WriteLine("No generator.");
return;
}

IReadOnlyCollection<string> existingOutputs = Array.Empty<string>();
BarCodeParameters parameters;
Expand Down Expand Up @@ -167,6 +196,7 @@ private void DealWithOneInputFile(RawArguments arguments)
null,
x => Console.WriteLine(x));
}).Wait(); // Image Magic throws if we are on an STA thread, so we have to execute everything on the thread pool and wait...

foreach (var barcode in result)
{
try
Expand Down Expand Up @@ -218,6 +248,10 @@ class RawArguments
public string RawHeight { get; set; } = null;
public bool UseInputHeight { get; set; } = false;
public string RawBarWidth { get; set; } = DefaultBarWidth;
public bool Smooth { get; set; } = false; // TODO

public bool GenerateNormal { get; set; } = true;
public bool GenerateNormalSmoothed { get; set; }
public bool GenerateLegacy { get; set; }
public bool GenerateLegacySmoothed { get; set; }
}
}

0 comments on commit b27a152

Please sign in to comment.