Browse Source

Alpha8 => A8

pull/1062/head
James Jackson-South 6 years ago
parent
commit
d68519d133
  1. 2
      src/ImageSharp/Advanced/AotCompilerTools.cs
  2. 44
      src/ImageSharp/PixelFormats/PixelImplementations/A8.cs
  3. 2
      src/ImageSharp/Processing/Processors/Binarization/BinaryErrorDiffusionProcessor{TPixel}.cs
  4. 2
      src/ImageSharp/Processing/Processors/Binarization/BinaryOrderedDitherProcessor{TPixel}.cs
  5. 2
      src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs
  6. 6
      tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs
  7. 48
      tests/ImageSharp.Tests/PixelFormats/A8Tests.cs
  8. 2
      tests/ImageSharp.Tests/Processing/Transforms/TransformsHelpersTest.cs
  9. 4
      tests/ImageSharp.Tests/TestImages.cs
  10. 2
      tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs
  11. 4
      tests/ImageSharp.Tests/TestUtilities/TestUtils.cs
  12. 2
      tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs
  13. 4
      tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs

2
src/ImageSharp/Advanced/AotCompilerTools.cs

@ -40,7 +40,7 @@ namespace SixLabors.ImageSharp.Advanced
/// </summary>
private static void SeedEverything()
{
Seed<Alpha8>();
Seed<A8>();
Seed<Argb32>();
Seed<Bgr24>();
Seed<Bgr565>();

44
src/ImageSharp/PixelFormats/PixelImplementations/Alpha8.cs → src/ImageSharp/PixelFormats/PixelImplementations/A8.cs

@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
@ -8,56 +8,56 @@ using System.Runtime.CompilerServices;
namespace SixLabors.ImageSharp.PixelFormats
{
/// <summary>
/// Packed pixel type containing a single 8 bit normalized W values.
/// Packed pixel type containing a single 8 bit normalized alpha value.
/// <para>
/// Ranges from [0, 0, 0, 0] to [0, 0, 0, 1] in vector form.
/// </para>
/// </summary>
public struct Alpha8 : IPixel<Alpha8>, IPackedVector<byte>
public struct A8 : IPixel<A8>, IPackedVector<byte>
{
/// <summary>
/// Initializes a new instance of the <see cref="Alpha8"/> struct.
/// Initializes a new instance of the <see cref="A8"/> struct.
/// </summary>
/// <param name="alpha">The alpha component.</param>
public Alpha8(byte alpha) => this.PackedValue = alpha;
public A8(byte alpha) => this.PackedValue = alpha;
/// <summary>
/// Initializes a new instance of the <see cref="Alpha8"/> struct.
/// Initializes a new instance of the <see cref="A8"/> struct.
/// </summary>
/// <param name="alpha">The alpha component.</param>
public Alpha8(float alpha) => this.PackedValue = Pack(alpha);
public A8(float alpha) => this.PackedValue = Pack(alpha);
/// <inheritdoc />
public byte PackedValue { get; set; }
/// <summary>
/// Compares two <see cref="Alpha8"/> objects for equality.
/// Compares two <see cref="A8"/> objects for equality.
/// </summary>
/// <param name="left">
/// The <see cref="Alpha8"/> on the left side of the operand.
/// The <see cref="A8"/> on the left side of the operand.
/// </param>
/// <param name="right">
/// The <see cref="Alpha8"/> on the right side of the operand.
/// The <see cref="A8"/> on the right side of the operand.
/// </param>
/// <returns>
/// True if the <paramref name="left"/> parameter is equal to the <paramref name="right"/> parameter; otherwise, false.
/// </returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator ==(Alpha8 left, Alpha8 right) => left.Equals(right);
public static bool operator ==(A8 left, A8 right) => left.Equals(right);
/// <summary>
/// Compares two <see cref="Alpha8"/> objects for equality.
/// Compares two <see cref="A8"/> objects for equality.
/// </summary>
/// <param name="left">The <see cref="Alpha8"/> on the left side of the operand.</param>
/// <param name="right">The <see cref="Alpha8"/> on the right side of the operand.</param>
/// <param name="left">The <see cref="A8"/> on the left side of the operand.</param>
/// <param name="right">The <see cref="A8"/> on the right side of the operand.</param>
/// <returns>
/// True if the <paramref name="left"/> parameter is not equal to the <paramref name="right"/> parameter; otherwise, false.
/// </returns>
[MethodImpl(InliningOptions.ShortMethod)]
public static bool operator !=(Alpha8 left, Alpha8 right) => !left.Equals(right);
public static bool operator !=(A8 left, A8 right) => !left.Equals(right);
/// <inheritdoc />
public PixelOperations<Alpha8> CreatePixelOperations() => new PixelOperations<Alpha8>();
public PixelOperations<A8> CreatePixelOperations() => new PixelOperations<A8>();
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
@ -128,21 +128,21 @@ namespace SixLabors.ImageSharp.PixelFormats
/// </summary>
/// <param name="obj">The object to compare.</param>
/// <returns>True if the object is equal to the packed vector.</returns>
public override bool Equals(object obj) => obj is Alpha8 other && this.Equals(other);
public override bool Equals(object obj) => obj is A8 other && this.Equals(other);
/// <summary>
/// Compares another Alpha8 packed vector with the packed vector.
/// Compares another A8 packed vector with the packed vector.
/// </summary>
/// <param name="other">The Alpha8 packed vector to compare.</param>
/// <param name="other">The A8 packed vector to compare.</param>
/// <returns>True if the packed vectors are equal.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public bool Equals(Alpha8 other) => this.PackedValue.Equals(other.PackedValue);
public bool Equals(A8 other) => this.PackedValue.Equals(other.PackedValue);
/// <summary>
/// Gets a string representation of the packed vector.
/// </summary>
/// <returns>A string representation of the packed vector.</returns>
public override string ToString() => $"Alpha8({this.PackedValue})";
public override string ToString() => $"A8({this.PackedValue})";
/// <inheritdoc />
[MethodImpl(InliningOptions.ShortMethod)]
@ -156,4 +156,4 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
private static byte Pack(float alpha) => (byte)Math.Round(alpha.Clamp(0, 1F) * 255F);
}
}
}

