Browse Source

Implement up GifMetadata

pull/2751/head
James Jackson-South 2 years ago
parent
commit
2752a450d8
  1. 20
      src/ImageSharp/Formats/Gif/GifColorTableMode.cs
  2. 8
      src/ImageSharp/Formats/Gif/GifDecoderCore.cs
  3. 2
      src/ImageSharp/Formats/Gif/GifEncoder.cs
  4. 12
      src/ImageSharp/Formats/Gif/GifEncoderCore.cs
  5. 4
      src/ImageSharp/Formats/Gif/GifFrameMetadata.cs
  6. 64
      src/ImageSharp/Formats/Gif/GifMetadata.cs
  7. 6
      src/ImageSharp/Formats/Gif/MetadataExtensions.cs
  8. 4
      src/ImageSharp/Formats/Png/PngEncoderCore.cs
  9. 40
      src/ImageSharp/PixelFormats/PixelColorType.cs
  10. 2
      src/ImageSharp/PixelFormats/PixelComponentInfo.cs
  11. 2
      src/ImageSharp/PixelFormats/PixelImplementations/L16.cs
  12. 2
      src/ImageSharp/PixelFormats/PixelImplementations/L8.cs
  13. 2
      src/ImageSharp/PixelFormats/PixelImplementations/La16.cs
  14. 2
      src/ImageSharp/PixelFormats/PixelImplementations/La32.cs
  15. 15
      tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs
  16. 10
      tests/ImageSharp.Tests/Formats/Gif/GifMetadataTests.cs
  17. 3
      tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.NonGeneric.cs
  18. 2
      tests/ImageSharp.Tests/PixelFormats/L16Tests.cs
  19. 2
      tests/ImageSharp.Tests/PixelFormats/L8Tests.cs
  20. 2
      tests/ImageSharp.Tests/PixelFormats/La16Tests.cs
  21. 2
      tests/ImageSharp.Tests/PixelFormats/La32Tests.cs
  22. 66
      tests/ImageSharp.Tests/PixelFormats/PixelColorTypeTests.cs

20
src/ImageSharp/Formats/Gif/GifColorTableMode.cs

@ -1,20 +0,0 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.Gif;
/// <summary>
/// Provides enumeration for the available color table modes.
/// </summary>
public enum GifColorTableMode
{
/// <summary>
/// A single color table is calculated from the first frame and reused for subsequent frames.
/// </summary>
Global,
/// <summary>
/// A unique color table is calculated for each frame.
/// </summary>
Local
}

8
src/ImageSharp/Formats/Gif/GifDecoderCore.cs

