Browse Source

MakeTransparentBlack is now a png encoder option

pull/1574/head
Brian Popow 6 years ago
parent
commit
3e0a38e4ff
  1. 5
      src/ImageSharp/Formats/Png/IPngEncoderOptions.cs
  2. 5
      src/ImageSharp/Formats/Png/PngChunkFilter.cs
  3. 5
      src/ImageSharp/Formats/Png/PngEncoder.cs
  4. 4
      src/ImageSharp/Formats/Png/PngEncoderCore.cs
  5. 4
      src/ImageSharp/Formats/Png/PngEncoderOptions.cs

5
src/ImageSharp/Formats/Png/IPngEncoderOptions.cs

@ -62,5 +62,10 @@ namespace SixLabors.ImageSharp.Formats.Png
/// Gets the optimize method. /// Gets the optimize method.
/// </summary> /// </summary>
PngChunkFilter? ChunkFilter { get; } PngChunkFilter? ChunkFilter { get; }
/// <summary>
/// Gets a value indicating whether fully transparent pixels should be converted to black pixels.
/// </summary>
bool MakeTransparentBlack { get; }
} }
} }

5
src/ImageSharp/Formats/Png/PngChunkFilter.cs

@ -36,11 +36,6 @@ namespace SixLabors.ImageSharp.Formats.Png
/// </summary> /// </summary>
ExcludeTextChunks = 1 << 3, ExcludeTextChunks = 1 << 3,
/// <summary>
/// Make fully transparent pixels black.
/// </summary>
MakeTransparentBlack = 16,
/// <summary> /// <summary>
/// All possible optimizations. /// All possible optimizations.
/// </summary> /// </summary>

5
src/ImageSharp/Formats/Png/PngEncoder.cs

@ -67,6 +67,11 @@ namespace SixLabors.ImageSharp.Formats.Png
/// </summary> /// </summary>
public PngChunkFilter? ChunkFilter { get; set; } public PngChunkFilter? ChunkFilter { get; set; }
/// <summary>
/// Gets or sets a value indicating whether fully transparent pixels should be converted to black pixels.
/// </summary>
public bool MakeTransparentBlack { get; set; }
/// <summary> /// <summary>
/// Encodes the image to the specified stream from the <see cref="Image{TPixel}"/>. /// Encodes the image to the specified stream from the <see cref="Image{TPixel}"/>.
/// </summary> /// </summary>

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

@ -7,7 +7,7 @@ using System.Buffers.Binary;
using System.IO; using System.IO;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Formats.Png.Chunks; using SixLabors.ImageSharp.Formats.Png.Chunks;
using SixLabors.ImageSharp.Formats.Png.Filters; using SixLabors.ImageSharp.Formats.Png.Filters;
using SixLabors.ImageSharp.Formats.Png.Zlib; using SixLabors.ImageSharp.Formats.Png.Zlib;
@ -145,7 +145,7 @@ namespace SixLabors.ImageSharp.Formats.Png
PngMetadata pngMetadata = metadata.GetFormatMetadata(PngFormat.Instance); PngMetadata pngMetadata = metadata.GetFormatMetadata(PngFormat.Instance);
PngEncoderOptionsHelpers.AdjustOptions<TPixel>(this.options, pngMetadata, out this.use16Bit, out this.bytesPerPixel); PngEncoderOptionsHelpers.AdjustOptions<TPixel>(this.options, pngMetadata, out this.use16Bit, out this.bytesPerPixel);
IndexedImageFrame<TPixel> quantized; IndexedImageFrame<TPixel> quantized;
if (((this.options.ChunkFilter ?? PngChunkFilter.None) & PngChunkFilter.MakeTransparentBlack) == PngChunkFilter.MakeTransparentBlack) if (this.options.MakeTransparentBlack)
{ {
using (Image<TPixel> tempImage = image.Clone()) using (Image<TPixel> tempImage = image.Clone())
{ {

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

@ -30,6 +30,7 @@ namespace SixLabors.ImageSharp.Formats.Png
this.Threshold = source.Threshold; this.Threshold = source.Threshold;
this.InterlaceMethod = source.InterlaceMethod; this.InterlaceMethod = source.InterlaceMethod;
this.ChunkFilter = source.ChunkFilter; this.ChunkFilter = source.ChunkFilter;
this.MakeTransparentBlack = source.MakeTransparentBlack;
} }
/// <summary> /// <summary>
@ -84,5 +85,8 @@ namespace SixLabors.ImageSharp.Formats.Png
/// Gets or sets a the optimize method. /// Gets or sets a the optimize method.
/// </summary> /// </summary>
public PngChunkFilter? ChunkFilter { get; set; } public PngChunkFilter? ChunkFilter { get; set; }
/// <inheritdoc/>
public bool MakeTransparentBlack { get; set; }
} }
} }

Loading…
Cancel
Save