From b0f6b73faaaf304e47dec9e58ca6be90b2e740bc Mon Sep 17 00:00:00 2001
From: Brian Popow <38701097+brianpopow@users.noreply.github.com>
Date: Fri, 3 May 2019 17:10:40 +0200
Subject: [PATCH] Add support for encoding 16 bit per pixel bitmaps (#899)
* Implemented encoding of 16 bits per pixel bitmaps
* Add unit tests for 16 bit encoding and Bgra5551 conversion
* Add additional Bgra5551 pixel conversion tests
* Add Bgra5551 tests for Short2/4 and HalfVector2/4
* Use scaled vector conversion
---
src/ImageSharp/Formats/Bmp/BmpBitsPerPixel.cs | 5 +
src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs | 3 +-
src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs | 30 ++++
.../Formats/Bmp/IBmpEncoderOptions.cs | 2 +-
src/ImageSharp/PixelFormats/IPixel.cs | 6 +
.../PixelImplementations/Alpha8.cs | 4 +
.../PixelImplementations/Argb32.cs | 4 +
.../PixelImplementations/Bgr24.cs | 4 +
.../PixelImplementations/Bgr565.cs | 4 +
.../PixelImplementations/Bgra32.cs | 4 +
.../PixelImplementations/Bgra4444.cs | 4 +
.../PixelImplementations/Bgra5551.cs | 4 +
.../PixelImplementations/Byte4.cs | 4 +
.../PixelImplementations/Gray16.cs | 4 +
.../PixelImplementations/Gray8.cs | 4 +
.../PixelImplementations/HalfSingle.cs | 4 +
.../PixelImplementations/HalfVector2.cs | 4 +
.../PixelImplementations/HalfVector4.cs | 4 +
.../PixelImplementations/NormalizedByte2.cs | 11 +-
.../PixelImplementations/NormalizedByte4.cs | 4 +
.../PixelImplementations/NormalizedShort2.cs | 4 +
.../PixelImplementations/NormalizedShort4.cs | 4 +
.../PixelFormats/PixelImplementations/Rg32.cs | 4 +
.../PixelImplementations/Rgb24.cs | 4 +
.../PixelImplementations/Rgb48.cs | 4 +
.../PixelImplementations/Rgba1010102.cs | 4 +
.../PixelImplementations/Rgba32.cs | 4 +
.../PixelImplementations/Rgba64.cs | 6 +-
.../PixelImplementations/RgbaVector.cs | 9 +-
.../PixelImplementations/Short2.cs | 9 +-
.../PixelImplementations/Short4.cs | 4 +
.../PixelOperations{TPixel}.Generated.cs | 72 ++++++++++
.../PixelOperations{TPixel}.Generated.tt | 3 +
.../Formats/Bmp/BmpDecoderTests.cs | 2 +-
.../Formats/Bmp/BmpEncoderTests.cs | 17 ++-
.../PixelFormats/Alpha8Tests.cs | 14 ++
.../PixelFormats/Argb32Tests.cs | 14 ++
.../PixelFormats/Bgr24Tests.cs | 15 ++
.../PixelFormats/Bgr565Tests.cs | 14 ++
.../PixelFormats/Bgra32Tests.cs | 14 ++
.../PixelFormats/Bgra4444Tests.cs | 14 ++
.../PixelFormats/Bgra5551Tests.cs | 129 +++++++++++++++++-
.../PixelFormats/Byte4Tests.cs | 14 ++
.../PixelFormats/Gray16Tests.cs | 14 ++
.../PixelFormats/Gray8Tests.cs | 14 ++
.../PixelFormats/HalfVector2Tests.cs | 17 +++
.../PixelFormats/HalfVector4Tests.cs | 14 ++
.../PixelFormats/NormalizedByte2Tests.cs | 14 ++
.../PixelFormats/NormalizedByte4Tests.cs | 14 ++
.../PixelFormats/NormalizedShort2Tests.cs | 14 ++
.../PixelFormats/NormalizedShort4Tests.cs | 14 ++
.../PixelFormats/Rg32Tests.cs | 14 ++
.../PixelFormats/Rgb24Tests.cs | 22 ++-
.../PixelFormats/Rgb48Tests.cs | 16 +++
.../PixelFormats/Rgba1010102Tests.cs | 14 ++
.../PixelFormats/Rgba32Tests.cs | 14 ++
.../PixelFormats/Rgba64Tests.cs | 17 +++
.../PixelFormats/Short2Tests.cs | 17 +++
.../PixelFormats/Short4Tests.cs | 14 ++
tests/ImageSharp.Tests/TestImages.cs | 1 +
.../TestUtilities/PixelTypes.cs | 2 +
tests/Images/Input/Bmp/rgb16.bmp | Bin 0 -> 16438 bytes
62 files changed, 712 insertions(+), 25 deletions(-)
create mode 100644 tests/Images/Input/Bmp/rgb16.bmp
diff --git a/src/ImageSharp/Formats/Bmp/BmpBitsPerPixel.cs b/src/ImageSharp/Formats/Bmp/BmpBitsPerPixel.cs
index 618999c87..38f5c1d66 100644
--- a/src/ImageSharp/Formats/Bmp/BmpBitsPerPixel.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpBitsPerPixel.cs
@@ -8,6 +8,11 @@ namespace SixLabors.ImageSharp.Formats.Bmp
///
public enum BmpBitsPerPixel : short
{
+ ///
+ /// 16 bits per pixel. Each pixel consists of 2 bytes.
+ ///
+ Pixel16 = 16,
+
///
/// 24 bits per pixel. Each pixel consists of 3 bytes.
///
diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
index b52c3754e..9d9c7b624 100644
--- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
@@ -1022,7 +1022,8 @@ namespace SixLabors.ImageSharp.Formats.Bmp
this.bmpMetadata.InfoHeaderType = infoHeaderType;
// We can only encode at these bit rates so far.
- if (bitsPerPixel.Equals((short)BmpBitsPerPixel.Pixel24)
+ if (bitsPerPixel.Equals((short)BmpBitsPerPixel.Pixel16)
+ || bitsPerPixel.Equals((short)BmpBitsPerPixel.Pixel24)
|| bitsPerPixel.Equals((short)BmpBitsPerPixel.Pixel32))
{
this.bmpMetadata.BitsPerPixel = (BmpBitsPerPixel)bitsPerPixel;
diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs
index c4c51b78e..82483e390 100644
--- a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs
+++ b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs
@@ -194,6 +194,10 @@ namespace SixLabors.ImageSharp.Formats.Bmp
case BmpBitsPerPixel.Pixel24:
this.Write24Bit(stream, pixels);
break;
+
+ case BmpBitsPerPixel.Pixel16:
+ this.Write16Bit(stream, pixels);
+ break;
}
}
@@ -246,5 +250,31 @@ namespace SixLabors.ImageSharp.Formats.Bmp
}
}
}
+
+ ///
+ /// Writes the 16bit color palette to the stream.
+ ///
+ /// The type of the pixel.
+ /// The to write to.
+ /// The containing pixel data.
+ private void Write16Bit(Stream stream, Buffer2D pixels)
+ where TPixel : struct, IPixel
+ {
+ using (IManagedByteBuffer row = this.AllocateRow(pixels.Width, 2))
+ {
+ for (int y = pixels.Height - 1; y >= 0; y--)
+ {
+ Span pixelSpan = pixels.GetRowSpan(y);
+
+ PixelOperations.Instance.ToBgra5551Bytes(
+ this.configuration,
+ pixelSpan,
+ row.GetSpan(),
+ pixelSpan.Length);
+
+ stream.Write(row.Array, 0, row.Length());
+ }
+ }
+ }
}
}
diff --git a/src/ImageSharp/Formats/Bmp/IBmpEncoderOptions.cs b/src/ImageSharp/Formats/Bmp/IBmpEncoderOptions.cs
index a3a056bfa..96ec423e7 100644
--- a/src/ImageSharp/Formats/Bmp/IBmpEncoderOptions.cs
+++ b/src/ImageSharp/Formats/Bmp/IBmpEncoderOptions.cs
@@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
///
/// Configuration options for use during bmp encoding
///
- /// The encoder can currently only write 24-bit and 32-bit rgb images to streams.
+ /// The encoder can currently only write 16-bit, 24-bit and 32-bit rgb images to streams.
internal interface IBmpEncoderOptions
{
///
diff --git a/src/ImageSharp/PixelFormats/IPixel.cs b/src/ImageSharp/PixelFormats/IPixel.cs
index 127740686..21ec2a3fd 100644
--- a/src/ImageSharp/PixelFormats/IPixel.cs
+++ b/src/ImageSharp/PixelFormats/IPixel.cs
@@ -61,6 +61,12 @@ namespace SixLabors.ImageSharp.PixelFormats
/// The value.
void FromArgb32(Argb32 source);
+ ///
+ /// Initializes the pixel instance from an value.
+ ///
+ /// The value.
+ void FromBgra5551(Bgra5551 source);
+
///
/// Initializes the pixel instance from an value.
///
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Alpha8.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Alpha8.cs
index 75b7ede82..cd864b545 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Alpha8.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Alpha8.cs
@@ -87,6 +87,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source) => this.PackedValue = source.A;
+ ///
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());
+
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromGray8(Gray8 source) => this.PackedValue = byte.MaxValue;
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs
index 8fc301631..075df01cd 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Argb32.cs
@@ -187,6 +187,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromArgb32(Argb32 source) => this.PackedValue = source.PackedValue;
+ ///
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());
+
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgr24(Bgr24 source)
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs
index 96ff7da6f..3ba6436a0 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr24.cs
@@ -109,6 +109,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgr24(Bgr24 source) => this = source;
+ ///
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());
+
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source)
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs
index a2e4dc880..9e42de388 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgr565.cs
@@ -87,6 +87,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromArgb32(Argb32 source) => this.FromVector4(source.ToVector4());
+ ///
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public void FromBgra5551(Bgra5551 source) => this.FromVector4(source.ToVector4());
+
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgr24(Bgr24 source) => this.FromScaledVector4(source.ToScaledVector4());
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs
index 1d156222f..758be8043 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra32.cs
@@ -159,6 +159,10 @@ namespace SixLabors.ImageSharp.PixelFormats
this.A = byte.MaxValue;
}
+ ///
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());
+
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source) => this = source;
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs
index 110b51822..6fcac6291 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra4444.cs
@@ -90,6 +90,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromArgb32(Argb32 source) => this.FromScaledVector4(source.ToScaledVector4());
+ ///
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());
+
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgr24(Bgr24 source) => this.FromScaledVector4(source.ToScaledVector4());
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs
index dcfb25a64..abb3eb19e 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Bgra5551.cs
@@ -87,6 +87,10 @@ namespace SixLabors.ImageSharp.PixelFormats
(this.PackedValue >> 15) & 0x01);
}
+ ///
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public void FromBgra5551(Bgra5551 source) => this = source;
+
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromArgb32(Argb32 source) => this.FromScaledVector4(source.ToScaledVector4());
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs
index 43a03dc5d..a07cd5213 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Byte4.cs
@@ -111,6 +111,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgb24(Rgb24 source) => this.FromScaledVector4(source.ToScaledVector4());
+ ///
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());
+
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgba32(Rgba32 source) => this.FromScaledVector4(source.ToScaledVector4());
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Gray16.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Gray16.cs
index 2e98a28ad..6fce1c757 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Gray16.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Gray16.cs
@@ -106,6 +106,10 @@ namespace SixLabors.ImageSharp.PixelFormats
ImageMaths.UpscaleFrom8BitTo16Bit(source.B));
}
+ ///
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());
+
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromGray8(Gray8 source) => this.PackedValue = ImageMaths.UpscaleFrom8BitTo16Bit(source.PackedValue);
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Gray8.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Gray8.cs
index 512bee39d..1c278b434 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Gray8.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Gray8.cs
@@ -97,6 +97,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source) => this.PackedValue = ImageMaths.Get8BitBT709Luminance(source.R, source.G, source.B);
+ ///
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());
+
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromGray8(Gray8 source) => this.PackedValue = source.PackedValue;
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs b/src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs
index 8323cf3e8..580cc5399 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/HalfSingle.cs
@@ -88,6 +88,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4());
+ ///
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());
+
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromGray8(Gray8 source) => this.FromScaledVector4(source.ToScaledVector4());
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs
index cb915459b..e2ed931b7 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector2.cs
@@ -99,6 +99,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4());
+ ///
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());
+
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromGray8(Gray8 source) => this.FromScaledVector4(source.ToScaledVector4());
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs
index 9f60ca8c7..3b30ebd1e 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/HalfVector4.cs
@@ -107,6 +107,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4());
+ ///
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());
+
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromGray8(Gray8 source) => this.FromScaledVector4(source.ToScaledVector4());
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs
index d39cfd402..cd95e87ec 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte2.cs
@@ -8,7 +8,7 @@ using System.Runtime.CompilerServices;
namespace SixLabors.ImageSharp.PixelFormats
{
///
- /// Packed packed pixel type containing two 8-bit signed normalized values, ranging from −1 to 1.
+ /// Packed pixel type containing two 8-bit signed normalized values, ranging from −1 to 1.
///
/// Ranges from [-1, -1, 0, 1] to [1, 1, 0, 1] in vector form.
///
@@ -107,10 +107,11 @@ namespace SixLabors.ImageSharp.PixelFormats
///
[MethodImpl(InliningOptions.ShortMethod)]
- public void ToRgba32(ref Rgba32 dest)
- {
- dest.FromScaledVector4(this.ToScaledVector4());
- }
+ public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());
+
+ ///
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public void ToRgba32(ref Rgba32 dest) => dest.FromScaledVector4(this.ToScaledVector4());
///
[MethodImpl(InliningOptions.ShortMethod)]
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs
index 8a9368463..73a3d3262 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedByte4.cs
@@ -110,6 +110,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4());
+ ///
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());
+
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromGray8(Gray8 source) => this.FromScaledVector4(source.ToScaledVector4());
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs
index b9cab1e7d..8d7c400b4 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort2.cs
@@ -105,6 +105,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4());
+ ///
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());
+
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromGray8(Gray8 source) => this.FromScaledVector4(source.ToScaledVector4());
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs
index 3bc74e6c6..453b1c1b7 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/NormalizedShort4.cs
@@ -112,6 +112,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4());
+ ///
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());
+
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromGray8(Gray8 source) => this.FromScaledVector4(source.ToScaledVector4());
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rg32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rg32.cs
index 6dc623518..0411f8f3e 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Rg32.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rg32.cs
@@ -93,6 +93,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4());
+ ///
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());
+
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromGray8(Gray8 source) => this.FromScaledVector4(source.ToScaledVector4());
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs
index 86565731d..1255f66d1 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb24.cs
@@ -156,6 +156,10 @@ namespace SixLabors.ImageSharp.PixelFormats
this.B = rgb;
}
+ ///
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());
+
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgb24(Rgb24 source) => this = source;
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs
index eda116a46..f59036ec7 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgb48.cs
@@ -126,6 +126,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromRgba64(Rgba64 source) => this = source.Rgb;
+ ///
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());
+
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromGray8(Gray8 source)
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs
index 895added1..38f61d56c 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba1010102.cs
@@ -99,6 +99,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4());
+ ///
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());
+
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromGray8(Gray8 source) => this.FromScaledVector4(source.ToScaledVector4());
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs
index 5a16704ef..7367c4463 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba32.cs
@@ -266,6 +266,10 @@ namespace SixLabors.ImageSharp.PixelFormats
this.A = source.A;
}
+ ///
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());
+
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromGray8(Gray8 source)
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs
index 5ae5492e2..87d1b235b 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Rgba64.cs
@@ -9,7 +9,7 @@ using System.Runtime.InteropServices;
namespace SixLabors.ImageSharp.PixelFormats
{
///
- /// Packed pixel type containing four 16-bit unsigned normalized values ranging from 0 to 635535.
+ /// Packed pixel type containing four 16-bit unsigned normalized values ranging from 0 to 65535.
///
/// Ranges from [0, 0, 0, 0] to [1, 1, 1, 1] in vector form.
///
@@ -154,6 +154,10 @@ namespace SixLabors.ImageSharp.PixelFormats
this.A = ImageMaths.UpscaleFrom8BitTo16Bit(source.A);
}
+ ///
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());
+
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromGray8(Gray8 source)
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs b/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs
index d65a5ade7..96003cc5b 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/RgbaVector.cs
@@ -134,6 +134,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4());
+ ///
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());
+
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromGray8(Gray8 source) => this.FromScaledVector4(source.ToScaledVector4());
@@ -152,10 +156,7 @@ namespace SixLabors.ImageSharp.PixelFormats
///
[MethodImpl(InliningOptions.ShortMethod)]
- public void ToRgba32(ref Rgba32 dest)
- {
- dest.FromScaledVector4(this.ToScaledVector4());
- }
+ public void ToRgba32(ref Rgba32 dest) => dest.FromScaledVector4(this.ToScaledVector4());
///
[MethodImpl(InliningOptions.ShortMethod)]
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs
index 96fe15ed6..803a77b23 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Short2.cs
@@ -111,6 +111,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4());
+ ///
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());
+
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromGray8(Gray8 source) => this.FromScaledVector4(source.ToScaledVector4());
@@ -129,10 +133,7 @@ namespace SixLabors.ImageSharp.PixelFormats
///
[MethodImpl(InliningOptions.ShortMethod)]
- public void ToRgba32(ref Rgba32 dest)
- {
- dest.FromScaledVector4(this.ToScaledVector4());
- }
+ public void ToRgba32(ref Rgba32 dest) => dest.FromScaledVector4(this.ToScaledVector4());
///
[MethodImpl(InliningOptions.ShortMethod)]
diff --git a/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs b/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs
index d224f8eb4..c52b29347 100644
--- a/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs
+++ b/src/ImageSharp/PixelFormats/PixelImplementations/Short4.cs
@@ -116,6 +116,10 @@ namespace SixLabors.ImageSharp.PixelFormats
[MethodImpl(InliningOptions.ShortMethod)]
public void FromBgra32(Bgra32 source) => this.FromScaledVector4(source.ToScaledVector4());
+ ///
+ [MethodImpl(InliningOptions.ShortMethod)]
+ public void FromBgra5551(Bgra5551 source) => this.FromScaledVector4(source.ToScaledVector4());
+
///
[MethodImpl(InliningOptions.ShortMethod)]
public void FromGray8(Gray8 source) => this.FromScaledVector4(source.ToScaledVector4());
diff --git a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs
index 207a8767d..700281992 100644
--- a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs
+++ b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.cs
@@ -657,5 +657,77 @@ namespace SixLabors.ImageSharp.PixelFormats
{
this.ToRgba64(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes));
}
+
+ ///
+ /// Converts all pixels in 'source` span of into a span of -s.
+ ///
+ /// A to configure internal operations
+ /// The source of data.
+ /// The to the destination pixels.
+ internal virtual void FromBgra5551(Configuration configuration, ReadOnlySpan source, Span destPixels)
+ {
+ Guard.DestinationShouldNotBeTooShort(source, destPixels, nameof(destPixels));
+
+ ref Bgra5551 sourceBaseRef = ref MemoryMarshal.GetReference(source);
+ ref TPixel destBaseRef = ref MemoryMarshal.GetReference(destPixels);
+
+ for (int i = 0; i < source.Length; i++)
+ {
+ ref Bgra5551 sp = ref Unsafe.Add(ref sourceBaseRef, i);
+ ref TPixel dp = ref Unsafe.Add(ref destBaseRef, i);
+
+ dp.FromBgra5551(sp);
+ }
+ }
+
+ ///
+ /// A helper for that expects a byte span.
+ /// The layout of the data in 'sourceBytes' must be compatible with layout.
+ ///
+ /// A to configure internal operations
+ /// The to the source bytes.
+ /// The to the destination pixels.
+ /// The number of pixels to convert.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ internal void FromBgra5551Bytes(Configuration configuration, ReadOnlySpan sourceBytes, Span destPixels, int count)
+ {
+ this.FromBgra5551(configuration, MemoryMarshal.Cast(sourceBytes).Slice(0, count), destPixels);
+ }
+
+ ///
+ /// Converts all pixels of the 'sourcePixels` span to a span of -s.
+ ///
+ /// A to configure internal operations
+ /// The span of source pixels
+ /// The destination span of data.
+ internal virtual void ToBgra5551(Configuration configuration, ReadOnlySpan sourcePixels, Span destPixels)
+ {
+ Guard.DestinationShouldNotBeTooShort(sourcePixels, destPixels, nameof(destPixels));
+
+ ref TPixel sourceBaseRef = ref MemoryMarshal.GetReference(sourcePixels);
+ ref Bgra5551 destBaseRef = ref MemoryMarshal.GetReference(destPixels);
+
+ for (int i = 0; i < sourcePixels.Length; i++)
+ {
+ ref TPixel sp = ref Unsafe.Add(ref sourceBaseRef, i);
+ ref Bgra5551 dp = ref Unsafe.Add(ref destBaseRef, i);
+
+ dp.FromScaledVector4(sp.ToScaledVector4());
+ }
+ }
+
+ ///
+ /// A helper for that expects a byte span as destination.
+ /// The layout of the data in 'destBytes' must be compatible with layout.
+ ///
+ /// A to configure internal operations
+ /// The to the source pixels.
+ /// The to the destination bytes.
+ /// The number of pixels to convert.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ internal void ToBgra5551Bytes(Configuration configuration, ReadOnlySpan sourcePixels, Span destBytes, int count)
+ {
+ this.ToBgra5551(configuration, sourcePixels.Slice(0, count), MemoryMarshal.Cast(destBytes));
+ }
}
}
\ No newline at end of file
diff --git a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt
index 8579423b3..860301232 100644
--- a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt
+++ b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.Generated.tt
@@ -136,5 +136,8 @@ namespace SixLabors.ImageSharp.PixelFormats
GenerateFromMethods("Rgba64");
GenerateToDestFormatMethods("Rgba64");
+ GenerateFromMethods("Bgra5551");
+ GenerateToDestFormatMethods("Bgra5551");
+
#> }
}
\ No newline at end of file
diff --git a/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs
index 5f3cc7db4..e615dbe56 100644
--- a/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs
+++ b/tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs
@@ -11,7 +11,7 @@ using Xunit;
// ReSharper disable InconsistentNaming
-namespace SixLabors.ImageSharp.Tests
+namespace SixLabors.ImageSharp.Tests.Formats.Bmp
{
using SixLabors.ImageSharp.Metadata;
using static TestImages.Bmp;
diff --git a/tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs
index c7558ab42..7e054734e 100644
--- a/tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs
+++ b/tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs
@@ -6,10 +6,11 @@ using SixLabors.ImageSharp.Formats.Bmp;
using SixLabors.ImageSharp.Metadata;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
+
using Xunit;
using Xunit.Abstractions;
-namespace SixLabors.ImageSharp.Tests
+namespace SixLabors.ImageSharp.Tests.Formats.Bmp
{
using static TestImages.Bmp;
@@ -25,16 +26,16 @@ namespace SixLabors.ImageSharp.Tests
public static readonly TheoryData RatioFiles =
new TheoryData
{
- { TestImages.Bmp.Car, 3780, 3780 , PixelResolutionUnit.PixelsPerMeter },
- { TestImages.Bmp.V5Header, 3780, 3780 , PixelResolutionUnit.PixelsPerMeter },
- { TestImages.Bmp.RLE8, 2835, 2835, PixelResolutionUnit.PixelsPerMeter }
+ { Car, 3780, 3780 , PixelResolutionUnit.PixelsPerMeter },
+ { V5Header, 3780, 3780 , PixelResolutionUnit.PixelsPerMeter },
+ { RLE8, 2835, 2835, PixelResolutionUnit.PixelsPerMeter }
};
public static readonly TheoryData BmpBitsPerPixelFiles =
new TheoryData
{
- { TestImages.Bmp.Car, BmpBitsPerPixel.Pixel24 },
- { TestImages.Bmp.Bit32Rgb, BmpBitsPerPixel.Pixel32 }
+ { Car, BmpBitsPerPixel.Pixel24 },
+ { Bit32Rgb, BmpBitsPerPixel.Pixel32 }
};
public BmpEncoderTests(ITestOutputHelper output) => this.Output = output;
@@ -111,6 +112,8 @@ namespace SixLabors.ImageSharp.Tests
[WithFile(WinBmpv5, PixelTypes.Rgba32 | PixelTypes.Rgb24, BmpBitsPerPixel.Pixel32)]
// WinBmpv3 is a 24 bits per pixel image
[WithFile(WinBmpv3, PixelTypes.Rgb24, BmpBitsPerPixel.Pixel24)]
+ [WithFile(Rgb16, PixelTypes.Bgra5551, BmpBitsPerPixel.Pixel16)]
+ [WithFile(Bit16, PixelTypes.Bgra5551, BmpBitsPerPixel.Pixel16)]
public void Encode_WithV3Header_Works(TestImageProvider provider, BmpBitsPerPixel bitsPerPixel)
// if supportTransparency is false, a v3 bitmap header will be written
where TPixel : struct, IPixel => TestBmpEncoderCore(provider, bitsPerPixel, supportTransparency: false);
@@ -121,6 +124,8 @@ namespace SixLabors.ImageSharp.Tests
[WithFile(WinBmpv4, PixelTypes.Rgba32 | PixelTypes.Rgb24, BmpBitsPerPixel.Pixel32)]
[WithFile(WinBmpv5, PixelTypes.Rgba32 | PixelTypes.Rgb24, BmpBitsPerPixel.Pixel32)]
[WithFile(WinBmpv3, PixelTypes.Rgb24, BmpBitsPerPixel.Pixel24)]
+ [WithFile(Rgb16, PixelTypes.Bgra5551, BmpBitsPerPixel.Pixel16)]
+ [WithFile(Bit16, PixelTypes.Bgra5551, BmpBitsPerPixel.Pixel16)]
public void Encode_WithV4Header_Works(TestImageProvider provider, BmpBitsPerPixel bitsPerPixel)
where TPixel : struct, IPixel => TestBmpEncoderCore(provider, bitsPerPixel, supportTransparency: true);
diff --git a/tests/ImageSharp.Tests/PixelFormats/Alpha8Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Alpha8Tests.cs
index 8f68c9d03..b6e87626b 100644
--- a/tests/ImageSharp.Tests/PixelFormats/Alpha8Tests.cs
+++ b/tests/ImageSharp.Tests/PixelFormats/Alpha8Tests.cs
@@ -94,5 +94,19 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
input.ToRgba32(ref actual);
Assert.Equal(expected, actual);
}
+
+ [Fact]
+ public void Alpha8_FromBgra5551()
+ {
+ // arrange
+ var alpha = default(Alpha8);
+ byte expected = byte.MaxValue;
+
+ // act
+ alpha.FromBgra5551(new Bgra5551(0.0f, 0.0f, 0.0f, 1.0f));
+
+ // assert
+ Assert.Equal(expected, alpha.PackedValue);
+ }
}
}
diff --git a/tests/ImageSharp.Tests/PixelFormats/Argb32Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Argb32Tests.cs
index b9f741490..4f3394e69 100644
--- a/tests/ImageSharp.Tests/PixelFormats/Argb32Tests.cs
+++ b/tests/ImageSharp.Tests/PixelFormats/Argb32Tests.cs
@@ -60,6 +60,20 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
Assert.Equal(expected, actual);
}
+ [Fact]
+ public void Argb32_FromBgra5551()
+ {
+ // arrange
+ var argb = default(Argb32);
+ uint expected = uint.MaxValue;
+
+ // act
+ argb.FromBgra5551(new Bgra5551(1.0f, 1.0f, 1.0f, 1.0f));
+
+ // assert
+ Assert.Equal(expected, argb.PackedValue);
+ }
+
[Fact]
public void Argb32_Clamping()
{
diff --git a/tests/ImageSharp.Tests/PixelFormats/Bgr24Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Bgr24Tests.cs
index 2295fbe56..f145e6928 100644
--- a/tests/ImageSharp.Tests/PixelFormats/Bgr24Tests.cs
+++ b/tests/ImageSharp.Tests/PixelFormats/Bgr24Tests.cs
@@ -95,5 +95,20 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
Assert.Equal(Vec(1, 2, 3), rgb.ToVector4());
}
+
+ [Fact]
+ public void Bgr24_FromBgra5551()
+ {
+ // arrange
+ var bgr = default(Bgr24);
+
+ // act
+ bgr.FromBgra5551(new Bgra5551(1.0f, 1.0f, 1.0f, 1.0f));
+
+ // assert
+ Assert.Equal(255, bgr.R);
+ Assert.Equal(255, bgr.G);
+ Assert.Equal(255, bgr.B);
+ }
}
}
\ No newline at end of file
diff --git a/tests/ImageSharp.Tests/PixelFormats/Bgr565Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Bgr565Tests.cs
index 967e358e1..4419fe898 100644
--- a/tests/ImageSharp.Tests/PixelFormats/Bgr565Tests.cs
+++ b/tests/ImageSharp.Tests/PixelFormats/Bgr565Tests.cs
@@ -63,6 +63,20 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
Assert.Equal(expected, actual);
}
+ [Fact]
+ public void Bgr565_FromBgra5551()
+ {
+ // arrange
+ var bgr = default(Bgr565);
+ ushort expected = ushort.MaxValue;
+
+ // act
+ bgr.FromBgra5551(new Bgra5551(1.0f, 1.0f, 1.0f, 1.0f));
+
+ // assert
+ Assert.Equal(expected, bgr.PackedValue);
+ }
+
[Fact]
public void Bgr565_Clamping()
{
diff --git a/tests/ImageSharp.Tests/PixelFormats/Bgra32Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Bgra32Tests.cs
index a5c53ed8b..171a3dfa0 100644
--- a/tests/ImageSharp.Tests/PixelFormats/Bgra32Tests.cs
+++ b/tests/ImageSharp.Tests/PixelFormats/Bgra32Tests.cs
@@ -102,5 +102,19 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
Assert.Equal(Vec(1, 2, 3, 4), rgb.ToVector4());
}
+
+ [Fact]
+ public void Bgra32_FromBgra5551()
+ {
+ // arrange
+ var bgra = default(Bgra32);
+ uint expected = uint.MaxValue;
+
+ // act
+ bgra.FromBgra5551(new Bgra5551(1.0f, 1.0f, 1.0f, 1.0f));
+
+ // assert
+ Assert.Equal(expected, bgra.PackedValue);
+ }
}
}
\ No newline at end of file
diff --git a/tests/ImageSharp.Tests/PixelFormats/Bgra4444Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Bgra4444Tests.cs
index 8b56ec19f..b6019016c 100644
--- a/tests/ImageSharp.Tests/PixelFormats/Bgra4444Tests.cs
+++ b/tests/ImageSharp.Tests/PixelFormats/Bgra4444Tests.cs
@@ -64,6 +64,20 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
Assert.Equal(expected, actual);
}
+ [Fact]
+ public void Bgra4444_FromBgra5551()
+ {
+ // arrange
+ var bgra = default(Bgra4444);
+ ushort expected = ushort.MaxValue;
+
+ // act
+ bgra.FromBgra5551(new Bgra5551(1.0f, 1.0f, 1.0f, 1.0f));
+
+ // assert
+ Assert.Equal(expected, bgra.PackedValue);
+ }
+
[Fact]
public void Bgra4444_Clamping()
{
diff --git a/tests/ImageSharp.Tests/PixelFormats/Bgra5551Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Bgra5551Tests.cs
index 76edee8a7..f5abca59a 100644
--- a/tests/ImageSharp.Tests/PixelFormats/Bgra5551Tests.cs
+++ b/tests/ImageSharp.Tests/PixelFormats/Bgra5551Tests.cs
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
+using System;
using System.Numerics;
using SixLabors.ImageSharp.PixelFormats;
using Xunit;
@@ -18,6 +19,13 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
float w = 0x1;
Assert.Equal(0xeacd, new Bgra5551(x / 0x1f, y / 0x1f, z / 0x1f, w).PackedValue);
Assert.Equal(3088, new Bgra5551(0.1f, -0.3f, 0.5f, -0.7f).PackedValue);
+
+ Assert.Equal(0xFFFF, new Bgra5551(Vector4.One).PackedValue);
+ Assert.Equal(0x7C00, new Bgra5551(Vector4.UnitX).PackedValue);
+ Assert.Equal(0x03E0, new Bgra5551(Vector4.UnitY).PackedValue);
+ Assert.Equal(0x001F, new Bgra5551(Vector4.UnitZ).PackedValue);
+ Assert.Equal(0x8000, new Bgra5551(Vector4.UnitW).PackedValue);
+
// Test the limits.
Assert.Equal(0x0, new Bgra5551(Vector4.Zero).PackedValue);
Assert.Equal(0xFFFF, new Bgra5551(Vector4.One).PackedValue);
@@ -53,7 +61,6 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
Vector4 scaled = new Bgra5551(Vector4.One).ToScaledVector4();
int expected = 0xFFFF;
var pixel = default(Bgra5551);
- pixel.FromScaledVector4(scaled);
// act
pixel.FromScaledVector4(scaled);
@@ -63,6 +70,126 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
Assert.Equal(expected, actual);
}
+ [Fact]
+ public void Bgra5551_FromRgba32()
+ {
+ // arrange
+ var bgra1 = default(Bgra5551);
+ var bgra2 = default(Bgra5551);
+ ushort expectedPackedValue1 = ushort.MaxValue;
+ ushort expectedPackedValue2 = 0xFC1F;
+
+ // act
+ bgra1.FromRgba32(new Rgba32(255, 255, 255, 255));
+ bgra2.FromRgba32(new Rgba32(255, 0, 255, 255));
+
+ // assert
+ Assert.Equal(expectedPackedValue1, bgra1.PackedValue);
+ Assert.Equal(expectedPackedValue2, bgra2.PackedValue);
+ }
+
+ [Fact]
+ public void Bgra5551_FromBgra32()
+ {
+ // arrange
+ var bgra1 = default(Bgra5551);
+ var bgra2 = default(Bgra5551);
+ ushort expectedPackedValue1 = ushort.MaxValue;
+ ushort expectedPackedValue2 = 0xFC1F;
+
+ // act
+ bgra1.FromBgra32(new Bgra32(255, 255, 255, 255));
+ bgra2.FromBgra32(new Bgra32(255, 0, 255, 255));
+
+ // assert
+ Assert.Equal(expectedPackedValue1, bgra1.PackedValue);
+ Assert.Equal(expectedPackedValue2, bgra2.PackedValue);
+ }
+
+ [Fact]
+ public void Bgra5551_FromArgb32()
+ {
+ // arrange
+ var bgra = default(Bgra5551);
+ ushort expectedPackedValue = ushort.MaxValue;
+
+ // act
+ bgra.FromArgb32(new Argb32(255, 255, 255, 255));
+
+ // assert
+ Assert.Equal(expectedPackedValue, bgra.PackedValue);
+ }
+
+ [Fact]
+ public void Bgra5551_FromRgba64()
+ {
+ // arrange
+ var bgra = default(Bgra5551);
+ ushort expectedPackedValue = ushort.MaxValue;
+
+ // act
+ bgra.FromRgba64(new Rgba64(ushort.MaxValue, ushort.MaxValue, ushort.MaxValue, ushort.MaxValue));
+
+ // assert
+ Assert.Equal(expectedPackedValue, bgra.PackedValue);
+ }
+
+ [Fact]
+ public void Bgra5551_FromGrey16()
+ {
+ // arrange
+ var bgra = default(Bgra5551);
+ ushort expectedPackedValue = ushort.MaxValue;
+
+ // act
+ bgra.FromGray16(new Gray16(ushort.MaxValue));
+
+ // assert
+ Assert.Equal(expectedPackedValue, bgra.PackedValue);
+ }
+
+ [Fact]
+ public void Bgra5551_FromGrey8()
+ {
+ // arrange
+ var bgra = default(Bgra5551);
+ ushort expectedPackedValue = ushort.MaxValue;
+
+ // act
+ bgra.FromGray8(new Gray8(byte.MaxValue));
+
+ // assert
+ Assert.Equal(expectedPackedValue, bgra.PackedValue);
+ }
+
+ [Fact]
+ public void Bgra5551_FromBgr24()
+ {
+ // arrange
+ var bgra = default(Bgra5551);
+ ushort expectedPackedValue = ushort.MaxValue;
+
+ // act
+ bgra.FromBgr24(new Bgr24(byte.MaxValue, byte.MaxValue, byte.MaxValue));
+
+ // assert
+ Assert.Equal(expectedPackedValue, bgra.PackedValue);
+ }
+
+ [Fact]
+ public void Bgra5551_FromRgb24()
+ {
+ // arrange
+ var bgra = default(Bgra5551);
+ ushort expectedPackedValue = ushort.MaxValue;
+
+ // act
+ bgra.FromRgb24(new Rgb24(byte.MaxValue, byte.MaxValue, byte.MaxValue));
+
+ // assert
+ Assert.Equal(expectedPackedValue, bgra.PackedValue);
+ }
+
[Fact]
public void Bgra5551_Clamping()
{
diff --git a/tests/ImageSharp.Tests/PixelFormats/Byte4Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Byte4Tests.cs
index 8391ef25a..9174a6abd 100644
--- a/tests/ImageSharp.Tests/PixelFormats/Byte4Tests.cs
+++ b/tests/ImageSharp.Tests/PixelFormats/Byte4Tests.cs
@@ -61,6 +61,20 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
Assert.Equal(expected, actual);
}
+ [Fact]
+ public void Byte4_FromBgra5551()
+ {
+ // arrange
+ var rgb = default(Byte4);
+ uint expected = 0xFFFFFFFF;
+
+ // act
+ rgb.FromBgra5551(new Bgra5551(1.0f, 1.0f, 1.0f, 1.0f));
+
+ // assert
+ Assert.Equal(expected, rgb.PackedValue);
+ }
+
[Fact]
public void Byte4_Clamping()
{
diff --git a/tests/ImageSharp.Tests/PixelFormats/Gray16Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Gray16Tests.cs
index cb19c031d..01b60832e 100644
--- a/tests/ImageSharp.Tests/PixelFormats/Gray16Tests.cs
+++ b/tests/ImageSharp.Tests/PixelFormats/Gray16Tests.cs
@@ -126,5 +126,19 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
Assert.Equal(expected, actual.B);
Assert.Equal(byte.MaxValue, actual.A);
}
+
+ [Fact]
+ public void Gray16_FromBgra5551()
+ {
+ // arrange
+ var gray = default(Gray16);
+ ushort expected = ushort.MaxValue;
+
+ // act
+ gray.FromBgra5551(new Bgra5551(1.0f, 1.0f, 1.0f, 1.0f));
+
+ // assert
+ Assert.Equal(expected, gray.PackedValue);
+ }
}
}
diff --git a/tests/ImageSharp.Tests/PixelFormats/Gray8Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Gray8Tests.cs
index 1e17985e6..159f97cde 100644
--- a/tests/ImageSharp.Tests/PixelFormats/Gray8Tests.cs
+++ b/tests/ImageSharp.Tests/PixelFormats/Gray8Tests.cs
@@ -148,6 +148,20 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
Assert.Equal(byte.MaxValue, actual.A);
}
+ [Fact]
+ public void Gray8_FromBgra5551()
+ {
+ // arrange
+ var grey = default(Gray8);
+ byte expected = byte.MaxValue;
+
+ // act
+ grey.FromBgra5551(new Bgra5551(1.0f, 1.0f, 1.0f, 1.0f));
+
+ // assert
+ Assert.Equal(expected, grey.PackedValue);
+ }
+
public class Rgba32Compatibility
{
// ReSharper disable once MemberHidesStaticFromOuterClass
diff --git a/tests/ImageSharp.Tests/PixelFormats/HalfVector2Tests.cs b/tests/ImageSharp.Tests/PixelFormats/HalfVector2Tests.cs
index ccdd23e8f..57da5438c 100644
--- a/tests/ImageSharp.Tests/PixelFormats/HalfVector2Tests.cs
+++ b/tests/ImageSharp.Tests/PixelFormats/HalfVector2Tests.cs
@@ -71,5 +71,22 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
// assert
Assert.Equal(expected, actual);
}
+
+ [Fact]
+ public void HalfVector2_FromBgra5551()
+ {
+ // arrange
+ var halfVector2 = default(HalfVector2);
+
+ // act
+ halfVector2.FromBgra5551(new Bgra5551(1.0f, 1.0f, 1.0f, 1.0f));
+
+ // assert
+ Vector4 actual = halfVector2.ToScaledVector4();
+ Assert.Equal(1F, actual.X);
+ Assert.Equal(1F, actual.Y);
+ Assert.Equal(0, actual.Z);
+ Assert.Equal(1, actual.W);
+ }
}
}
diff --git a/tests/ImageSharp.Tests/PixelFormats/HalfVector4Tests.cs b/tests/ImageSharp.Tests/PixelFormats/HalfVector4Tests.cs
index c61dd97d2..ed1a0b720 100644
--- a/tests/ImageSharp.Tests/PixelFormats/HalfVector4Tests.cs
+++ b/tests/ImageSharp.Tests/PixelFormats/HalfVector4Tests.cs
@@ -65,5 +65,19 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
// assert
Assert.Equal(expected, actual);
}
+
+ [Fact]
+ public void HalfVector4_FromBgra5551()
+ {
+ // arrange
+ var halfVector4 = default(HalfVector4);
+ Vector4 expected = Vector4.One;
+
+ // act
+ halfVector4.FromBgra5551(new Bgra5551(1.0f, 1.0f, 1.0f, 1.0f));
+
+ // assert
+ Assert.Equal(expected, halfVector4.ToScaledVector4());
+ }
}
}
diff --git a/tests/ImageSharp.Tests/PixelFormats/NormalizedByte2Tests.cs b/tests/ImageSharp.Tests/PixelFormats/NormalizedByte2Tests.cs
index 506ebe0fe..1533f9cf9 100644
--- a/tests/ImageSharp.Tests/PixelFormats/NormalizedByte2Tests.cs
+++ b/tests/ImageSharp.Tests/PixelFormats/NormalizedByte2Tests.cs
@@ -66,5 +66,19 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
// assert
Assert.Equal(expected, actual);
}
+
+ [Fact]
+ public void NormalizedByte2_FromBgra5551()
+ {
+ // arrange
+ var normalizedByte2 = default(NormalizedByte2);
+ var expected = new Vector4(1, 1, 0, 1);
+
+ // act
+ normalizedByte2.FromBgra5551(new Bgra5551(1.0f, 1.0f, 1.0f, 1.0f));
+
+ // assert
+ Assert.Equal(expected, normalizedByte2.ToVector4());
+ }
}
}
diff --git a/tests/ImageSharp.Tests/PixelFormats/NormalizedByte4Tests.cs b/tests/ImageSharp.Tests/PixelFormats/NormalizedByte4Tests.cs
index 19a49e5d8..1cb404a00 100644
--- a/tests/ImageSharp.Tests/PixelFormats/NormalizedByte4Tests.cs
+++ b/tests/ImageSharp.Tests/PixelFormats/NormalizedByte4Tests.cs
@@ -60,5 +60,19 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
// assert
Assert.Equal(expected, actual);
}
+
+ [Fact]
+ public void NormalizedByte4_FromBgra5551()
+ {
+ // arrange
+ var normalizedByte4 = default(NormalizedByte4);
+ Vector4 expected = Vector4.One;
+
+ // act
+ normalizedByte4.FromBgra5551(new Bgra5551(1.0f, 1.0f, 1.0f, 1.0f));
+
+ // assert
+ Assert.Equal(expected, normalizedByte4.ToVector4());
+ }
}
}
diff --git a/tests/ImageSharp.Tests/PixelFormats/NormalizedShort2Tests.cs b/tests/ImageSharp.Tests/PixelFormats/NormalizedShort2Tests.cs
index 216ed4ad7..ff9350b70 100644
--- a/tests/ImageSharp.Tests/PixelFormats/NormalizedShort2Tests.cs
+++ b/tests/ImageSharp.Tests/PixelFormats/NormalizedShort2Tests.cs
@@ -69,5 +69,19 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
// assert
Assert.Equal(expected, actual);
}
+
+ [Fact]
+ public void NormalizedShort2_FromBgra5551()
+ {
+ // arrange
+ var normalizedShort2 = default(NormalizedShort2);
+ var expected = new Vector4(1, 1, 0, 1);
+
+ // act
+ normalizedShort2.FromBgra5551(new Bgra5551(1.0f, 1.0f, 1.0f, 1.0f));
+
+ // assert
+ Assert.Equal(expected, normalizedShort2.ToVector4());
+ }
}
}
diff --git a/tests/ImageSharp.Tests/PixelFormats/NormalizedShort4Tests.cs b/tests/ImageSharp.Tests/PixelFormats/NormalizedShort4Tests.cs
index d06d46d06..cea7e3146 100644
--- a/tests/ImageSharp.Tests/PixelFormats/NormalizedShort4Tests.cs
+++ b/tests/ImageSharp.Tests/PixelFormats/NormalizedShort4Tests.cs
@@ -61,5 +61,19 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
// assert
Assert.Equal(expected, actual);
}
+
+ [Fact]
+ public void NormalizedShort4_FromBgra5551()
+ {
+ // arrange
+ var normalizedShort4 = default(NormalizedShort4);
+ Vector4 expected = Vector4.One;
+
+ // act
+ normalizedShort4.FromBgra5551(new Bgra5551(1.0f, 1.0f, 1.0f, 1.0f));
+
+ // assert
+ Assert.Equal(expected, normalizedShort4.ToVector4());
+ }
}
}
diff --git a/tests/ImageSharp.Tests/PixelFormats/Rg32Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Rg32Tests.cs
index 46e5fbc3c..bccaaf816 100644
--- a/tests/ImageSharp.Tests/PixelFormats/Rg32Tests.cs
+++ b/tests/ImageSharp.Tests/PixelFormats/Rg32Tests.cs
@@ -62,6 +62,20 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
Assert.Equal(expected, actual);
}
+ [Fact]
+ public void Rg32_FromBgra5551()
+ {
+ // arrange
+ var rg32 = new Rg32(Vector2.One);
+ uint expected = 0xFFFFFFFF;
+
+ // act
+ rg32.FromBgra5551(new Bgra5551(1.0f, 1.0f, 1.0f, 1.0f));
+
+ // assert
+ Assert.Equal(expected, rg32.PackedValue);
+ }
+
[Fact]
public void Rg32_Clamping()
{
diff --git a/tests/ImageSharp.Tests/PixelFormats/Rgb24Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Rgb24Tests.cs
index 92e8d302d..df459422c 100644
--- a/tests/ImageSharp.Tests/PixelFormats/Rgb24Tests.cs
+++ b/tests/ImageSharp.Tests/PixelFormats/Rgb24Tests.cs
@@ -103,11 +103,31 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
[Fact]
public void ToRgba32()
{
+ // arrange
var rgb = new Rgb24(1, 2, 3);
Rgba32 rgba = default;
+ var expected = new Rgba32(1, 2, 3, 255);
+
+ // act
rgb.ToRgba32(ref rgba);
- Assert.Equal(new Rgba32(1, 2, 3, 255), rgba);
+ // assert
+ Assert.Equal(expected, rgba);
+ }
+
+ [Fact]
+ public void Rgb24_FromBgra5551()
+ {
+ // arrange
+ var rgb = new Rgb24(255, 255, 255);
+
+ // act
+ rgb.FromBgra5551(new Bgra5551(1.0f, 1.0f, 1.0f, 1.0f));
+
+ // assert
+ Assert.Equal(255, rgb.R);
+ Assert.Equal(255, rgb.G);
+ Assert.Equal(255, rgb.B);
}
}
}
\ No newline at end of file
diff --git a/tests/ImageSharp.Tests/PixelFormats/Rgb48Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Rgb48Tests.cs
index d30e49860..3bddc21ab 100644
--- a/tests/ImageSharp.Tests/PixelFormats/Rgb48Tests.cs
+++ b/tests/ImageSharp.Tests/PixelFormats/Rgb48Tests.cs
@@ -58,5 +58,21 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
// assert
Assert.Equal(expected, actual);
}
+
+ [Fact]
+ public void Rgb48_FromBgra5551()
+ {
+ // arrange
+ var rgb = default(Rgb48);
+ ushort expected = ushort.MaxValue;
+
+ // act
+ rgb.FromBgra5551(new Bgra5551(1.0f, 1.0f, 1.0f, 1.0f));
+
+ // assert
+ Assert.Equal(expected, rgb.R);
+ Assert.Equal(expected, rgb.G);
+ Assert.Equal(expected, rgb.B);
+ }
}
}
\ No newline at end of file
diff --git a/tests/ImageSharp.Tests/PixelFormats/Rgba1010102Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Rgba1010102Tests.cs
index a897dd4cd..0dbed2d2c 100644
--- a/tests/ImageSharp.Tests/PixelFormats/Rgba1010102Tests.cs
+++ b/tests/ImageSharp.Tests/PixelFormats/Rgba1010102Tests.cs
@@ -64,6 +64,20 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
Assert.Equal(expected, actual.PackedValue);
}
+ [Fact]
+ public void Rgba1010102_FromBgra5551()
+ {
+ // arrange
+ var rgba = new Rgba1010102(Vector4.One);
+ uint expected = 0xFFFFFFFF;
+
+ // act
+ rgba.FromBgra5551(new Bgra5551(1.0f, 1.0f, 1.0f, 1.0f));
+
+ // assert
+ Assert.Equal(expected, rgba.PackedValue);
+ }
+
[Fact]
public void Rgba1010102_Clamping()
{
diff --git a/tests/ImageSharp.Tests/PixelFormats/Rgba32Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Rgba32Tests.cs
index ad1d13740..275afa35d 100644
--- a/tests/ImageSharp.Tests/PixelFormats/Rgba32Tests.cs
+++ b/tests/ImageSharp.Tests/PixelFormats/Rgba32Tests.cs
@@ -276,5 +276,19 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
// assert
Assert.Equal(expected, actual);
}
+
+ [Fact]
+ public void Rgba32_FromBgra5551()
+ {
+ // arrange
+ var rgb = default(Rgba32);
+ uint expected = 0xFFFFFFFF;
+
+ // act
+ rgb.FromBgra5551(new Bgra5551(1.0f, 1.0f, 1.0f, 1.0f));
+
+ // assert
+ Assert.Equal(expected, rgb.PackedValue);
+ }
}
}
\ No newline at end of file
diff --git a/tests/ImageSharp.Tests/PixelFormats/Rgba64Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Rgba64Tests.cs
index 3e5d7a56e..51f80e0e1 100644
--- a/tests/ImageSharp.Tests/PixelFormats/Rgba64Tests.cs
+++ b/tests/ImageSharp.Tests/PixelFormats/Rgba64Tests.cs
@@ -91,5 +91,22 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
// assert
Assert.Equal(expected, actual);
}
+
+ [Fact]
+ public void Rgba64_FromBgra5551()
+ {
+ // arrange
+ var rgba = default(Rgba64);
+ ushort expected = ushort.MaxValue;
+
+ // act
+ rgba.FromBgra5551(new Bgra5551(1.0f, 1.0f, 1.0f, 1.0f));
+
+ // assert
+ Assert.Equal(expected, rgba.R);
+ Assert.Equal(expected, rgba.G);
+ Assert.Equal(expected, rgba.B);
+ Assert.Equal(expected, rgba.A);
+ }
}
}
diff --git a/tests/ImageSharp.Tests/PixelFormats/Short2Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Short2Tests.cs
index c9a3b33c9..4ae172ed4 100644
--- a/tests/ImageSharp.Tests/PixelFormats/Short2Tests.cs
+++ b/tests/ImageSharp.Tests/PixelFormats/Short2Tests.cs
@@ -141,5 +141,22 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
// assert
Assert.Equal(expected, actual);
}
+
+ [Fact]
+ public void Short2_FromBgra5551()
+ {
+ // arrange
+ var short2 = default(Short2);
+
+ // act
+ short2.FromBgra5551(new Bgra5551(1.0f, 1.0f, 1.0f, 1.0f));
+
+ // assert
+ Vector4 actual = short2.ToScaledVector4();
+ Assert.Equal(1, actual.X);
+ Assert.Equal(1, actual.Y);
+ Assert.Equal(0, actual.Z);
+ Assert.Equal(1, actual.W);
+ }
}
}
diff --git a/tests/ImageSharp.Tests/PixelFormats/Short4Tests.cs b/tests/ImageSharp.Tests/PixelFormats/Short4Tests.cs
index 247342a05..1cb7d8998 100644
--- a/tests/ImageSharp.Tests/PixelFormats/Short4Tests.cs
+++ b/tests/ImageSharp.Tests/PixelFormats/Short4Tests.cs
@@ -181,5 +181,19 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
// assert
Assert.Equal(expected, actual);
}
+
+ [Fact]
+ public void Short4_FromBgra5551()
+ {
+ // arrange
+ var short4 = default(Short4);
+ Vector4 expected = Vector4.One;
+
+ // act
+ short4.FromBgra5551(new Bgra5551(1.0f, 1.0f, 1.0f, 1.0f));
+
+ // assert
+ Assert.Equal(expected, short4.ToScaledVector4());
+ }
}
}
diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs
index 23bebd621..f82278ef5 100644
--- a/tests/ImageSharp.Tests/TestImages.cs
+++ b/tests/ImageSharp.Tests/TestImages.cs
@@ -241,6 +241,7 @@ namespace SixLabors.ImageSharp.Tests
public const string Bit16Inverted = "Bmp/test16-inverted.bmp";
public const string Bit32Rgb = "Bmp/rgb32.bmp";
public const string Bit32Rgba = "Bmp/rgba32.bmp";
+ public const string Rgb16 = "Bmp/rgb16.bmp";
// Note: This format can be called OS/2 BMPv1, or Windows BMPv2
public const string WinBmpv2 = "Bmp/pal8os2v1_winv2.bmp";
diff --git a/tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs b/tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs
index a051e577d..e4a7572d6 100644
--- a/tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs
+++ b/tests/ImageSharp.Tests/TestUtilities/PixelTypes.cs
@@ -58,6 +58,8 @@ namespace SixLabors.ImageSharp.Tests
Rgb48 = 1 << 21,
+ Bgra5551 = 1 << 22,
+
// TODO: Add multi-flag entries by rules defined in PackedPixelConverterHelper
// "All" is handled as a separate, individual case instead of using bitwise OR
diff --git a/tests/Images/Input/Bmp/rgb16.bmp b/tests/Images/Input/Bmp/rgb16.bmp
new file mode 100644
index 0000000000000000000000000000000000000000..6bfe47af4f72866315bed53d0f6f8591bc372ccb
GIT binary patch
literal 16438
zcmdto2V5HG{|9hX)KgJUMLiYAsi>Do;zdzWaa@$>#Sn8EVo-6Mih3&Qsi^1Zpqp;G
z64OmL-E_uuhIG8ON>Ear0tj(MsfTV!b
zz>J_wPF8SENPcJ$SQ=IyUKvr%t%NNU#^^?rU
zGg@?MU5GBPi%`$H7+qS<1z0`)<@O7g*)Q_2JJ-R%XTxlaO|ms?J=?^#vH@Sj7x$%n
zwY~;lv#-q;^h5m!KiW^{XY{l9*&Pv!{N?_P|E&L<|GfW#e-aC3Cj%**RFKb2gVK2!
zNl5CNjJ27WS%RE(`Rj|aO40HSmD$xfHNv{w`n<;c7EyaaS7C3_fOxogtYp&5(Z396
z<(v-Qz_LWEJ^WqIdZL7{CA$&;WYC1Xuwe013bYr~qw%A;2793jhPrKq8P1)CC#?
zErIqxC`c3}4`PC5gXV(fgBF5HS!HYt*vKgdE4UJ96R$F80?`Sic}uS~yM{43SF{2Z8r
zaY&Aaqvx17Rt^x11mnR}ur}BbY!0>sgCS@L5kiOPLX07n5PJv|Dhic{GNH4fbD{I0
z3!yEnR(2aea@xTTZYQMVbtQGD_GD0*y;*%Z{rRe*fzrY9p-Q@XxMrkov|imf)-v8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