mirror of https://github.com/SixLabors/ImageSharp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.3 KiB
38 lines
1.3 KiB
namespace ImageSharp.Tests.TestUtilities.Integration
|
|
{
|
|
using System;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
|
|
using ImageSharp.Formats;
|
|
using ImageSharp.PixelFormats;
|
|
|
|
public class ReferenceDecoder : IImageDecoder
|
|
{
|
|
public static ReferenceDecoder Instance { get; } = new ReferenceDecoder();
|
|
|
|
public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream)
|
|
where TPixel : struct, IPixel<TPixel>
|
|
{
|
|
using (var sourceBitmap = new System.Drawing.Bitmap(stream))
|
|
{
|
|
if (sourceBitmap.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb)
|
|
{
|
|
return IntegrationTestUtils.FromSystemDrawingBitmap<TPixel>(sourceBitmap);
|
|
}
|
|
|
|
using (var convertedBitmap = new System.Drawing.Bitmap(
|
|
sourceBitmap.Width,
|
|
sourceBitmap.Height,
|
|
System.Drawing.Imaging.PixelFormat.Format32bppArgb))
|
|
{
|
|
using (var g = Graphics.FromImage(convertedBitmap))
|
|
{
|
|
g.DrawImage(sourceBitmap, new PointF(0, 0));
|
|
}
|
|
return IntegrationTestUtils.FromSystemDrawingBitmap<TPixel>(convertedBitmap);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|