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)
{
// TODO: This should be the length only.
// 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];
var converted = new TPixel[palette.Length];
Span<byte> constantsBytes = MemoryMarshal.Cast<Rgba32, byte>(palette.AsSpan());
PixelOperations<TPixel>.Instance.FromRgba32Bytes(

4
src/ImageSharp/Processing/KnownQuantizers.cs

@ -12,26 +12,22 @@ namespace SixLabors.ImageSharp.Processing
{
/// <summary>
/// Gets the adaptive Octree quantizer. Fast with good quality.
/// The quantizer only supports a single alpha value.
/// </summary>
public static IQuantizer Octree { get; } = new OctreeQuantizer();
/// <summary>
/// Gets the Xiaolin Wu's Color Quantizer which generates high quality output.
/// The quantizer supports multiple alpha values.
/// </summary>
public static IQuantizer Wu { get; } = new WuQuantizer();
/// <summary>
/// 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>
public static IQuantizer WebSafe { get; } = new WebSafePaletteQuantizer();
/// <summary>
/// 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 quantizer supports a single alpha value.
/// </summary>
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);
}
[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]
[WithFile(TestImages.Gif.Giphy, PixelTypes.Rgba32, true)]
[WithFile(TestImages.Gif.Giphy, PixelTypes.Rgba32, false)]

2
tests/Images/External

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