2
src/ImageSharp/Processing/Processors/Binarization/BinaryErrorDiffusionProcessor{TPixel}.cs

@ -39,7 +39,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Binarization
IErrorDiffuser diffuser = this.definition.Diffuser;
byte threshold = (byte)MathF.Round(this.definition.Threshold * 255F);
bool isAlphaOnly = typeof(TPixel) == typeof(Alpha8);
bool isAlphaOnly = typeof(TPixel) == typeof(A8);
var interest = Rectangle.Intersect(this.SourceRectangle, source.Bounds());
int startY = interest.Y;

2
src/ImageSharp/Processing/Processors/Binarization/BinaryOrderedDitherProcessor{TPixel}.cs

@ -38,7 +38,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Binarization
TPixel upperColor = this.definition.UpperColor.ToPixel<TPixel>();
TPixel lowerColor = this.definition.LowerColor.ToPixel<TPixel>();
bool isAlphaOnly = typeof(TPixel) == typeof(Alpha8);
bool isAlphaOnly = typeof(TPixel) == typeof(A8);
var interest = Rectangle.Intersect(this.SourceRectangle, source.Bounds());
int startY = interest.Y;

2
src/ImageSharp/Processing/Processors/Binarization/BinaryThresholdProcessor{TPixel}.cs

@ -47,7 +47,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Binarization
int startX = interest.X;
int endX = interest.Right;
bool isAlphaOnly = typeof(TPixel) == typeof(Alpha8);
bool isAlphaOnly = typeof(TPixel) == typeof(A8);
var workingRect = Rectangle.FromLTRB(startX, startY, endX, endY);

6
tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs

