Skip to content

Commit

Permalink
Merge pull request #613 from SixLabors/js/16-bit-pngs
Browse files Browse the repository at this point in the history
Add 16 bit png support
  • Loading branch information
JimBobSquarePants authored Jun 23, 2018
2 parents d715eb1 + 46df59f commit 0d179d6
Show file tree
Hide file tree
Showing 98 changed files with 3,148 additions and 672 deletions.
2 changes: 1 addition & 1 deletion src/ImageSharp/Common/Helpers/ImageMaths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static int FastAbs(int x)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int GetBitsNeededForColorDepth(int colors)
{
return (int)Math.Ceiling(Math.Log(colors, 2));
return Math.Max(1, (int)Math.Ceiling(Math.Log(colors, 2)));
}

/// <summary>
Expand Down
14 changes: 10 additions & 4 deletions src/ImageSharp/Formats/Png/IPngEncoderOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@ namespace SixLabors.ImageSharp.Formats.Png
internal interface IPngEncoderOptions
{
/// <summary>
/// Gets the png color type
/// Gets the number of bits per sample or per palette index (not per pixel).
/// Not all values are allowed for all <see cref="ColorType"/> values.
/// </summary>
PngColorType PngColorType { get; }
PngBitDepth BitDepth { get; }

/// <summary>
/// Gets the png filter method.
/// Gets the color type
/// </summary>
PngFilterMethod PngFilterMethod { get; }
PngColorType ColorType { get; }

/// <summary>
/// Gets the filter method.
/// </summary>
PngFilterMethod FilterMethod { get; }

/// <summary>
/// Gets the compression level 1-9.
Expand Down
22 changes: 22 additions & 0 deletions src/ImageSharp/Formats/Png/PngBitDepth.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.

// Note the value assignment, This will allow us to add 1, 2, and 4 bit encoding when we support it.
namespace SixLabors.ImageSharp.Formats.Png
{
/// <summary>
/// Provides enumeration for the available PNG bit depths.
/// </summary>
public enum PngBitDepth
{
/// <summary>
/// 8 bits per sample or per palette index (not per pixel).
/// </summary>
Bit8 = 8,

/// <summary>
/// 16 bits per sample or per palette index (not per pixel).
/// </summary>
Bit16 = 16
}
}
8 changes: 4 additions & 4 deletions src/ImageSharp/Formats/Png/PngConfigurationModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ namespace SixLabors.ImageSharp.Formats.Png
public sealed class PngConfigurationModule : IConfigurationModule
{
/// <inheritdoc/>
public void Configure(Configuration config)
public void Configure(Configuration configuration)
{
config.ImageFormatsManager.SetEncoder(ImageFormats.Png, new PngEncoder());
config.ImageFormatsManager.SetDecoder(ImageFormats.Png, new PngDecoder());
config.ImageFormatsManager.AddImageFormatDetector(new PngImageFormatDetector());
configuration.ImageFormatsManager.SetEncoder(ImageFormats.Png, new PngEncoder());
configuration.ImageFormatsManager.SetDecoder(ImageFormats.Png, new PngDecoder());
configuration.ImageFormatsManager.AddImageFormatDetector(new PngImageFormatDetector());
}
}
}
Loading

0 comments on commit 0d179d6

Please sign in to comment.