forked from amkovkov/GranuSightSoftware2
142 lines
4.7 KiB
C#
142 lines
4.7 KiB
C#
using Avalonia;
|
|
using Avalonia.OpenGL.Egl;
|
|
|
|
using System.CommandLine;
|
|
|
|
namespace GSS2.Test;
|
|
|
|
public partial class Program
|
|
{
|
|
private enum RenderingMode
|
|
{
|
|
X11,
|
|
DRM
|
|
}
|
|
|
|
private static string[]? _args = null;
|
|
private static readonly RootCommand _rootCommand = new("Run UI application");
|
|
private static readonly Option<bool> _fullscreen = new("--fullscreen")
|
|
{
|
|
Description = "Run in fullscreen mode"
|
|
};
|
|
|
|
private static readonly Command _cameraTuningCommand = new("camera-tuning")
|
|
{
|
|
Description = "Tune camera parameters"
|
|
};
|
|
private static readonly Option<FileInfo> _cameraTuningOutputFile = new("--output")
|
|
{
|
|
Description = "Output image file",
|
|
Required = false
|
|
};
|
|
private static readonly Option<double> _cameraTuningGainR = new("--gain-r")
|
|
{
|
|
Description = "Color gain (red channel) to start from",
|
|
DefaultValueFactory = (_) => 1
|
|
};
|
|
private static readonly Option<double> _cameraTuningGainG = new("--gain-g")
|
|
{
|
|
Description = "Color gain (green channel) to start from",
|
|
DefaultValueFactory = (_) => 1
|
|
};
|
|
private static readonly Option<double> _cameraTuningGainB = new("--gain-b")
|
|
{
|
|
Description = "Color gain (blue channel) to start from",
|
|
DefaultValueFactory = (_) => 1
|
|
};
|
|
private static readonly Option<double> _cameraTuningThreshold = new("--threshold")
|
|
{
|
|
Description = "Threshold to stop on",
|
|
DefaultValueFactory = (_) => 0.1
|
|
};
|
|
private static readonly Option<uint> _cameraTuningSteps = new("--steps")
|
|
{
|
|
Description = "Maximum steps count",
|
|
DefaultValueFactory = (_) => 10
|
|
};
|
|
|
|
private static readonly Command _captureCommand = new("capture")
|
|
{
|
|
Description = "Capture image from camera"
|
|
};
|
|
private static readonly Option<FileInfo> _captureOutputFile = new("--output")
|
|
{
|
|
Description = "Output image file",
|
|
DefaultValueFactory = (_) => new FileInfo("image.png")
|
|
};
|
|
private static readonly Option<double> _captureIntencityWhite = new("--intencity-white")
|
|
{
|
|
Description = "Illuminator intencity for white (from 0 to 1)",
|
|
DefaultValueFactory = (_) => 1
|
|
};
|
|
private static readonly Option<double> _captureIntencityUv365nm = new("--intencity-uv365nm")
|
|
{
|
|
Description = "Illuminator intencity for UV 365 nm (from 0 to 1)",
|
|
DefaultValueFactory = (_) => 0
|
|
};
|
|
private static readonly Option<double> _captureIntencityUv254nm = new("--intencity-uv254nm")
|
|
{
|
|
Description = "Illuminator intencity for UV 254 nm (from 0 to 1)",
|
|
DefaultValueFactory = (_) => 0
|
|
};
|
|
|
|
private static readonly Option<RenderingMode> _renderingMode = new("--rendering-mode")
|
|
{
|
|
Description = "Rendering mode to use",
|
|
DefaultValueFactory = (_) => RenderingMode.X11
|
|
};
|
|
private static readonly Option<bool> _hideConsole = new("--hide-console")
|
|
{
|
|
Description = "Suppress console output",
|
|
DefaultValueFactory = (result) => result.GetRequiredValue(_renderingMode) == RenderingMode.DRM
|
|
};
|
|
|
|
public static event ConsoleCancelEventHandler? ShutdownRequested;
|
|
|
|
[STAThread]
|
|
public static int Main(string[] args)
|
|
{
|
|
_args = args;
|
|
|
|
_rootCommand.SetAction(Ui);
|
|
_rootCommand.Add(_fullscreen);
|
|
_rootCommand.Add(_renderingMode);
|
|
_rootCommand.Add(_hideConsole);
|
|
|
|
_rootCommand.Add(_cameraTuningCommand);
|
|
_cameraTuningCommand.SetAction(CameraTuning);
|
|
_cameraTuningCommand.Add(_cameraTuningOutputFile);
|
|
_cameraTuningCommand.Add(_cameraTuningGainR);
|
|
_cameraTuningCommand.Add(_cameraTuningGainG);
|
|
_cameraTuningCommand.Add(_cameraTuningGainB);
|
|
_cameraTuningCommand.Add(_cameraTuningThreshold);
|
|
_cameraTuningCommand.Add(_cameraTuningSteps);
|
|
|
|
_rootCommand.Add(_captureCommand);
|
|
_captureCommand.SetAction(Capture);
|
|
_captureCommand.Add(_captureOutputFile);
|
|
_captureCommand.Add(_captureIntencityWhite);
|
|
_captureCommand.Add(_captureIntencityUv365nm);
|
|
_captureCommand.Add(_captureIntencityUv254nm);
|
|
|
|
Console.CancelKeyPress += new ConsoleCancelEventHandler(OnProgramShutdown);
|
|
Console.WriteLine("Press Ctrl+C to shut down.");
|
|
|
|
var parseResult = _rootCommand.Parse(_args);
|
|
if (parseResult.Errors.Count() != 0)
|
|
{
|
|
foreach (var parseError in parseResult.Errors)
|
|
Console.Error.WriteLine(parseError.Message);
|
|
return 1;
|
|
}
|
|
|
|
return parseResult.Invoke();
|
|
}
|
|
|
|
private static void OnProgramShutdown(object? sender, ConsoleCancelEventArgs ea)
|
|
{
|
|
ShutdownRequested?.Invoke(sender, ea);
|
|
ea.Cancel = true;
|
|
}
|
|
}
|