@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
TestImages.Png.VimImage2,
TestImages.Png.Rgb24BppTrans,
TestImages.Png.GrayAlpha8Bit,
TestImages.Png.GrayA8Bit,
TestImages.Png.Gray1BitTrans,
TestImages.Png.Bad.ZlibOverflow,
TestImages.Png.Bad.ZlibOverflow2,
@ -73,7 +73,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
TestImages.Png.GrayAlpha1BitInterlaced,
TestImages.Png.GrayAlpha2BitInterlaced,
TestImages.Png.Gray4BitInterlaced,
TestImages.Png.GrayAlpha8BitInterlaced
TestImages.Png.GrayA8BitInterlaced
};
public static readonly string[] TestImagesIssue1014 =
@ -180,7 +180,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
}
[Theory]
[WithFile(TestImages.Png.GrayAlpha8BitInterlaced, PixelTypes)]
[WithFile(TestImages.Png.GrayA8BitInterlaced, PixelTypes)]
public void Decoder_CanDecodeGrey8bitWithAlpha<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{

48
tests/ImageSharp.Tests/PixelFormats/Alpha8Tests.cs → tests/ImageSharp.Tests/PixelFormats/A8Tests.cs

@ -7,42 +7,42 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.PixelFormats
{
public class Alpha8Tests
public class A8Tests
{
[Fact]
public void Alpha8_Constructor()
public void A8_Constructor()
{
// Test the limits.
Assert.Equal(byte.MinValue, new Alpha8(0F).PackedValue);
Assert.Equal(byte.MaxValue, new Alpha8(1F).PackedValue);
Assert.Equal(byte.MinValue, new A8(0F).PackedValue);
Assert.Equal(byte.MaxValue, new A8(1F).PackedValue);
// Test clamping.
Assert.Equal(byte.MinValue, new Alpha8(-1234F).PackedValue);
Assert.Equal(byte.MaxValue, new Alpha8(1234F).PackedValue);
Assert.Equal(byte.MinValue, new A8(-1234F).PackedValue);
Assert.Equal(byte.MaxValue, new A8(1234F).PackedValue);
// Test ordering
Assert.Equal(124, new Alpha8(124F / byte.MaxValue).PackedValue);
Assert.Equal(26, new Alpha8(0.1F).PackedValue);
Assert.Equal(124, new A8(124F / byte.MaxValue).PackedValue);
Assert.Equal(26, new A8(0.1F).PackedValue);
}
[Fact]
public void Alpha8_Equality()
public void A8_Equality()
{
var left = new Alpha8(16);
var right = new Alpha8(32);
var left = new A8(16);
var right = new A8(32);
Assert.True(left == new Alpha8(16));
Assert.True(left == new A8(16));
Assert.True(left != right);
Assert.Equal(left, (object)new Alpha8(16));
Assert.Equal(left, (object)new A8(16));
}
[Fact]
public void Alpha8_FromScaledVector4()
public void A8_FromScaledVector4()
{
// Arrange
Alpha8 alpha = default;
A8 alpha = default;
int expected = 128;
Vector4 scaled = new Alpha8(.5F).ToScaledVector4();
Vector4 scaled = new A8(.5F).ToScaledVector4();
// Act
alpha.FromScaledVector4(scaled);
@ -53,10 +53,10 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
}
[Fact]
public void Alpha8_ToScaledVector4()
public void A8_ToScaledVector4()
{
// Arrange
var alpha = new Alpha8(.5F);
var alpha = new A8(.5F);
// Act
Vector4 actual = alpha.ToScaledVector4();
@ -69,10 +69,10 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
}
[Fact]
public void Alpha8_ToVector4()
public void A8_ToVector4()
{
// Arrange
var alpha = new Alpha8(.5F);
var alpha = new A8(.5F);
// Act
var actual = alpha.ToVector4();
@ -85,9 +85,9 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
}
[Fact]
public void Alpha8_ToRgba32()
public void A8_ToRgba32()
{
var input = new Alpha8(128);
var input = new A8(128);
var expected = new Rgba32(0, 0, 0, 128);
Rgba32 actual = default;
@ -96,10 +96,10 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
}
[Fact]
public void Alpha8_FromBgra5551()
public void A8_FromBgra5551()
{
// arrange
var alpha = default(Alpha8);
var alpha = default(A8);
byte expected = byte.MaxValue;
// act

2
tests/ImageSharp.Tests/Processing/Transforms/TransformsHelpersTest.cs

@ -15,7 +15,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms
{
int xy = 1;
using (var img = new Image<Alpha8>(xy, xy))
using (var img = new Image<A8>(xy, xy))
{
var profile = new ExifProfile();
img.Metadata.ExifProfile = profile;

4
tests/ImageSharp.Tests/TestImages.cs

@ -28,8 +28,8 @@ namespace SixLabors.ImageSharp.Tests
public const string Bpp1 = "Png/bpp1.png";
public const string Gray4Bpp = "Png/gray_4bpp.png";
public const string Gray16Bit = "Png/gray-16.png";
public const string GrayAlpha8Bit = "Png/gray-alpha-8.png";
public const string GrayAlpha8BitInterlaced = "Png/rollsroyce.png";
public const string GrayA8Bit = "Png/gray-alpha-8.png";
public const string GrayA8BitInterlaced = "Png/rollsroyce.png";
public const string GrayAlpha1BitInterlaced = "Png/iftbbn0g01.png";
public const string GrayAlpha2BitInterlaced = "Png/iftbbn0g02.png";
public const string Gray4BitInterlaced = "Png/iftbbn0g04.png";

2
tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs

@ -14,7 +14,7 @@ namespace SixLabors.ImageSharp.Tests
{
Undefined = 0,
Alpha8 = 1 << 0,
A8 = 1 << 0,
Argb32 = 1 << 1,

4
tests/ImageSharp.Tests/TestUtilities/TestUtils.cs

@ -39,8 +39,8 @@ namespace SixLabors.ImageSharp.Tests
ClrTypes2PixelTypes[defaultPixelFormatType] = PixelTypes.Rgba32;
// Add PixelFormat types
string nameSpace = typeof(Alpha8).FullName;
nameSpace = nameSpace.Substring(0, nameSpace.Length - typeof(Alpha8).Name.Length - 1);
string nameSpace = typeof(A8).FullName;
nameSpace = nameSpace.Substring(0, nameSpace.Length - typeof(A8).Name.Length - 1);
foreach (PixelTypes pt in AllConcretePixelTypes.Where(pt => pt != PixelTypes.Rgba32))
{
string typeName = $"{nameSpace}.{pt}";

2
tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs

@ -170,7 +170,7 @@ namespace SixLabors.ImageSharp.Tests
[Theory]
[WithBlankImages(1, 1, PixelTypes.Rgba32, PixelTypes.Rgba32)]
[WithBlankImages(1, 1, PixelTypes.Alpha8, PixelTypes.Alpha8)]
[WithBlankImages(1, 1, PixelTypes.A8, PixelTypes.A8)]
[WithBlankImages(1, 1, PixelTypes.Argb32, PixelTypes.Argb32)]
public void PixelType_PropertyValueIsCorrect<TPixel>(TestImageProvider<TPixel> provider, PixelTypes expected)
where TPixel : struct, IPixel<TPixel> =>

4
tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs

@ -99,13 +99,13 @@ namespace SixLabors.ImageSharp.Tests
[Fact]
public void ExpandAllTypes_1()
{
PixelTypes pixelTypes = PixelTypes.Alpha8 | PixelTypes.Bgr565 | PixelTypes.HalfVector2 | PixelTypes.Rgba32;
PixelTypes pixelTypes = PixelTypes.A8 | PixelTypes.Bgr565 | PixelTypes.HalfVector2 | PixelTypes.Rgba32;
IEnumerable<KeyValuePair<PixelTypes, Type>> expanded = pixelTypes.ExpandAllTypes();
Assert.Equal(4, expanded.Count());
AssertContainsPixelType<Alpha8>(PixelTypes.Alpha8, expanded);
AssertContainsPixelType<A8>(PixelTypes.A8, expanded);
AssertContainsPixelType<Bgr565>(PixelTypes.Bgr565, expanded);
AssertContainsPixelType<HalfVector2>(PixelTypes.HalfVector2, expanded);
AssertContainsPixelType<Rgba32>(PixelTypes.Rgba32, expanded);

Loading…
Cancel
Save