mirror of
https://github.com/AtomUI/AtomUI.git
synced 2026-10-21 08:32:21 +08:00
70 lines
1.9 KiB
C#
70 lines
1.9 KiB
C#
using System.Buffers.Binary;
|
|
using Avalonia;
|
|
using Avalonia.Media;
|
|
|
|
namespace AtomUI.Controls.Shared.Tests.ImageLoading;
|
|
|
|
internal static class ImageLoadingTestSupport
|
|
{
|
|
internal static ImageLoadingOptions CreateOptions(Action<ImageLoadingOptionsBuilder>? configure = null)
|
|
{
|
|
var builder = new ImageLoadingOptionsBuilder
|
|
{
|
|
IsPersistentCacheEnabled = false
|
|
};
|
|
configure?.Invoke(builder);
|
|
return builder.Build("AtomUI.Controls.Shared.Tests");
|
|
}
|
|
|
|
internal static byte[] CreatePngHeader(int width = 2, int height = 3, bool animated = false)
|
|
{
|
|
var bytes = new byte[animated ? 32 : 24];
|
|
new byte[] { 0x89, (byte)'P', (byte)'N', (byte)'G', 0x0d, 0x0a, 0x1a, 0x0a }
|
|
.CopyTo(bytes, 0);
|
|
BinaryPrimitives.WriteUInt32BigEndian(bytes.AsSpan(16, 4), checked((uint)width));
|
|
BinaryPrimitives.WriteUInt32BigEndian(bytes.AsSpan(20, 4), checked((uint)height));
|
|
if (animated)
|
|
{
|
|
"acTL"u8.CopyTo(bytes.AsSpan(24));
|
|
}
|
|
return bytes;
|
|
}
|
|
|
|
internal static ImageEncodedContent CreateContent(
|
|
byte[] bytes,
|
|
string? mediaType = "image/png",
|
|
ImageCacheSource cacheSource = ImageCacheSource.Local,
|
|
bool noStore = false)
|
|
{
|
|
return new ImageEncodedContent(
|
|
bytes,
|
|
mediaType,
|
|
cacheSource,
|
|
DateTimeOffset.UtcNow,
|
|
NoStore: noStore);
|
|
}
|
|
}
|
|
|
|
internal sealed class TestImage : IImage, IDisposable
|
|
{
|
|
private int _disposeCount;
|
|
|
|
internal TestImage(double width = 10, double height = 10)
|
|
{
|
|
Size = new Size(width, height);
|
|
}
|
|
|
|
public Size Size { get; }
|
|
|
|
internal int DisposeCount => Volatile.Read(ref _disposeCount);
|
|
|
|
public void Draw(DrawingContext context, Rect sourceRect, Rect destRect)
|
|
{
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
Interlocked.Increment(ref _disposeCount);
|
|
}
|
|
}
|