@ -696,14 +696,14 @@ internal sealed class GifDecoderCore : IImageDecoderInternals
&& this.logicalScreenDescriptor.GlobalColorTableSize > 0)
{
GifFrameMetadata gifMeta = metadata.GetGifMetadata();
gifMeta.ColorTableMode = GifColorTableMode.Global;
gifMeta.ColorTableMode = FrameColorTableMode.Global;
}
if (this.imageDescriptor.LocalColorTableFlag
&& this.imageDescriptor.LocalColorTableSize > 0)
{
GifFrameMetadata gifMeta = metadata.GetGifMetadata();
gifMeta.ColorTableMode = GifColorTableMode.Local;
gifMeta.ColorTableMode = FrameColorTableMode.Local;
Color[] colorTable = new Color[this.imageDescriptor.LocalColorTableSize];
ReadOnlySpan<Rgb24> rgbTable = MemoryMarshal.Cast<byte, Rgb24>(this.currentLocalColorTable!.GetSpan()[..this.currentLocalColorTableSize]);
@ -766,8 +766,8 @@ internal sealed class GifDecoderCore : IImageDecoderInternals
this.metadata = meta;
this.gifMetadata = meta.GetGifMetadata();
this.gifMetadata.ColorTableMode = this.logicalScreenDescriptor.GlobalColorTableFlag
? GifColorTableMode.Global
: GifColorTableMode.Local;
? FrameColorTableMode.Global
: FrameColorTableMode.Local;
if (this.logicalScreenDescriptor.GlobalColorTableFlag)
{

2
src/ImageSharp/Formats/Gif/GifEncoder.cs

@ -11,7 +11,7 @@ public sealed class GifEncoder : QuantizingImageEncoder
/// <summary>
/// Gets the color table mode: Global or local.
/// </summary>
public GifColorTableMode? ColorTableMode { get; init; }
public FrameColorTableMode? ColorTableMode { get; init; }
/// <inheritdoc/>
protected override void Encode<TPixel>(Image<TPixel> image, Stream stream, CancellationToken cancellationToken)

12
src/ImageSharp/Formats/Gif/GifEncoderCore.cs

@ -49,7 +49,7 @@ internal sealed class GifEncoderCore : IImageEncoderInternals
/// <summary>
/// The color table mode: Global or local.
/// </summary>
private GifColorTableMode? colorTableMode;
private FrameColorTableMode? colorTableMode;
/// <summary>
/// The pixel sampling strategy for global quantization.
@ -87,7 +87,7 @@ internal sealed class GifEncoderCore : IImageEncoderInternals
GifMetadata gifMetadata = GetGifMetadata(image);
this.colorTableMode ??= gifMetadata.ColorTableMode;
bool useGlobalTable = this.colorTableMode == GifColorTableMode.Global;
bool useGlobalTable = this.colorTableMode == FrameColorTableMode.Global;
// Quantize the first image frame returning a palette.
IndexedImageFrame<TPixel>? quantized = null;
@ -99,7 +99,7 @@ internal sealed class GifEncoderCore : IImageEncoderInternals
if (this.quantizer is null)
{
// Is this a gif with color information. If so use that, otherwise use octree.
if (gifMetadata.ColorTableMode == GifColorTableMode.Global && gifMetadata.GlobalColorTable?.Length > 0)
if (gifMetadata.ColorTableMode == FrameColorTableMode.Global && gifMetadata.GlobalColorTable?.Length > 0)
{
// We avoid dithering by default to preserve the original colors.
int transparencyIndex = GetTransparentIndex(quantized, frameMetadata);
@ -221,7 +221,7 @@ internal sealed class GifEncoderCore : IImageEncoderInternals
metadata = GifFrameMetadata.FromAnimatedMetadata(ani);
}
if (metadata?.ColorTableMode == GifColorTableMode.Global && transparencyIndex > -1)
if (metadata?.ColorTableMode == FrameColorTableMode.Global && transparencyIndex > -1)
{
metadata.HasTransparency = true;
metadata.TransparencyIndex = ClampIndex(transparencyIndex);
@ -258,7 +258,7 @@ internal sealed class GifEncoderCore : IImageEncoderInternals
ImageFrame<TPixel> currentFrame = image.Frames[i];
ImageFrame<TPixel>? nextFrame = i < image.Frames.Count - 1 ? image.Frames[i + 1] : null;
GifFrameMetadata gifMetadata = GetGifFrameMetadata(currentFrame, globalTransparencyIndex);
bool useLocal = this.colorTableMode == GifColorTableMode.Local || (gifMetadata.ColorTableMode == GifColorTableMode.Local);
bool useLocal = this.colorTableMode == FrameColorTableMode.Local || (gifMetadata.ColorTableMode == FrameColorTableMode.Local);
if (!useLocal && !hasPaletteQuantizer && i > 0)
{
@ -301,7 +301,7 @@ internal sealed class GifEncoderCore : IImageEncoderInternals
Buffer2D<byte> indices = ((IPixelSource)quantized).PixelBuffer;
Rectangle interest = indices.FullRectangle();
bool useLocal = this.colorTableMode == GifColorTableMode.Local || (metadata.ColorTableMode == GifColorTableMode.Local);
bool useLocal = this.colorTableMode == FrameColorTableMode.Local || (metadata.ColorTableMode == FrameColorTableMode.Local);
int bitDepth = ColorNumerics.GetBitsNeededForColorDepth(quantized.Palette.Length);
this.WriteImageDescriptor(interest, useLocal, bitDepth, stream);

4
src/ImageSharp/Formats/Gif/GifFrameMetadata.cs

@ -40,7 +40,7 @@ public class GifFrameMetadata : IDeepCloneable
/// <summary>
/// Gets or sets the color table mode.
/// </summary>
public GifColorTableMode ColorTableMode { get; set; }
public FrameColorTableMode ColorTableMode { get; set; }
/// <summary>
/// Gets or sets the local color table, if any.
@ -101,7 +101,7 @@ public class GifFrameMetadata : IDeepCloneable
return new()
{
LocalColorTable = metadata.ColorTable,
ColorTableMode = metadata.ColorTableMode == FrameColorTableMode.Global ? GifColorTableMode.Global : GifColorTableMode.Local,
ColorTableMode = metadata.ColorTableMode,
FrameDelay = (int)Math.Round(metadata.Duration.TotalMilliseconds / 10),
DisposalMethod = GetMode(metadata.DisposalMode),
HasTransparency = hasTransparency,

64
src/ImageSharp/Formats/Gif/GifMetadata.cs

@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.Formats.Gif;
/// <summary>
/// Provides Gif specific metadata information for the image.
/// </summary>
public class GifMetadata : IDeepCloneable
public class GifMetadata : IFormatMetadata<GifMetadata>
{
/// <summary>
/// Initializes a new instance of the <see cref="GifMetadata"/> class.
@ -49,7 +49,7 @@ public class GifMetadata : IDeepCloneable
/// <summary>
/// Gets or sets the color table mode.
/// </summary>
public GifColorTableMode ColorTableMode { get; set; }
public FrameColorTableMode ColorTableMode { get; set; }
/// <summary>
/// Gets or sets the global color table, if any.
@ -69,9 +69,6 @@ public class GifMetadata : IDeepCloneable
/// </summary>
public IList<string> Comments { get; set; } = [];
/// <inheritdoc/>
public IDeepCloneable DeepClone() => new GifMetadata(this);
internal static GifMetadata FromAnimatedMetadata(AnimatedImageMetadata metadata)
{
int index = 0;
@ -92,9 +89,64 @@ public class GifMetadata : IDeepCloneable
return new()
{
GlobalColorTable = metadata.ColorTable,
ColorTableMode = metadata.ColorTableMode == FrameColorTableMode.Global ? GifColorTableMode.Global : GifColorTableMode.Local,
ColorTableMode = metadata.ColorTableMode,
RepeatCount = metadata.RepeatCount,
BackgroundColorIndex = (byte)Numerics.Clamp(index, 0, 255),
};
}
/// <inheritdoc/>
public static GifMetadata FromFormatConnectingMetadata(FormatConnectingMetadata metadata)
{
int index = 0;
Color background = metadata.BackgroundColor;
if (metadata.ColorTable.HasValue)
{
ReadOnlySpan<Color> colorTable = metadata.ColorTable.Value.Span;
for (int i = 0; i < colorTable.Length; i++)
{
if (background == colorTable[i])
{
index = i;
break;
}
}
}
return new()
{
GlobalColorTable = metadata.ColorTable,
ColorTableMode = metadata.ColorTableMode,
RepeatCount = metadata.RepeatCount,
BackgroundColorIndex = (byte)Numerics.Clamp(index, 0, 255),
};
}
/// <inheritdoc/>
public FormatConnectingMetadata ToFormatConnectingMetadata()
{
Color color = this.GlobalColorTable.HasValue && this.GlobalColorTable.Value.Span.Length > this.BackgroundColorIndex
? this.GlobalColorTable.Value.Span[this.BackgroundColorIndex]
: Color.Transparent;
return new()
{
AnimateRootFrame = true,
BackgroundColor = color,
ColorTable = this.GlobalColorTable,
ColorTableMode = this.ColorTableMode,
PixelTypeInfo = new PixelTypeInfo(24)
{
ColorType = PixelColorType.Indexed,
ComponentInfo = PixelComponentInfo.Create(3, 24, 8, 8, 8),
},
RepeatCount = this.RepeatCount,
};
}
/// <inheritdoc/>
public IDeepCloneable DeepClone() => ((IDeepCloneable<GifMetadata>)this).DeepClone();
/// <inheritdoc/>
GifMetadata IDeepCloneable<GifMetadata>.DeepClone() => new(this);
}

6
src/ImageSharp/Formats/Gif/MetadataExtensions.cs

@ -70,7 +70,7 @@ public static partial class MetadataExtensions
return new()
{
ColorTable = source.GlobalColorTable,
ColorTableMode = source.ColorTableMode == GifColorTableMode.Global ? FrameColorTableMode.Global : FrameColorTableMode.Local,
ColorTableMode = source.ColorTableMode,
RepeatCount = source.RepeatCount,
BackgroundColor = background,
};
@ -83,12 +83,12 @@ public static partial class MetadataExtensions
bool blendSource = source.DisposalMethod == GifDisposalMethod.RestoreToBackground || (source.LocalColorTable?.Length == 256 && !source.HasTransparency);
// If the color table is global and frame has no transparency. Consider it 'Source' also.
blendSource |= source.ColorTableMode == GifColorTableMode.Global && !source.HasTransparency;
blendSource |= source.ColorTableMode == FrameColorTableMode.Global && !source.HasTransparency;
return new()
{
ColorTable = source.LocalColorTable,
ColorTableMode = source.ColorTableMode == GifColorTableMode.Global ? FrameColorTableMode.Global : FrameColorTableMode.Local,
ColorTableMode = source.ColorTableMode,
Duration = TimeSpan.FromMilliseconds(source.FrameDelay * 10),
DisposalMode = GetMode(source.DisposalMethod),
BlendMode = blendSource ? FrameBlendMode.Source : FrameBlendMode.Over,

4
src/ImageSharp/Formats/Png/PngEncoderCore.cs

@ -1680,14 +1680,14 @@ internal sealed class PngEncoderCore : IImageEncoderInternals, IDisposable
{
return info.ColorType switch
{
PixelColorType.Grayscale => PngColorType.Grayscale,
PixelColorType.Luminance => PngColorType.Grayscale,
_ => PngColorType.Rgb,
};
}
return info.ColorType switch
{
PixelColorType.Grayscale | PixelColorType.Alpha or PixelColorType.Alpha => PngColorType.GrayscaleWithAlpha,
PixelColorType.Luminance | PixelColorType.Alpha or PixelColorType.Alpha => PngColorType.GrayscaleWithAlpha,
_ => PngColorType.RgbWithAlpha,
};
}

40
src/ImageSharp/PixelFormats/PixelColorType.cs

@ -35,34 +35,39 @@ public enum PixelColorType
Alpha = 1 << 3,
/// <summary>
/// Indicates that the color is in grayscale.
/// Represents the Exponent component used in formats like R9G9B9E5.
/// </summary>
Grayscale = 1 << 4,
Exponent = 1 << 4,
/// <summary>
/// Indicates that the color is in RGB (Red, Green, Blue) format.
/// Indicates that the color is in luminance (grayscale) format.
/// </summary>
RGB = Red | Green | Blue | (1 << 5),
Luminance = 1 << 5,
/// <summary>
/// Indicates that the color is in BGR (Blue, Green, Red) format.
/// Indicates that the color is indexed using a palette.
/// </summary>
Indexed = 1 << 6,
/// <summary>
/// Indicates that the color is in RGB (Red, Green, Blue) format.
/// </summary>
BGR = Blue | Green | Red | (1 << 6),
RGB = Red | Green | Blue | (1 << 7),
/// <summary>
/// Represents the Luminance component in YCbCr.
/// Indicates that the color is in BGR (Blue, Green, Red) format.
/// </summary>
Luminance = 1 << 7,
BGR = Blue | Green | Red | (1 << 8),
/// <summary>
/// Represents the Chrominance Blue component in YCbCr.
/// </summary>
ChrominanceBlue = 1 << 8,
ChrominanceBlue = 1 << 9,
/// <summary>
/// Represents the Chrominance Red component in YCbCr.
/// </summary>
ChrominanceRed = 1 << 9,
ChrominanceRed = 1 << 10,
/// <summary>
/// Indicates that the color is in YCbCr (Luminance, Chrominance Blue, Chrominance Red) format.
@ -72,22 +77,22 @@ public enum PixelColorType
/// <summary>
/// Represents the Cyan component in CMYK.
/// </summary>
Cyan = 1 << 10,
Cyan = 1 << 11,
/// <summary>
/// Represents the Magenta component in CMYK.
/// </summary>
Magenta = 1 << 11,
Magenta = 1 << 12,
/// <summary>
/// Represents the Yellow component in CMYK.
/// </summary>
Yellow = 1 << 12,
Yellow = 1 << 13,
/// <summary>
/// Represents the Key (black) component in CMYK and YCCK.
/// </summary>
Key = 1 << 13,
Key = 1 << 14,
/// <summary>
/// Indicates that the color is in CMYK (Cyan, Magenta, Yellow, Key) format.
@ -99,13 +104,8 @@ public enum PixelColorType
/// </summary>
YCCK = Luminance | ChrominanceBlue | ChrominanceRed | Key,
/// <summary>
/// Indicates that the color is indexed using a palette.
/// </summary>
Indexed = 1 << 14,
/// <summary>
/// Indicates that the color is of a type not specified in this enum.
/// </summary>
Other = 1 << 15
Other = 1 << 16
}

2
src/ImageSharp/PixelFormats/PixelComponentInfo.cs

@ -53,7 +53,7 @@ public readonly struct PixelComponentInfo
/// <exception cref="ArgumentOutOfRangeException">The component precision and index cannot exceed the component range.</exception>
public static PixelComponentInfo Create(int count, int bitsPerPixel, params int[] precision)
{
if (precision.Length != count || precision.Length > 16)
if (precision.Length < count || precision.Length > 16)
{
throw new ArgumentOutOfRangeException(nameof(count), $"Count {count} must match the length of precision array and cannot exceed 16.");
}

2
src/ImageSharp/PixelFormats/PixelImplementations/L16.cs

@ -71,7 +71,7 @@ public partial struct L16 : IPixel<L16>, IPackedVector<ushort>
public static PixelTypeInfo GetPixelTypeInfo()
=> PixelTypeInfo.Create<L16>(
PixelComponentInfo.Create<L16>(1, 16),
PixelColorType.Grayscale,
PixelColorType.Luminance,
PixelAlphaRepresentation.None);
/// <inheritdoc />

2
src/ImageSharp/PixelFormats/PixelImplementations/L8.cs

@ -73,7 +73,7 @@ public partial struct L8 : IPixel<L8>, IPackedVector<byte>
public static PixelTypeInfo GetPixelTypeInfo()
=> PixelTypeInfo.Create<L8>(
PixelComponentInfo.Create<L8>(1, 8),
PixelColorType.Grayscale,
PixelColorType.Luminance,
PixelAlphaRepresentation.None);
/// <inheritdoc />

2
src/ImageSharp/PixelFormats/PixelImplementations/La16.cs

@ -100,7 +100,7 @@ public partial struct La16 : IPixel<La16>, IPackedVector<ushort>
public static PixelTypeInfo GetPixelTypeInfo()
=> PixelTypeInfo.Create<La16>(
PixelComponentInfo.Create<La16>(2, 8, 8),
PixelColorType.Grayscale | PixelColorType.Alpha,
PixelColorType.Luminance | PixelColorType.Alpha,
PixelAlphaRepresentation.Unassociated);
/// <inheritdoc/>

2
src/ImageSharp/PixelFormats/PixelImplementations/La32.cs

@ -97,7 +97,7 @@ public partial struct La32 : IPixel<La32>, IPackedVector<uint>
public static PixelTypeInfo GetPixelTypeInfo()
=> PixelTypeInfo.Create<La32>(
PixelComponentInfo.Create<La32>(2, 16, 16),
PixelColorType.Grayscale | PixelColorType.Alpha,
PixelColorType.Luminance | PixelColorType.Alpha,
PixelAlphaRepresentation.Unassociated);
/// <inheritdoc/>

15
tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs

@ -1,6 +1,7 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Gif;
using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.Formats.Webp;
@ -113,7 +114,7 @@ public class GifEncoderTests
using Image<TPixel> image = provider.GetImage();
GifEncoder encoder = new()
{
ColorTableMode = GifColorTableMode.Global,
ColorTableMode = FrameColorTableMode.Global,
Quantizer = new OctreeQuantizer(new QuantizerOptions { Dither = null })
};
@ -122,7 +123,7 @@ public class GifEncoderTests
encoder = new()
{
ColorTableMode = GifColorTableMode.Local,
ColorTableMode = FrameColorTableMode.Local,
Quantizer = new OctreeQuantizer(new QuantizerOptions { Dither = null }),
};
@ -148,7 +149,7 @@ public class GifEncoderTests
GifEncoder encoder = new()
{
ColorTableMode = GifColorTableMode.Global,
ColorTableMode = FrameColorTableMode.Global,
PixelSamplingStrategy = new DefaultPixelSamplingStrategy(maxPixels, scanRatio)
};
@ -175,10 +176,10 @@ public class GifEncoderTests
Image<Rgba32> image = Image.Load<Rgba32>(inStream);
GifMetadata metaData = image.Metadata.GetGifMetadata();
GifFrameMetadata frameMetadata = image.Frames.RootFrame.Metadata.GetGifMetadata();
GifColorTableMode colorMode = metaData.ColorTableMode;
FrameColorTableMode colorMode = metaData.ColorTableMode;
int maxColors;
if (colorMode == GifColorTableMode.Global)
if (colorMode == FrameColorTableMode.Global)
{
maxColors = metaData.GlobalColorTable.Value.Length;
}
@ -204,7 +205,7 @@ public class GifEncoderTests
// Gifiddle and Cyotek GifInfo say this image has 64 colors.
colorMode = cloneMetadata.ColorTableMode;
if (colorMode == GifColorTableMode.Global)
if (colorMode == FrameColorTableMode.Global)
{
maxColors = metaData.GlobalColorTable.Value.Length;
}
@ -220,7 +221,7 @@ public class GifEncoderTests
GifFrameMetadata iMeta = image.Frames[i].Metadata.GetGifMetadata();
GifFrameMetadata cMeta = clone.Frames[i].Metadata.GetGifMetadata();
if (iMeta.ColorTableMode == GifColorTableMode.Local)
if (iMeta.ColorTableMode == FrameColorTableMode.Local)
{
Assert.Equal(iMeta.LocalColorTable.Value.Length, cMeta.LocalColorTable.Value.Length);
}

10
tests/ImageSharp.Tests/Formats/Gif/GifMetadataTests.cs

@ -33,7 +33,7 @@ public class GifMetadataTests
GifMetadata meta = new()
{
RepeatCount = 1,
ColorTableMode = GifColorTableMode.Global,
ColorTableMode = FrameColorTableMode.Global,
GlobalColorTable = new[] { Color.Black, Color.White },
Comments = new List<string> { "Foo" }
};
@ -41,7 +41,7 @@ public class GifMetadataTests
GifMetadata clone = (GifMetadata)meta.DeepClone();
clone.RepeatCount = 2;
clone.ColorTableMode = GifColorTableMode.Local;
clone.ColorTableMode = FrameColorTableMode.Local;
clone.GlobalColorTable = new[] { Color.Black };
Assert.False(meta.RepeatCount.Equals(clone.RepeatCount));
@ -183,11 +183,11 @@ public class GifMetadataTests
}
[Theory]
[InlineData(TestImages.Gif.Cheers, 93, GifColorTableMode.Global, 256, 4, GifDisposalMethod.NotDispose)]
[InlineData(TestImages.Gif.Cheers, 93, FrameColorTableMode.Global, 256, 4, GifDisposalMethod.NotDispose)]
public void Identify_Frames(
string imagePath,
int framesCount,
GifColorTableMode colorTableMode,
FrameColorTableMode colorTableMode,
int globalColorTableLength,
int frameDelay,
GifDisposalMethod disposalMethod)
@ -206,7 +206,7 @@ public class GifMetadataTests
Assert.Equal(colorTableMode, gifFrameMetadata.ColorTableMode);
if (colorTableMode == GifColorTableMode.Global)
if (colorTableMode == FrameColorTableMode.Global)
{
Assert.Equal(globalColorTableLength, gifMetadata.GlobalColorTable.Value.Length);
}

3
tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.NonGeneric.cs

@ -1,6 +1,7 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Gif;
using SixLabors.ImageSharp.PixelFormats;
@ -315,7 +316,7 @@ public abstract partial class ImageFrameCollectionTests
Assert.Equal(aData.DisposalMethod, bData.DisposalMethod);
Assert.Equal(aData.FrameDelay, bData.FrameDelay);
if (aData.ColorTableMode == GifColorTableMode.Local && bData.ColorTableMode == GifColorTableMode.Local)
if (aData.ColorTableMode == FrameColorTableMode.Local && bData.ColorTableMode == FrameColorTableMode.Local)
{
Assert.Equal(aData.LocalColorTable.Value.Length, bData.LocalColorTable.Value.Length);
}

2
tests/ImageSharp.Tests/PixelFormats/L16Tests.cs

@ -161,7 +161,7 @@ public class L16Tests
PixelTypeInfo info = L16.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<L16>() * 8, info.BitsPerPixel);
Assert.Equal(PixelAlphaRepresentation.None, info.AlphaRepresentation);
Assert.Equal(PixelColorType.Grayscale, info.ColorType);
Assert.Equal(PixelColorType.Luminance, info.ColorType);
PixelComponentInfo componentInfo = info.ComponentInfo.Value;
Assert.Equal(1, componentInfo.ComponentCount);

2
tests/ImageSharp.Tests/PixelFormats/L8Tests.cs

@ -245,7 +245,7 @@ public class L8Tests
PixelTypeInfo info = L8.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<L8>() * 8, info.BitsPerPixel);
Assert.Equal(PixelAlphaRepresentation.None, info.AlphaRepresentation);
Assert.Equal(PixelColorType.Grayscale, info.ColorType);
Assert.Equal(PixelColorType.Luminance, info.ColorType);
PixelComponentInfo componentInfo = info.ComponentInfo.Value;
Assert.Equal(1, componentInfo.ComponentCount);

2
tests/ImageSharp.Tests/PixelFormats/La16Tests.cs

@ -248,7 +248,7 @@ public class La16Tests
PixelTypeInfo info = La16.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<La16>() * 8, info.BitsPerPixel);
Assert.Equal(PixelAlphaRepresentation.Unassociated, info.AlphaRepresentation);
Assert.Equal(PixelColorType.Grayscale | PixelColorType.Alpha, info.ColorType);
Assert.Equal(PixelColorType.Luminance | PixelColorType.Alpha, info.ColorType);
PixelComponentInfo componentInfo = info.ComponentInfo.Value;
Assert.Equal(2, componentInfo.ComponentCount);

2
tests/ImageSharp.Tests/PixelFormats/La32Tests.cs

@ -167,7 +167,7 @@ public class La32Tests
PixelTypeInfo info = La32.GetPixelTypeInfo();
Assert.Equal(Unsafe.SizeOf<La32>() * 8, info.BitsPerPixel);
Assert.Equal(PixelAlphaRepresentation.Unassociated, info.AlphaRepresentation);
Assert.Equal(PixelColorType.Grayscale | PixelColorType.Alpha, info.ColorType);
Assert.Equal(PixelColorType.Luminance | PixelColorType.Alpha, info.ColorType);
PixelComponentInfo componentInfo = info.ComponentInfo.Value;
Assert.Equal(2, componentInfo.ComponentCount);

66
tests/ImageSharp.Tests/PixelFormats/PixelColorTypeTests.cs

@ -36,10 +36,24 @@ public class PixelColorTypeTests
}
[Fact]
public void PixelColorType_GrayscaleFlag_ShouldBeSet()
public void PixelColorType_Exponent_ShouldBeSet()
{
const PixelColorType colorType = PixelColorType.Grayscale;
Assert.True(colorType.HasFlag(PixelColorType.Grayscale));
const PixelColorType colorType = PixelColorType.Exponent;
Assert.True(colorType.HasFlag(PixelColorType.Exponent));
}
[Fact]
public void PixelColorType_LuminanceFlag_ShouldBeSet()
{
const PixelColorType colorType = PixelColorType.Luminance;
Assert.True(colorType.HasFlag(PixelColorType.Luminance));
}
[Fact]
public void PixelColorType_Indexed_ShouldBeSet()
{
const PixelColorType colorType = PixelColorType.Indexed;
Assert.True(colorType.HasFlag(PixelColorType.Indexed));
}
[Fact]
@ -62,13 +76,6 @@ public class PixelColorTypeTests
Assert.False(colorType.HasFlag(PixelColorType.RGB));
}
[Fact]
public void PixelColorType_LuminanceFlag_ShouldBeSet()
{
const PixelColorType colorType = PixelColorType.Luminance;
Assert.True(colorType.HasFlag(PixelColorType.Luminance));
}
[Fact]
public void PixelColorType_ChrominanceBlueFlag_ShouldBeSet()
{
@ -140,13 +147,6 @@ public class PixelColorTypeTests
Assert.True(colorType.HasFlag(PixelColorType.Key));
}
[Fact]
public void PixelColorType_Indexed_ShouldBeSet()
{
const PixelColorType colorType = PixelColorType.Indexed;
Assert.True(colorType.HasFlag(PixelColorType.Indexed));
}
[Fact]
public void PixelColorType_Other_ShouldBeSet()
{
@ -165,15 +165,16 @@ public class PixelColorTypeTests
public void PixelColorType_RGB_ShouldNotContainOtherFlags()
{
const PixelColorType colorType = PixelColorType.RGB;
Assert.False(colorType.HasFlag(PixelColorType.Grayscale));
Assert.False(colorType.HasFlag(PixelColorType.Alpha));
Assert.False(colorType.HasFlag(PixelColorType.Exponent));
Assert.False(colorType.HasFlag(PixelColorType.Luminance));
Assert.False(colorType.HasFlag(PixelColorType.Indexed));
Assert.False(colorType.HasFlag(PixelColorType.ChrominanceBlue));
Assert.False(colorType.HasFlag(PixelColorType.ChrominanceRed));
Assert.False(colorType.HasFlag(PixelColorType.Cyan));
Assert.False(colorType.HasFlag(PixelColorType.Magenta));
Assert.False(colorType.HasFlag(PixelColorType.Yellow));
Assert.False(colorType.HasFlag(PixelColorType.Key));
Assert.False(colorType.HasFlag(PixelColorType.Indexed));
Assert.False(colorType.HasFlag(PixelColorType.Other));
}
@ -181,15 +182,16 @@ public class PixelColorTypeTests
public void PixelColorType_BGR_ShouldNotContainOtherFlags()
{
const PixelColorType colorType = PixelColorType.BGR;
Assert.False(colorType.HasFlag(PixelColorType.Grayscale));
Assert.False(colorType.HasFlag(PixelColorType.Alpha));
Assert.False(colorType.HasFlag(PixelColorType.Exponent));
Assert.False(colorType.HasFlag(PixelColorType.Luminance));
Assert.False(colorType.HasFlag(PixelColorType.Indexed));
Assert.False(colorType.HasFlag(PixelColorType.ChrominanceBlue));
Assert.False(colorType.HasFlag(PixelColorType.ChrominanceRed));
Assert.False(colorType.HasFlag(PixelColorType.Cyan));
Assert.False(colorType.HasFlag(PixelColorType.Magenta));
Assert.False(colorType.HasFlag(PixelColorType.Yellow));
Assert.False(colorType.HasFlag(PixelColorType.Key));
Assert.False(colorType.HasFlag(PixelColorType.Indexed));
Assert.False(colorType.HasFlag(PixelColorType.Other));
}
@ -201,12 +203,12 @@ public class PixelColorTypeTests
Assert.False(colorType.HasFlag(PixelColorType.Green));
Assert.False(colorType.HasFlag(PixelColorType.Blue));
Assert.False(colorType.HasFlag(PixelColorType.Alpha));
Assert.False(colorType.HasFlag(PixelColorType.Grayscale));
Assert.False(colorType.HasFlag(PixelColorType.Exponent));
Assert.False(colorType.HasFlag(PixelColorType.Indexed));
Assert.False(colorType.HasFlag(PixelColorType.Cyan));
Assert.False(colorType.HasFlag(PixelColorType.Magenta));
Assert.False(colorType.HasFlag(PixelColorType.Yellow));
Assert.False(colorType.HasFlag(PixelColorType.Key));
Assert.False(colorType.HasFlag(PixelColorType.Indexed));
Assert.False(colorType.HasFlag(PixelColorType.Other));
}
@ -218,11 +220,11 @@ public class PixelColorTypeTests
Assert.False(colorType.HasFlag(PixelColorType.Green));
Assert.False(colorType.HasFlag(PixelColorType.Blue));
Assert.False(colorType.HasFlag(PixelColorType.Alpha));
Assert.False(colorType.HasFlag(PixelColorType.Grayscale));
Assert.False(colorType.HasFlag(PixelColorType.Exponent));
Assert.False(colorType.HasFlag(PixelColorType.Luminance));
Assert.False(colorType.HasFlag(PixelColorType.Indexed));
Assert.False(colorType.HasFlag(PixelColorType.ChrominanceBlue));
Assert.False(colorType.HasFlag(PixelColorType.ChrominanceRed));
Assert.False(colorType.HasFlag(PixelColorType.Indexed));
Assert.False(colorType.HasFlag(PixelColorType.Other));
}
@ -234,11 +236,11 @@ public class PixelColorTypeTests
Assert.False(colorType.HasFlag(PixelColorType.Green));
Assert.False(colorType.HasFlag(PixelColorType.Blue));
Assert.False(colorType.HasFlag(PixelColorType.Alpha));
Assert.False(colorType.HasFlag(PixelColorType.Grayscale));
Assert.False(colorType.HasFlag(PixelColorType.Exponent));
Assert.False(colorType.HasFlag(PixelColorType.Indexed));
Assert.False(colorType.HasFlag(PixelColorType.Cyan));
Assert.False(colorType.HasFlag(PixelColorType.Magenta));
Assert.False(colorType.HasFlag(PixelColorType.Yellow));
Assert.False(colorType.HasFlag(PixelColorType.Indexed));
Assert.False(colorType.HasFlag(PixelColorType.Other));
}
@ -250,10 +252,10 @@ public class PixelColorTypeTests
Assert.False(colorType.HasFlag(PixelColorType.Green));
Assert.False(colorType.HasFlag(PixelColorType.Blue));
Assert.False(colorType.HasFlag(PixelColorType.Alpha));
Assert.False(colorType.HasFlag(PixelColorType.Grayscale));
Assert.False(colorType.HasFlag(PixelColorType.Exponent));
Assert.False(colorType.HasFlag(PixelColorType.Luminance));
Assert.False(colorType.HasFlag(PixelColorType.RGB));
Assert.False(colorType.HasFlag(PixelColorType.BGR));
Assert.False(colorType.HasFlag(PixelColorType.Luminance));
Assert.False(colorType.HasFlag(PixelColorType.ChrominanceBlue));
Assert.False(colorType.HasFlag(PixelColorType.ChrominanceRed));
Assert.False(colorType.HasFlag(PixelColorType.YCbCr));
@ -274,10 +276,11 @@ public class PixelColorTypeTests
Assert.False(colorType.HasFlag(PixelColorType.Green));
Assert.False(colorType.HasFlag(PixelColorType.Blue));
Assert.False(colorType.HasFlag(PixelColorType.Alpha));
Assert.False(colorType.HasFlag(PixelColorType.Grayscale));
Assert.False(colorType.HasFlag(PixelColorType.Exponent));
Assert.False(colorType.HasFlag(PixelColorType.Luminance));
Assert.False(colorType.HasFlag(PixelColorType.Indexed));
Assert.False(colorType.HasFlag(PixelColorType.RGB));
Assert.False(colorType.HasFlag(PixelColorType.BGR));
Assert.False(colorType.HasFlag(PixelColorType.Luminance));
Assert.False(colorType.HasFlag(PixelColorType.ChrominanceBlue));
Assert.False(colorType.HasFlag(PixelColorType.ChrominanceRed));
Assert.False(colorType.HasFlag(PixelColorType.YCbCr));
@ -287,6 +290,5 @@ public class PixelColorTypeTests
Assert.False(colorType.HasFlag(PixelColorType.Key));
Assert.False(colorType.HasFlag(PixelColorType.CMYK));
Assert.False(colorType.HasFlag(PixelColorType.YCCK));
Assert.False(colorType.HasFlag(PixelColorType.Indexed));
}
}

Loading…
Cancel
Save