csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
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.
51 lines
1.7 KiB
51 lines
1.7 KiB
using Avalonia.Media.Imaging;
|
|
using Avalonia.Platform;
|
|
using Xunit;
|
|
|
|
namespace Avalonia.Base.UnitTests.Media.Imaging
|
|
{
|
|
public class PixelFormatTranscoderTests
|
|
{
|
|
[Fact]
|
|
public void Should_Transcode()
|
|
{
|
|
var sourceMemory = CreateBitmapMemory();
|
|
|
|
var destMemory = new BitmapMemory(PixelFormat.Bgra8888, AlphaFormat.Opaque, sourceMemory.Size);
|
|
|
|
PixelFormatTranscoder.Transcode(
|
|
sourceMemory.Address,
|
|
sourceMemory.Size,
|
|
sourceMemory.RowBytes,
|
|
sourceMemory.Format,
|
|
sourceMemory.AlphaFormat,
|
|
destMemory.Address,
|
|
destMemory.RowBytes,
|
|
destMemory.Format,
|
|
destMemory.AlphaFormat);
|
|
|
|
var reader = new PixelFormatReader.Bgra8888PixelFormatReader();
|
|
|
|
reader.Reset(destMemory.Address);
|
|
|
|
Assert.Equal(new Rgba8888Pixel(255, 0, 0, 0), reader.ReadNext());
|
|
Assert.Equal(new Rgba8888Pixel(0, 255, 0, 0), reader.ReadNext());
|
|
Assert.Equal(new Rgba8888Pixel(0, 0, 255, 0), reader.ReadNext());
|
|
}
|
|
|
|
private BitmapMemory CreateBitmapMemory()
|
|
{
|
|
var bitmapMemory = new BitmapMemory(PixelFormat.Rgba8888, AlphaFormat.Opaque, new PixelSize(3, 1));
|
|
|
|
var sourceWriter = new PixelFormatWriter.Rgba8888PixelFormatWriter();
|
|
|
|
sourceWriter.Reset(bitmapMemory.Address);
|
|
|
|
sourceWriter.WriteNext(new Rgba8888Pixel { R = 255 });
|
|
sourceWriter.WriteNext(new Rgba8888Pixel { G = 255 });
|
|
sourceWriter.WriteNext(new Rgba8888Pixel { B = 255 });
|
|
|
|
return bitmapMemory;
|
|
}
|
|
}
|
|
}
|
|
|