public void Generate_All_Barcode_Settings_Combinations()
    {
        Assert.Inconclusive("Uncomment me to run the test");

        var ffmpegWrapper   = new FfmpegWrapper(FfmpegExecutablePath);
        var streamProcessor = new ImageStreamProcessor();

        var allGenerators = new List <IBarGenerator>();

        // Legacy (reference)
        allGenerators.Add(GdiBarGenerator.CreateLegacy(false));
        // Legacy (reference) smoothed
        allGenerators.Add(GdiBarGenerator.CreateLegacy(true));

        foreach (var average in new[] { GdiAverage.No, GdiAverage.OnePass })
        {
            foreach (var interpolationMode in new[] { InterpolationMode.HighQualityBicubic, InterpolationMode.NearestNeighbor, InterpolationMode.Bicubic })
            {
                allGenerators.Add(new GdiBarGenerator(average: average, scalingMode: ScalingMode.Sane, interpolationMode: interpolationMode));
            }
        }

        foreach (var average in new[] { false, true })
        {
            foreach (var interpolation in new[]
            {
                InterpolationSettings.Average,
                InterpolationSettings.CubicSmoother,
                InterpolationSettings.NearestNeighbor,
            })
            {
                allGenerators.Add(new MagicScalerBarGenerator("noname", average: average, interpolation: interpolation));
            }
        }

        CreateTestVideoIfNecessary();
        var inputPath = TestVideoFilePath;

        inputPath = @"G:\videos\In Bruges (2008)\In.Bruges.2008.720p.BrRip.x264.YIFY.mp4";

        {
            var results = streamProcessor.CreateBarCodes(
                new BarCodeParameters
            {
                Width                = 1280,
                BarWidth             = 1,
                InputPath            = inputPath,
                GeneratorOutputPaths = allGenerators.ToDictionary(x => x, x => x.Name)
            },
                ffmpegWrapper,
                CancellationToken.None,
                progress: null,
                log: x => TestContext.WriteLine(x));

            foreach (var result in results)
            {
                result.Value.Save($"{result.Key.Name}.png");
            }
        }

        //{
        //    var results = streamProcessor.CreateBarCodes(
        //        inputPath,
        //        new BarCodeParameters { Width = 500, BarWidth = 50 },
        //        ffmpegWrapper,
        //         CancellationToken.None,
        //         progress: null,
        //         log: x => TestContext.WriteLine(x),
        //         allGenerators.ToArray());

        //    foreach (var result in results)
        //    {
        //        result.Value.Save($"50-{result.Key.Name}.png");
        //    }
        //}
    }
示例#2
0
    public MainForm()
    {
        InitializeComponent();

        var executingAssembly = Assembly.GetExecutingAssembly();

        Icon  = Icon.ExtractAssociatedIcon(executingAssembly.Location);
        Text += $" - {executingAssembly.GetName().Version}";

        _barGenerators = new List <BarGeneratorViewModel>
        {
            new BarGeneratorViewModel(
                new MagicScalerBarGenerator("Normal", average: false),
                "The default mode to generate barcodes.\r\nIt scales images using a resampling algorithm that takes care of gamma correction and produces correct color averages.",
                initialCheckState: true),
            new BarGeneratorViewModel(
                new MagicScalerBarGenerator("Normal (smoothed)", "_smoothed", average: true, InterpolationSettings.CubicSmoother),
                "Almost the same as the 'Normal' mode, but vertically smoothed.\r\nIt also uses a 'cubic smoother' resampling algorithm that generates images sharper than the normal algorithm.",
                initialCheckState: false),
            new BarGeneratorViewModel(
                GdiBarGenerator.CreateLegacy(average: false),
                "The mode used in previous versions.\r\nIt's relatively fast, but the algorithm used to scale images is of poor quality.\r\nThis mode is not recommended, and only here for backward-compatibility.",
                initialCheckState: false),
            new BarGeneratorViewModel(
                GdiBarGenerator.CreateLegacy(average: true),
                "Same as 'Legacy', but vertically smoothed.",
                initialCheckState: false),
        };

        barGeneratorList.DisplayMember = nameof(BarGeneratorViewModel.DisplayName);
        barGeneratorList.Items.Clear();
        foreach (var item in _barGenerators)
        {
            barGeneratorList.Items.Add(item, isChecked: item.Checked);
        }

        barGeneratorList.SelectedItem = _barGenerators.First(x => x.Checked); // So that the right panel displays something.
        barGeneratorList.SelectedItem = null;                                 // Unselect so a click on the line will not uncheck the item.

        AppendLog(Text);

        _openFileDialog = new OpenFileDialog()
        {
            CheckFileExists = true,
            CheckPathExists = true,
        };

        _saveFileDialog = new SaveFileDialog()
        {
            DefaultExt      = ".png",
            Filter          = "Bitmap|*.bmp|Jpeg|*.jpg|Png|*.png|Gif|*.gif|All files|*.*",
            FilterIndex     = 3, // 1 based
            OverwritePrompt = true,
        };

        _ffmpegWrapper              = new FfmpegWrapper("ffmpeg.exe");
        _imageProcessor             = new ImageStreamProcessor();
        _barCodeParametersValidator = new BarCodeParametersValidator();

        useInputHeightForOutputCheckBox.Checked = true;
        generateButton.Text = GenerateButtonText;
    }