Loading files
bbd0ea8c1This file is pinned to the selected release. Download the original to open it in your design tool.
using Hast.Layer;
using Hast.Samples.SampleAssembly;
using System.Drawing;
using System.Drawing.Imaging;
using System.Threading.Tasks;
namespace Hast.Samples.Consumer.SampleRunners
{
internal class ImageProcessingAlgorithmsSampleRunner : ISampleRunner
{
public void Configure(HardwareGenerationConfiguration configuration)
{
configuration.AddHardwareEntryPointType<ImageContrastModifier>();
// ImageFilter is not parallelized, so not including it not to take away FPGA resources from
// ImageContrastModifier.
//configuration.AddHardwareEntryPointType<ImageFilter>();
}
public async Task Run(IHastlayer hastlayer, IHardwareRepresentation hardwareRepresentation, IProxyGenerationConfiguration configuration)
{
// In case you wish to test the sample with a larger file, the fpga.jpg file must be replaced. You can find
// a 100 megapixel jpeg here: https://photographingspace.com/100-megapixel-moon/
using var bitmap = new Bitmap("fpga.jpg");
var imageContrastModifier = await hastlayer
.GenerateProxy(hardwareRepresentation, new ImageContrastModifier(), configuration);
var modifiedImage = imageContrastModifier.ChangeImageContrast(bitmap, -50, hastlayer, hardwareRepresentation.HardwareGenerationConfiguration);
modifiedImage.Save("contrast.bmp", ImageFormat.Bmp);
var sw = System.Diagnostics.Stopwatch.StartNew();
var cpuOutput = new ImageContrastModifier().ChangeImageContrast(bitmap, -50, hastlayer, hardwareRepresentation.HardwareGenerationConfiguration);
sw.Stop();
System.Console.WriteLine("On CPU it took " + sw.ElapsedMilliseconds + " ms.");
// ImageFilter disabled until it's improved.
//var imageFilter = await hastlayer.GenerateProxy(hardwareRepresentation, new ImageFilter());
//var filteredImage = imageFilter.DetectHorizontalEdges(bitmap);
}
}
}