📷 A modern, cross-platform, 2D Graphics library for .NET
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.
 
 

117 lines
3.1 KiB

<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
// <auto-generated />
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats;
using Xunit;
using Xunit.Abstractions;
<#+
private static readonly string[] UnassociatedAlphaPixelTypes =
{
"A8",
"Argb32",
"Bgra32",
"Bgra4444",
"Bgra5551",
"Byte4",
"HalfVector4",
"La16",
"La32",
"NormalizedByte4",
"NormalizedShort4",
"Rgba1010102",
"Rgba32",
"Rgba64",
"RgbaVector",
"Short4"
};
private static readonly string[] AssociatedAlphaPixelTypes = Array.Empty<string>();
private static readonly string[] CommonPixelTypes =
{
"A8",
"Argb32",
"Bgr24",
"Bgr565",
"Bgra32",
"Bgra4444",
"Bgra5551",
"Byte4",
"HalfSingle",
"HalfVector2",
"HalfVector4",
"L16",
"L8",
"La16",
"La32",
"NormalizedByte2",
"NormalizedByte4",
"NormalizedShort2",
"NormalizedShort4",
"Rg32",
"Rgb24",
"Rgb48",
"Rgba1010102",
"Rgba32",
"Rgba64",
"RgbaVector",
"Short2",
"Short4",
};
void GenerateSpecializedClass(string pixelType, string alpha)
{
#>
public partial class <#=pixelType#>_OperationsTests : PixelOperationsTests<<#=pixelType#>>
{
public <#=pixelType#>_OperationsTests(ITestOutputHelper output)
: base(output)
{
}
[Fact]
public void IsSpecialImplementation() => Assert.IsType<<#=pixelType#>.PixelOperations>(PixelOperations<<#=pixelType#>>.Instance);
[Fact]
public void PixelTypeInfoHasCorrectBitsPerPixel()
{
var bits = <#=pixelType#>.PixelOperations.Instance.GetPixelTypeInfo().BitsPerPixel;
Assert.Equal(Unsafe.SizeOf<<#=pixelType#>>() * 8, bits);
}
[Fact]
public void PixelTypeInfoHasCorrectAlphaRepresentation()
{
var alphaRepresentation = <#=pixelType#>.PixelOperations.Instance.GetPixelTypeInfo().AlphaRepresentation;
Assert.Equal(<#=alpha#>, alphaRepresentation);
}
}
<#+
}
void GenerateAllSpecializedClasses()
{
foreach (string pixelType in CommonPixelTypes)
{
string alpha = "PixelAlphaRepresentation.None";
if (AssociatedAlphaPixelTypes.Contains(pixelType))
{
alpha = "PixelAlphaRepresentation.Associated";
}
else if (UnassociatedAlphaPixelTypes.Contains(pixelType))
{
alpha = "PixelAlphaRepresentation.Unassociated";
}
GenerateSpecializedClass(pixelType, alpha);
}
}
#>