Browse Source

Fix transparency allocation

Former-commit-id: 85c4d5c0ccd92dce6265040068aeffe851604045
Former-commit-id: 5b59aa6bb210dcc113cee26d2986c172170a9d8e
Former-commit-id: a048ee2bfc5bf0bdbdcbdd709c485ccb6c50d90d
af/merge-core
James Jackson-South 10 years ago
parent
commit
3a87134f3e
  1. 5
      src/ImageProcessorCore/Formats/Gif/GifEncoder.cs
  2. 2
      src/ImageProcessorCore/Quantizers/Octree/Quantizer.cs
  3. 2
      src/ImageProcessorCore/Quantizers/Wu/WuQuantizer.cs

5
src/ImageProcessorCore/Formats/Gif/GifEncoder.cs

@ -131,7 +131,7 @@ namespace ImageProcessorCore.Formats
private QuantizedImage WriteColorTable(ImageBase image, Stream stream, int quality, int bitDepth)
{
// Quantize the image returning a palette.
QuantizedImage quantizedImage = this.Quantizer.Quantize(image, quality.Clamp(1, 255));
QuantizedImage quantizedImage = this.Quantizer.Quantize(image, quality);
// Grab the palette and write it to the stream.
Bgra32[] palette = quantizedImage.Palette;
@ -162,6 +162,7 @@ namespace ImageProcessorCore.Formats
/// </summary>
/// <param name="image">The <see cref="ImageBase"/> to encode.</param>
/// <param name="stream">The stream to write to.</param>
/// <param name="transparencyIndex">The index of the color in the color palette to make transparent.</param>
private void WriteGraphicalControlExtension(ImageBase image, Stream stream, int transparencyIndex)
{
// TODO: Check transparency logic.
@ -189,7 +190,7 @@ namespace ImageProcessorCore.Formats
this.WriteByte(stream, packed);
this.WriteShort(stream, extension.DelayTime);
this.WriteByte(stream, extension.TransparencyIndex);
this.WriteByte(stream, extension.TransparencyIndex == -1 ? 255 : extension.TransparencyIndex);
this.WriteByte(stream, GifConstants.Terminator);
}

2
src/ImageProcessorCore/Quantizers/Octree/Quantizer.cs

@ -37,7 +37,7 @@ namespace ImageProcessorCore.Quantizers
/// <summary>
/// Gets or sets the transparency index.
/// </summary>
public int TransparentIndex { get; protected set; }
public int TransparentIndex { get; protected set; } = -1;
/// <inheritdoc/>
public virtual QuantizedImage Quantize(ImageBase image, int maxColors)

2
src/ImageProcessorCore/Quantizers/Wu/WuQuantizer.cs

@ -715,7 +715,7 @@ namespace ImageProcessorCore.Quantizers
{
List<Bgra32> pallette = new List<Bgra32>();
byte[] pixels = new byte[image.Width * image.Height];
int transparentIndex = 0;
int transparentIndex = -1;
for (int k = 0; k < colorCount; k++)
{

Loading…
Cancel
Save