Add image processing benchmarks and UI folder open buttons
- Added MaddoShared.Benchmarks project with BenchmarkDotNet for comprehensive image processing performance tests (parallel, chunk, size, stress). - Included helper for generating test images and custom configs to ensure InProcess toolchain for .NET Windows compatibility. - Added cross-platform scripts to run benchmarks easily. - Updated .gitignore for benchmark artifacts and temp files. - Exposed GetFilesToProcessPublic in ImageCreationStuff for testability. - Added file name sanitization in ImageCreatorSharp to prevent IO errors. - Enhanced WinForms UI: added "Open" buttons for source/destination folders, handled folder opening in Explorer, and improved user messaging and layout. - Updated solution file to include new benchmark project.
This commit is contained in:
parent
39b0904a72
commit
c2fd4bf780
17 changed files with 1608 additions and 301 deletions
107
MaddoShared.Benchmarks/Helpers/TestImageGenerator.cs
Normal file
107
MaddoShared.Benchmarks/Helpers/TestImageGenerator.cs
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
|
||||
namespace MaddoShared.Benchmarks.Helpers;
|
||||
|
||||
/// <summary>
|
||||
/// Helper class to generate test images for benchmarking
|
||||
/// </summary>
|
||||
[SuppressMessage("Interoperability", "CA1416:Validate platform compatibility")]
|
||||
public static class TestImageGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// Generates a set of test JPEG images in the specified directory
|
||||
/// </summary>
|
||||
/// <param name="outputDirectory">Directory where images will be created</param>
|
||||
/// <param name="imageCount">Number of images to generate</param>
|
||||
/// <param name="width">Width of each image</param>
|
||||
/// <param name="height">Height of each image</param>
|
||||
/// <param name="includeSubfolders">Whether to create images in subfolders</param>
|
||||
public static void GenerateTestImages(
|
||||
string outputDirectory,
|
||||
int imageCount,
|
||||
int width = 4000,
|
||||
int height = 3000,
|
||||
bool includeSubfolders = false)
|
||||
{
|
||||
Directory.CreateDirectory(outputDirectory);
|
||||
|
||||
var random = new Random(42); // Fixed seed for reproducibility
|
||||
|
||||
for (int i = 0; i < imageCount; i++)
|
||||
{
|
||||
var targetDir = outputDirectory;
|
||||
|
||||
if (includeSubfolders && i % 10 == 0)
|
||||
{
|
||||
targetDir = Path.Combine(outputDirectory, $"Subfolder_{i / 10}");
|
||||
Directory.CreateDirectory(targetDir);
|
||||
}
|
||||
|
||||
var filePath = Path.Combine(targetDir, $"test_image_{i:D5}.jpg");
|
||||
|
||||
// Skip if already exists
|
||||
if (File.Exists(filePath))
|
||||
continue;
|
||||
|
||||
using var bitmap = new Bitmap(width, height);
|
||||
using var graphics = Graphics.FromImage(bitmap);
|
||||
|
||||
// Fill with a random color background
|
||||
var bgColor = Color.FromArgb(random.Next(256), random.Next(256), random.Next(256));
|
||||
graphics.Clear(bgColor);
|
||||
|
||||
// Draw some random shapes to make it more realistic
|
||||
for (int j = 0; j < 20; j++)
|
||||
{
|
||||
var color = Color.FromArgb(random.Next(256), random.Next(256), random.Next(256));
|
||||
var brush = new SolidBrush(color);
|
||||
var x = random.Next(width);
|
||||
var y = random.Next(height);
|
||||
var w = random.Next(200, 800);
|
||||
var h = random.Next(200, 800);
|
||||
graphics.FillEllipse(brush, x, y, w, h);
|
||||
}
|
||||
|
||||
// Add some text
|
||||
using var font = new Font("Arial", 48, FontStyle.Bold);
|
||||
var text = $"Test Image {i}";
|
||||
var textBrush = new SolidBrush(Color.White);
|
||||
graphics.DrawString(text, font, textBrush, new PointF(100, 100));
|
||||
|
||||
// Save as JPEG with standard quality
|
||||
var encoder = GetEncoder(ImageFormat.Jpeg);
|
||||
var encoderParameters = new EncoderParameters(1);
|
||||
encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, 85L);
|
||||
|
||||
bitmap.Save(filePath, encoder, encoderParameters);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cleans up generated test images
|
||||
/// </summary>
|
||||
public static void CleanupTestImages(string directory)
|
||||
{
|
||||
if (Directory.Exists(directory))
|
||||
{
|
||||
Directory.Delete(directory, recursive: true);
|
||||
}
|
||||
}
|
||||
|
||||
private static ImageCodecInfo GetEncoder(ImageFormat format)
|
||||
{
|
||||
var codecs = ImageCodecInfo.GetImageEncoders();
|
||||
foreach (var codec in codecs)
|
||||
{
|
||||
if (codec.FormatID == format.Guid)
|
||||
{
|
||||
return codec;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue