Browse Source

Don't force transparency

af/merge-core
James Jackson-South 8 years ago
parent
commit
42913b64b7
  1. 5
      src/ImageSharp/PixelFormats/NamedColors{TPixel}.cs
  2. 4
      src/ImageSharp/Processing/KnownQuantizers.cs
  3. 25
      tests/ImageSharp.Tests/Quantization/QuantizedImageTests.cs
  4. 2
      tests/Images/External

5
src/ImageSharp/PixelFormats/NamedColors{TPixel}.cs

@ -746,10 +746,7 @@ namespace SixLabors.ImageSharp.PixelFormats
private static TPixel[] GetPalette(Rgba32[] palette) private static TPixel[] GetPalette(Rgba32[] palette)
{ {
// TODO: This should be the length only. var converted = new TPixel[palette.Length];
// We need to fix and update tests/reference images.
// If someone wants transparency they should add it to the palette.
var converted = new TPixel[palette.Length + 1];
Span<byte> constantsBytes = MemoryMarshal.Cast<Rgba32, byte>(palette.AsSpan()); Span<byte> constantsBytes = MemoryMarshal.Cast<Rgba32, byte>(palette.AsSpan());
PixelOperations<TPixel>.Instance.FromRgba32Bytes( PixelOperations<TPixel>.Instance.FromRgba32Bytes(

4
src/ImageSharp/Processing/KnownQuantizers.cs

@ -12,26 +12,22 @@ namespace SixLabors.ImageSharp.Processing
{ {
/// <summary> /// <summary>
/// Gets the adaptive Octree quantizer. Fast with good quality. /// Gets the adaptive Octree quantizer. Fast with good quality.
/// The quantizer only supports a single alpha value.
/// </summary> /// </summary>
public static IQuantizer Octree { get; } = new OctreeQuantizer(); public static IQuantizer Octree { get; } = new OctreeQuantizer();
/// <summary> /// <summary>
/// Gets the Xiaolin Wu's Color Quantizer which generates high quality output. /// Gets the Xiaolin Wu's Color Quantizer which generates high quality output.
/// The quantizer supports multiple alpha values.
/// </summary> /// </summary>
public static IQuantizer Wu { get; } = new WuQuantizer(); public static IQuantizer Wu { get; } = new WuQuantizer();
/// <summary> /// <summary>
/// Gets the palette based quantizer consisting of web safe colors as defined in the CSS Color Module Level 4. /// Gets the palette based quantizer consisting of web safe colors as defined in the CSS Color Module Level 4.
/// The quantizer supports a single alpha value.
/// </summary> /// </summary>
public static IQuantizer WebSafe { get; } = new WebSafePaletteQuantizer(); public static IQuantizer WebSafe { get; } = new WebSafePaletteQuantizer();
/// <summary> /// <summary>
/// Gets the palette based quantizer consisting of colors as defined in the original second edition of Werner’s Nomenclature of Colours 1821. /// Gets the palette based quantizer consisting of colors as defined in the original second edition of Werner’s Nomenclature of Colours 1821.
/// The hex codes were collected and defined by Nicholas Rougeux <see href="https://www.c82.net/werner"/> /// The hex codes were collected and defined by Nicholas Rougeux <see href="https://www.c82.net/werner"/>
/// The quantizer supports a single alpha value.
/// </summary> /// </summary>
public static IQuantizer Werner { get; } = new WernerPaletteQuantizer(); public static IQuantizer Werner { get; } = new WernerPaletteQuantizer();
} }

25
tests/ImageSharp.Tests/Quantization/QuantizedImageTests.cs

@ -31,31 +31,6 @@ namespace SixLabors.ImageSharp.Tests
Assert.True(wu.CreateFrameQuantizer<Rgba32>(this.Configuration).Dither); Assert.True(wu.CreateFrameQuantizer<Rgba32>(this.Configuration).Dither);
} }
[Theory]
[WithFile(TestImages.Gif.Giphy, PixelTypes.Rgba32, true)]
[WithFile(TestImages.Gif.Giphy, PixelTypes.Rgba32, false)]
public void PaletteQuantizerYieldsCorrectTransparentPixel<TPixel>(
TestImageProvider<TPixel> provider,
bool dither)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
Assert.True(image[0, 0].Equals(default(TPixel)));
var quantizer = new WebSafePaletteQuantizer(dither);
foreach (ImageFrame<TPixel> frame in image.Frames)
{
QuantizedFrame<TPixel> quantized =
quantizer.CreateFrameQuantizer<TPixel>(this.Configuration).QuantizeFrame(frame);
int index = this.GetTransparentIndex(quantized);
Assert.Equal(index, quantized.GetPixelSpan()[0]);
}
}
}
[Theory] [Theory]
[WithFile(TestImages.Gif.Giphy, PixelTypes.Rgba32, true)] [WithFile(TestImages.Gif.Giphy, PixelTypes.Rgba32, true)]
[WithFile(TestImages.Gif.Giphy, PixelTypes.Rgba32, false)] [WithFile(TestImages.Gif.Giphy, PixelTypes.Rgba32, false)]

2
tests/Images/External

@ -1 +1 @@
Subproject commit f41ae0327a3ab21ab2388c32160bda67debcc082 Subproject commit ed8a7b0b6fe1b2e2a7c822aa617103ae31192655
Loading…
Cancel
Save