Skip to content

Commit

Permalink
2.0 project files, updated comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Nominom committed Feb 12, 2021
1 parent 964be3c commit f16afbc
Show file tree
Hide file tree
Showing 29 changed files with 236 additions and 158 deletions.
4 changes: 2 additions & 2 deletions BCnEnc.Net/BCnEncoder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageLicenseExpression>MIT OR Unlicense</PackageLicenseExpression>
<Copyright />
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<Version>1.2.3</Version>
<Version>2.0.0</Version>
<Authors>Nominom</Authors>
<Company />
<Product>BCnEncoder.Net</Product>
Expand All @@ -31,7 +31,7 @@ Supported formats are:
<RepositoryType>git</RepositoryType>
<PackageTags>BCn BC BC1 BC2 BC3 BC4 BC5 BC7 BPTC RGTC S3TC DXT1 DXT3 DXT5 ktx dds texture compression encoding decoding decompression image gpu</PackageTags>
<PackageProjectUrl>https://github.com/Nominom/BCnEncoder.NET</PackageProjectUrl>
<PackageReleaseNotes>Upgraded ImageSharp dependency from 1.0.0 beta 7 to version 1.0.1</PackageReleaseNotes>
<PackageReleaseNotes>Removed ImageSharp dependency, added async api methods, added ATC and BGRA support, added new raw api methods, improved dds file handling and fixed some bugs. See the github page for more information about 2.0.</PackageReleaseNotes>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down
10 changes: 5 additions & 5 deletions BCnEnc.Net/Decoder/BcBlockDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ protected override RawBlock4X4Rgba32 DecodeBlock(Bc3Block block)

internal class Bc4Decoder : BaseBcBlockDecoder<Bc4Block>
{
private readonly Bc4Component component;
private readonly ColorComponent component;

public Bc4Decoder(Bc4Component component)
public Bc4Decoder(ColorComponent component)
{
this.component = component;
}
Expand All @@ -124,10 +124,10 @@ protected override RawBlock4X4Rgba32 DecodeBlock(Bc4Block block)

internal class Bc5Decoder : BaseBcBlockDecoder<Bc5Block>
{
private readonly Bc4Component component1;
private readonly Bc4Component component2;
private readonly ColorComponent component1;
private readonly ColorComponent component2;

public Bc5Decoder(Bc4Component component1, Bc4Component component2)
public Bc5Decoder(ColorComponent component1, ColorComponent component2)
{
this.component1 = component1;
this.component2 = component2;
Expand Down
128 changes: 70 additions & 58 deletions BCnEnc.Net/Decoder/BcDecoder.cs

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions BCnEnc.Net/Decoder/Options/DecoderOutputOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ public class DecoderOutputOptions
/// <summary>
/// The color channel to populate with the values of a BC4 block.
/// </summary>
public Bc4Component Bc4Component { get; set; } = Bc4Component.R;
public ColorComponent Bc4Component { get; set; } = ColorComponent.R;

/// <summary>
/// The color channel to populate with the values of the first BC5 block.
/// </summary>
public Bc4Component Bc5Component1 { get; set; } = Bc4Component.R;
public ColorComponent Bc5Component1 { get; set; } = ColorComponent.R;

/// <summary>
/// The color channel to populate with the values of the second BC5 block.
/// </summary>
public Bc4Component Bc5Component2 { get; set; } = Bc4Component.G;
public ColorComponent Bc5Component2 { get; set; } = ColorComponent.G;
}
}
2 changes: 1 addition & 1 deletion BCnEnc.Net/Encoder/AtcBlockEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ internal class AtcInterpolatedAlphaBlockEncoder : BaseBcBlockEncoder<AtcInterpol

public AtcInterpolatedAlphaBlockEncoder()
{
bc4BlockEncoder = new Bc4ComponentBlockEncoder(Bc4Component.A);
bc4BlockEncoder = new Bc4ComponentBlockEncoder(ColorComponent.A);
atcBlockEncoder = new AtcBlockEncoder();
}

Expand Down
2 changes: 1 addition & 1 deletion BCnEnc.Net/Encoder/Bc3BlockEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace BCnEncoder.Encoder
{
internal class Bc3BlockEncoder : BaseBcBlockEncoder<Bc3Block>
{
private static readonly Bc4ComponentBlockEncoder bc4BlockEncoder = new Bc4ComponentBlockEncoder(Bc4Component.A);
private static readonly Bc4ComponentBlockEncoder bc4BlockEncoder = new Bc4ComponentBlockEncoder(ColorComponent.A);

public override Bc3Block EncodeBlock(RawBlock4X4Rgba32 block, CompressionQuality quality)
{
Expand Down
6 changes: 3 additions & 3 deletions BCnEnc.Net/Encoder/Bc4BlockEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal class Bc4BlockEncoder : BaseBcBlockEncoder<Bc4Block>
{
private readonly Bc4ComponentBlockEncoder bc4Encoder;

public Bc4BlockEncoder(Bc4Component component)
public Bc4BlockEncoder(ColorComponent component)
{
bc4Encoder = new Bc4ComponentBlockEncoder(component);
}
Expand Down Expand Up @@ -42,9 +42,9 @@ public override DxgiFormat GetDxgiFormat()

internal class Bc4ComponentBlockEncoder
{
private readonly Bc4Component component;
private readonly ColorComponent component;

public Bc4ComponentBlockEncoder(Bc4Component component)
public Bc4ComponentBlockEncoder(ColorComponent component)
{
this.component = component;
}
Expand Down
2 changes: 1 addition & 1 deletion BCnEnc.Net/Encoder/Bc5BlockEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal class Bc5BlockEncoder : BaseBcBlockEncoder<Bc5Block>
private readonly Bc4ComponentBlockEncoder redBlockEncoder;
private readonly Bc4ComponentBlockEncoder greenBlockEncoder;

public Bc5BlockEncoder(Bc4Component component1, Bc4Component component2)
public Bc5BlockEncoder(ColorComponent component1, ColorComponent component2)
{
redBlockEncoder = new Bc4ComponentBlockEncoder(component1);
greenBlockEncoder = new Bc4ComponentBlockEncoder(component2);
Expand Down
18 changes: 9 additions & 9 deletions BCnEnc.Net/Encoder/BcEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public Task<byte[]> EncodeToRawBytesAsync(ReadOnlyMemory2D<ColorRgba32> input, i
/// <summary>
/// Encodes all mipMaps of a cubeMap image to a stream asynchronously either in ktx or dds format.
/// The format can be set in <see cref="EncoderOutputOptions.FileFormat"/>.
/// Order of faces is +X, -X, +Y, -Y, +Z, -Z
/// Order of faces is +X, -X, +Y, -Y, +Z, -Z. Back maps to positive Z and front to negative Z.
/// </summary>
/// <param name="right">The positive X-axis face of the cubeMap</param>
/// <param name="left">The negative X-axis face of the cubeMap</param>
Expand All @@ -235,7 +235,7 @@ public Task EncodeCubeMapToStreamAsync(ReadOnlyMemory2D<ColorRgba32> right, Read
/// <summary>
/// Encodes all mipMaps of a cubeMap image to a <see cref="KtxFile"/> asynchronously.
/// The format can be set in <see cref="EncoderOutputOptions.FileFormat"/>.
/// Order of faces is +X, -X, +Y, -Y, +Z, -Z
/// Order of faces is +X, -X, +Y, -Y, +Z, -Z. Back maps to positive Z and front to negative Z.
/// </summary>
/// <param name="right">The positive X-axis face of the cubeMap</param>
/// <param name="left">The negative X-axis face of the cubeMap</param>
Expand All @@ -255,7 +255,7 @@ public Task<KtxFile> EncodeCubeMapToKtxAsync(ReadOnlyMemory2D<ColorRgba32> right
/// <summary>
/// Encodes all mipMaps of a cubeMap image to a <see cref="DdsFile"/> asynchronously.
/// The format can be set in <see cref="EncoderOutputOptions.FileFormat"/>.
/// Order of faces is +X, -X, +Y, -Y, +Z, -Z
/// Order of faces is +X, -X, +Y, -Y, +Z, -Z. Back maps to positive Z and front to negative Z.
/// </summary>
/// <param name="right">The positive X-axis face of the cubeMap</param>
/// <param name="left">The negative X-axis face of the cubeMap</param>
Expand Down Expand Up @@ -402,7 +402,7 @@ public byte[] EncodeToRawBytes(ReadOnlyMemory2D<ColorRgba32> input, int mipLevel
/// <summary>
/// Encodes all mipMaps of a cubeMap image to a stream either in ktx or dds format.
/// The format can be set in <see cref="EncoderOutputOptions.FileFormat"/>.
/// Order of faces is +X, -X, +Y, -Y, +Z, -Z
/// Order of faces is +X, -X, +Y, -Y, +Z, -Z. Back maps to positive Z and front to negative Z.
/// </summary>
/// <param name="right">The positive X-axis face of the cubeMap</param>
/// <param name="left">The negative X-axis face of the cubeMap</param>
Expand Down Expand Up @@ -432,7 +432,7 @@ public void EncodeCubeMapToStream(ReadOnlySpan<byte> right, ReadOnlySpan<byte> l
/// <summary>
/// Encodes all mipMaps of a cubeMap image to a stream either in ktx or dds format.
/// The format can be set in <see cref="EncoderOutputOptions.FileFormat"/>.
/// Order of faces is +X, -X, +Y, -Y, +Z, -Z
/// Order of faces is +X, -X, +Y, -Y, +Z, -Z. Back maps to positive Z and front to negative Z.
/// </summary>
/// <param name="right">The positive X-axis face of the cubeMap</param>
/// <param name="left">The negative X-axis face of the cubeMap</param>
Expand All @@ -451,7 +451,7 @@ public void EncodeCubeMapToStream(ReadOnlyMemory2D<ColorRgba32> right, ReadOnlyM
/// <summary>
/// Encodes all mipMaps of a cubeMap image to a <see cref="KtxFile"/>.
/// The format can be set in <see cref="EncoderOutputOptions.FileFormat"/>.
/// Order of faces is +X, -X, +Y, -Y, +Z, -Z
/// Order of faces is +X, -X, +Y, -Y, +Z, -Z. Back maps to positive Z and front to negative Z.
/// </summary>
/// <param name="right">The positive X-axis face of the cubeMap</param>
/// <param name="left">The negative X-axis face of the cubeMap</param>
Expand Down Expand Up @@ -480,7 +480,7 @@ public KtxFile EncodeCubeMapToKtx(ReadOnlySpan<byte> right, ReadOnlySpan<byte> l
/// <summary>
/// Encodes all mipMaps of a cubeMap image to a <see cref="KtxFile"/>.
/// The format can be set in <see cref="EncoderOutputOptions.FileFormat"/>.
/// Order of faces is +X, -X, +Y, -Y, +Z, -Z
/// Order of faces is +X, -X, +Y, -Y, +Z, -Z. Back maps to positive Z and front to negative Z.
/// </summary>
/// <param name="right">The positive X-axis face of the cubeMap</param>
/// <param name="left">The negative X-axis face of the cubeMap</param>
Expand All @@ -499,7 +499,7 @@ public KtxFile EncodeCubeMapToKtx(ReadOnlyMemory2D<ColorRgba32> right, ReadOnlyM
/// <summary>
/// Encodes all mipMaps of a cubeMap image to a <see cref="DdsFile"/>.
/// The format can be set in <see cref="EncoderOutputOptions.FileFormat"/>.
/// Order of faces is +X, -X, +Y, -Y, +Z, -Z
/// Order of faces is +X, -X, +Y, -Y, +Z, -Z. Back maps to positive Z and front to negative Z.
/// </summary>
/// <param name="right">The positive X-axis face of the cubeMap</param>
/// <param name="left">The negative X-axis face of the cubeMap</param>
Expand Down Expand Up @@ -528,7 +528,7 @@ public DdsFile EncodeCubeMapToDds(ReadOnlySpan<byte> right, ReadOnlySpan<byte> l
/// <summary>
/// Encodes all mipMaps of a cubeMap image to a <see cref="DdsFile"/>.
/// The format can be set in <see cref="EncoderOutputOptions.FileFormat"/>.
/// Order of faces is +X, -X, +Y, -Y, +Z, -Z
/// Order of faces is +X, -X, +Y, -Y, +Z, -Z. Back maps to positive Z and front to negative Z.
/// </summary>
/// <param name="right">The positive X-axis face of the cubeMap</param>
/// <param name="left">The negative X-axis face of the cubeMap</param>
Expand Down
12 changes: 6 additions & 6 deletions BCnEnc.Net/Encoder/Options/EncoderInputOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ public class EncoderInputOptions
public bool LuminanceAsRed { get; set; } = false;

/// <summary>
/// The color channel to take for the values of a BC4 block.
/// The color channel to take for the values of a BC4 block. Default is red.
/// </summary>
public Bc4Component Bc4Component { get; set; } = Bc4Component.R;
public ColorComponent Bc4Component { get; set; } = ColorComponent.R;

/// <summary>
/// The color channel to take for the values of the first BC5 block.
/// The color channel to take for the values of the first BC5 block. Default is red.
/// </summary>
public Bc4Component Bc5Component1 { get; set; } = Bc4Component.R;
public ColorComponent Bc5Component1 { get; set; } = ColorComponent.R;

/// <summary>
/// The color channel to take for the values of the second BC5 block.
/// The color channel to take for the values of the second BC5 block. Default is green.
/// </summary>
public Bc4Component Bc5Component2 { get; set; } = Bc4Component.G;
public ColorComponent Bc5Component2 { get; set; } = ColorComponent.G;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@ namespace BCnEncoder.Shared
/// <summary>
/// The component to take from colors for BC4 and BC5.
/// </summary>
public enum Bc4Component
public enum ColorComponent
{
/// <summary>
/// Specifies the red component.
/// The red component of an Rgba32 color.
/// </summary>
R,

/// <summary>
/// Specifies the green component.
/// The green component of an Rgba32 color.
/// </summary>
G,

/// <summary>
/// Specifies the blue component.
/// The blue component of an Rgba32 color.
/// </summary>
B,

/// <summary>
/// Specifies the alpha component.
/// The alpha component of an Rgba32 color.
/// </summary>
A,

/// <summary>
/// Specifies the luminance.
/// Use the color's luminance value as the component.
/// </summary>
Luminance
}
Expand Down
36 changes: 18 additions & 18 deletions BCnEnc.Net/Shared/ComponentHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,51 @@ namespace BCnEncoder.Shared
{
internal static class ComponentHelper
{
public static ColorRgba32 ComponentToColor(Bc4Component component, byte componentValue)
public static ColorRgba32 ComponentToColor(ColorComponent component, byte componentValue)
{
switch (component)
{
case Bc4Component.R:
case ColorComponent.R:
return new ColorRgba32(componentValue, 0, 0, 255);

case Bc4Component.G:
case ColorComponent.G:
return new ColorRgba32(0, componentValue, 0, 255);

case Bc4Component.B:
case ColorComponent.B:
return new ColorRgba32(0, 0, componentValue, 255);

case Bc4Component.A:
case ColorComponent.A:
return new ColorRgba32(0, 0, 0, componentValue);

case Bc4Component.Luminance:
case ColorComponent.Luminance:
return new ColorRgba32(componentValue, componentValue, componentValue, 255);

default:
throw new InvalidOperationException("Unsupported component.");
}
}

public static ColorRgba32 ComponentToColor(ColorRgba32 existingColor, Bc4Component component, byte componentValue)
public static ColorRgba32 ComponentToColor(ColorRgba32 existingColor, ColorComponent component, byte componentValue)
{
switch (component)
{
case Bc4Component.R:
case ColorComponent.R:
existingColor.r = componentValue;
break;

case Bc4Component.G:
case ColorComponent.G:
existingColor.g = componentValue;
break;

case Bc4Component.B:
case ColorComponent.B:
existingColor.b = componentValue;
break;

case Bc4Component.A:
case ColorComponent.A:
existingColor.a = componentValue;
break;

case Bc4Component.Luminance:
case ColorComponent.Luminance:
existingColor.r = existingColor.g = existingColor.b = componentValue;
break;

Expand All @@ -60,23 +60,23 @@ public static ColorRgba32 ComponentToColor(ColorRgba32 existingColor, Bc4Compone
return existingColor;
}

public static byte ColorToComponent(ColorRgba32 color, Bc4Component component)
public static byte ColorToComponent(ColorRgba32 color, ColorComponent component)
{
switch (component)
{
case Bc4Component.R:
case ColorComponent.R:
return color.r;

case Bc4Component.G:
case ColorComponent.G:
return color.g;

case Bc4Component.B:
case ColorComponent.B:
return color.b;

case Bc4Component.A:
case ColorComponent.A:
return color.a;

case Bc4Component.Luminance:
case ColorComponent.Luminance:
return (byte)(new ColorYCbCr(color).y * 255);

default:
Expand Down
4 changes: 2 additions & 2 deletions BCnEnc.Net/Shared/EncodedBlocks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public byte Endpoint1

public void SetComponentIndex(int pixelIndex, byte redIndex) => componentBlock.SetComponentIndex(pixelIndex, redIndex);

public readonly RawBlock4X4Rgba32 Decode(Bc4Component component = Bc4Component.R)
public readonly RawBlock4X4Rgba32 Decode(ColorComponent component = ColorComponent.R)
{
var output = new RawBlock4X4Rgba32();
var pixels = output.AsSpan;
Expand Down Expand Up @@ -251,7 +251,7 @@ public byte Green1

public void SetGreenIndex(int pixelIndex, byte greenIndex) => greenBlock.SetComponentIndex(pixelIndex, greenIndex);

public readonly RawBlock4X4Rgba32 Decode(Bc4Component component1 = Bc4Component.R, Bc4Component component2 = Bc4Component.G)
public readonly RawBlock4X4Rgba32 Decode(ColorComponent component1 = ColorComponent.R, ColorComponent component2 = ColorComponent.G)
{
var output = new RawBlock4X4Rgba32();
var pixels = output.AsSpan;
Expand Down
2 changes: 1 addition & 1 deletion BCnEnc.Net/Shared/LinearClustering.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace BCnEncoder.Shared
/// <summary>
/// Simple Linear Iterative Clustering.
/// </summary>
public static class LinearClustering
internal static class LinearClustering
{

private struct LabXy
Expand Down
2 changes: 1 addition & 1 deletion BCnEncTests/AtcTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using BCnEncoder.Shared;
using BCnEncTests.Support;
using Xunit;
using BCnEncoder.NET.ImageSharp;
using BCnEncoder.ImageSharp;

namespace BCnEncTests
{
Expand Down
2 changes: 1 addition & 1 deletion BCnEncTests/BC1Tests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using BCnEncoder.Shared;
using SixLabors.ImageSharp.PixelFormats;
using Xunit;
using BCnEncoder.NET.ImageSharp;
using BCnEncoder.ImageSharp;

namespace BCnEncTests
{
Expand Down
Loading

0 comments on commit f16afbc

Please sign in to comment.