Skip to content

Commit

Permalink
Version 1.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Nominom committed May 24, 2020
1 parent a0031ab commit 6d6aa6f
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 86 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.1</Version>
<Version>1.2.2</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>Added xml documentation to nuget.</PackageReleaseNotes>
<PackageReleaseNotes>Changed EncodingQuality to CompressionQuality.</PackageReleaseNotes>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down
20 changes: 10 additions & 10 deletions BCnEnc.Net/Encoder/Bc1BlockEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace BCnEncoder.Encoder
internal class Bc1BlockEncoder : IBcBlockEncoder
{

public byte[] Encode(RawBlock4X4Rgba32[] blocks, int blockWidth, int blockHeight, EncodingQuality quality, bool parallel)
public byte[] Encode(RawBlock4X4Rgba32[] blocks, int blockWidth, int blockHeight, CompressionQuality quality, bool parallel)
{
byte[] outputData = new byte[blockWidth * blockHeight * Marshal.SizeOf<Bc1Block>()];
Span<Bc1Block> outputBlocks = MemoryMarshal.Cast<byte, Bc1Block>(outputData);
Expand All @@ -32,15 +32,15 @@ public byte[] Encode(RawBlock4X4Rgba32[] blocks, int blockWidth, int blockHeight
return outputData;
}

private Bc1Block EncodeBlock(RawBlock4X4Rgba32 block, EncodingQuality quality)
private Bc1Block EncodeBlock(RawBlock4X4Rgba32 block, CompressionQuality quality)
{
switch (quality)
{
case EncodingQuality.Fast:
case CompressionQuality.Fast:
return Bc1BlockEncoderFast.EncodeBlock(block);
case EncodingQuality.Balanced:
case CompressionQuality.Balanced:
return Bc1BlockEncoderBalanced.EncodeBlock(block);
case EncodingQuality.BestQuality:
case CompressionQuality.BestQuality:
return Bc1BlockEncoderSlow.EncodeBlock(block);

default:
Expand Down Expand Up @@ -242,7 +242,7 @@ internal static Bc1Block EncodeBlock(RawBlock4X4Rgba32 rawBlock)
internal class Bc1AlphaBlockEncoder : IBcBlockEncoder
{

public byte[] Encode(RawBlock4X4Rgba32[] blocks, int blockWidth, int blockHeight, EncodingQuality quality, bool parallel)
public byte[] Encode(RawBlock4X4Rgba32[] blocks, int blockWidth, int blockHeight, CompressionQuality quality, bool parallel)
{
byte[] outputData = new byte[blockWidth * blockHeight * Marshal.SizeOf<Bc1Block>()];
Span<Bc1Block> outputBlocks = MemoryMarshal.Cast<byte, Bc1Block>(outputData);
Expand All @@ -266,15 +266,15 @@ public byte[] Encode(RawBlock4X4Rgba32[] blocks, int blockWidth, int blockHeight
return outputData;
}

private Bc1Block EncodeBlock(RawBlock4X4Rgba32 block, EncodingQuality quality)
private Bc1Block EncodeBlock(RawBlock4X4Rgba32 block, CompressionQuality quality)
{
switch (quality)
{
case EncodingQuality.Fast:
case CompressionQuality.Fast:
return Bc1AlphaBlockEncoderFast.EncodeBlock(block);
case EncodingQuality.Balanced:
case CompressionQuality.Balanced:
return Bc1AlphaBlockEncoderBalanced.EncodeBlock(block);
case EncodingQuality.BestQuality:
case CompressionQuality.BestQuality:
return Bc1AlphaBlockEncoderSlow.EncodeBlock(block);

default:
Expand Down
10 changes: 5 additions & 5 deletions BCnEnc.Net/Encoder/Bc2BlockEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace BCnEncoder.Encoder
internal class Bc2BlockEncoder : IBcBlockEncoder
{

public byte[] Encode(RawBlock4X4Rgba32[] blocks, int blockWidth, int blockHeight, EncodingQuality quality, bool parallel)
public byte[] Encode(RawBlock4X4Rgba32[] blocks, int blockWidth, int blockHeight, CompressionQuality quality, bool parallel)
{
byte[] outputData = new byte[blockWidth * blockHeight * Marshal.SizeOf<Bc2Block>()];
Span<Bc2Block> outputBlocks = MemoryMarshal.Cast<byte, Bc2Block>(outputData);
Expand All @@ -32,15 +32,15 @@ public byte[] Encode(RawBlock4X4Rgba32[] blocks, int blockWidth, int blockHeight
return outputData;
}

private Bc2Block EncodeBlock(RawBlock4X4Rgba32 block, EncodingQuality quality)
private Bc2Block EncodeBlock(RawBlock4X4Rgba32 block, CompressionQuality quality)
{
switch (quality)
{
case EncodingQuality.Fast:
case CompressionQuality.Fast:
return Bc2BlockEncoderFast.EncodeBlock(block);
case EncodingQuality.Balanced:
case CompressionQuality.Balanced:
return Bc2BlockEncoderBalanced.EncodeBlock(block);
case EncodingQuality.BestQuality:
case CompressionQuality.BestQuality:
return Bc2BlockEncoderSlow.EncodeBlock(block);

default:
Expand Down
10 changes: 5 additions & 5 deletions BCnEnc.Net/Encoder/Bc3BlockEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace BCnEncoder.Encoder
internal class Bc3BlockEncoder : IBcBlockEncoder
{

public byte[] Encode(RawBlock4X4Rgba32[] blocks, int blockWidth, int blockHeight, EncodingQuality quality, bool parallel)
public byte[] Encode(RawBlock4X4Rgba32[] blocks, int blockWidth, int blockHeight, CompressionQuality quality, bool parallel)
{
byte[] outputData = new byte[blockWidth * blockHeight * Marshal.SizeOf<Bc3Block>()];
Span<Bc3Block> outputBlocks = MemoryMarshal.Cast<byte, Bc3Block>(outputData);
Expand All @@ -33,15 +33,15 @@ public byte[] Encode(RawBlock4X4Rgba32[] blocks, int blockWidth, int blockHeight
return outputData;
}

private Bc3Block EncodeBlock(RawBlock4X4Rgba32 block, EncodingQuality quality)
private Bc3Block EncodeBlock(RawBlock4X4Rgba32 block, CompressionQuality quality)
{
switch (quality)
{
case EncodingQuality.Fast:
case CompressionQuality.Fast:
return Bc3BlockEncoderFast.EncodeBlock(block);
case EncodingQuality.Balanced:
case CompressionQuality.Balanced:
return Bc3BlockEncoderBalanced.EncodeBlock(block);
case EncodingQuality.BestQuality:
case CompressionQuality.BestQuality:
return Bc3BlockEncoderSlow.EncodeBlock(block);

default:
Expand Down
10 changes: 5 additions & 5 deletions BCnEnc.Net/Encoder/Bc4BlockEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public Bc4BlockEncoder(bool luminanceAsRed) {
this.luminanceAsRed = luminanceAsRed;
}

public byte[] Encode(RawBlock4X4Rgba32[] blocks, int blockWidth, int blockHeight, EncodingQuality quality,
public byte[] Encode(RawBlock4X4Rgba32[] blocks, int blockWidth, int blockHeight, CompressionQuality quality,
bool parallel) {
byte[] outputData = new byte[blockWidth * blockHeight * Marshal.SizeOf<Bc4Block>()];
Span<Bc4Block> outputBlocks = MemoryMarshal.Cast<byte, Bc4Block>(outputData);
Expand All @@ -33,7 +33,7 @@ public byte[] Encode(RawBlock4X4Rgba32[] blocks, int blockWidth, int blockHeight
return outputData;
}

private Bc4Block EncodeBlock(RawBlock4X4Rgba32 block, EncodingQuality quality) {
private Bc4Block EncodeBlock(RawBlock4X4Rgba32 block, CompressionQuality quality) {
Bc4Block output = new Bc4Block();
byte[] colors = new byte[16];
var pixels = block.AsSpan;
Expand All @@ -46,11 +46,11 @@ private Bc4Block EncodeBlock(RawBlock4X4Rgba32 block, EncodingQuality quality) {
}
}
switch (quality) {
case EncodingQuality.Fast:
case CompressionQuality.Fast:
return FindRedValues(output, colors, 3);
case EncodingQuality.Balanced:
case CompressionQuality.Balanced:
return FindRedValues(output, colors, 4);
case EncodingQuality.BestQuality:
case CompressionQuality.BestQuality:
return FindRedValues(output, colors, 8);

default:
Expand Down
10 changes: 5 additions & 5 deletions BCnEnc.Net/Encoder/Bc5BlockEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace BCnEncoder.Encoder
{
internal class Bc5BlockEncoder : IBcBlockEncoder {

public byte[] Encode(RawBlock4X4Rgba32[] blocks, int blockWidth, int blockHeight, EncodingQuality quality, bool parallel)
public byte[] Encode(RawBlock4X4Rgba32[] blocks, int blockWidth, int blockHeight, CompressionQuality quality, bool parallel)
{
byte[] outputData = new byte[blockWidth * blockHeight * Marshal.SizeOf<Bc5Block>()];
Span<Bc5Block> outputBlocks = MemoryMarshal.Cast<byte, Bc5Block>(outputData);
Expand All @@ -28,7 +28,7 @@ public byte[] Encode(RawBlock4X4Rgba32[] blocks, int blockWidth, int blockHeight
return outputData;
}

private Bc5Block EncodeBlock(RawBlock4X4Rgba32 block, EncodingQuality quality) {
private Bc5Block EncodeBlock(RawBlock4X4Rgba32 block, CompressionQuality quality) {
Bc5Block output = new Bc5Block();
byte[] reds = new byte[16];
byte[] greens = new byte[16];
Expand All @@ -41,15 +41,15 @@ private Bc5Block EncodeBlock(RawBlock4X4Rgba32 block, EncodingQuality quality) {
int variations = 0;
int errorThreshold = 0;
switch (quality) {
case EncodingQuality.Fast:
case CompressionQuality.Fast:
variations = 3;
errorThreshold = 5;
break;
case EncodingQuality.Balanced:
case CompressionQuality.Balanced:
variations = 5;
errorThreshold = 1;
break;
case EncodingQuality.BestQuality:
case CompressionQuality.BestQuality:
variations = 8;
errorThreshold = 0;
break;
Expand Down
10 changes: 5 additions & 5 deletions BCnEnc.Net/Encoder/Bc7/Bc7Encoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace BCnEncoder.Encoder.Bc7
internal class Bc7Encoder : IBcBlockEncoder
{

public byte[] Encode(RawBlock4X4Rgba32[] blocks, int blockWidth, int blockHeight, EncodingQuality quality, bool parallel)
public byte[] Encode(RawBlock4X4Rgba32[] blocks, int blockWidth, int blockHeight, CompressionQuality quality, bool parallel)
{
byte[] outputData = new byte[blockWidth * blockHeight * Marshal.SizeOf<Bc7Block>()];
Span<Bc7Block> outputBlocks = MemoryMarshal.Cast<byte, Bc7Block>(outputData);
Expand Down Expand Up @@ -75,15 +75,15 @@ private static ClusterIndices4X4 CreateClusterIndexBlock(RawBlock4X4Rgba32 raw,
}


private static Bc7Block EncodeBlock(RawBlock4X4Rgba32 rawBlock, EncodingQuality quality)
private static Bc7Block EncodeBlock(RawBlock4X4Rgba32 rawBlock, CompressionQuality quality)
{
switch (quality)
{
case EncodingQuality.Fast:
case CompressionQuality.Fast:
return Bc7EncoderFast.EncodeBlock(rawBlock);
case EncodingQuality.Balanced:
case CompressionQuality.Balanced:
return Bc7EncoderBalanced.EncodeBlock(rawBlock);
case EncodingQuality.BestQuality:
case CompressionQuality.BestQuality:
return Bc7EncoderBestQuality.EncodeBlock(rawBlock);
default:
throw new ArgumentOutOfRangeException(nameof(quality), quality, null);
Expand Down
4 changes: 2 additions & 2 deletions BCnEnc.Net/Encoder/BcEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public class EncoderOutputOptions
/// </summary>
public CompressionFormat format = CompressionFormat.BC1;
/// <summary>
/// The quality of the encoding. Use either fast or balanced for testing.
/// The quality of the compression. Use either fast or balanced for testing.
/// Fast can be used for near real-time encoding for most algorithms.
/// Use bestQuality when needed. Default is balanced.
/// </summary>
public EncodingQuality quality = EncodingQuality.Balanced;
public CompressionQuality quality = CompressionQuality.Balanced;
/// <summary>
/// The output file format of the data. Either Ktx or Dds.
/// Default is Ktx.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
namespace BCnEncoder.Encoder
{
public enum EncodingQuality
public enum CompressionQuality
{
/// <summary>
/// Fast, but low quality. Especially bad with gradients.
/// </summary>
Fast,
/// <summary>
/// Strikes a balance between speed and quality. Enough for most purposes.
/// Strikes a balance between speed and quality. Good enough for most purposes.
/// </summary>
Balanced,
/// <summary>
/// Aims for best quality encoding. Can be very slow at times.
/// Aims for best quality encoding. Can be very slow.
/// </summary>
BestQuality
}
Expand Down
2 changes: 1 addition & 1 deletion BCnEnc.Net/Encoder/IBcBlockEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace BCnEncoder.Encoder
{
internal interface IBcBlockEncoder
{
byte[] Encode(RawBlock4X4Rgba32[] blocks, int blockWidth, int blockHeight, EncodingQuality quality, bool parallel = true);
byte[] Encode(RawBlock4X4Rgba32[] blocks, int blockWidth, int blockHeight, CompressionQuality quality, bool parallel = true);
GlInternalFormat GetInternalFormat();
GLFormat GetBaseInternalFormat();
DXGI_FORMAT GetDxgiFormat();
Expand Down
16 changes: 8 additions & 8 deletions BCnEncTests/DdsWritingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void DdsWriteRgba() {
var image = ImageLoader.testLenna;

BcEncoder encoder = new BcEncoder();
encoder.OutputOptions.quality = EncodingQuality.Fast;
encoder.OutputOptions.quality = CompressionQuality.Fast;
encoder.OutputOptions.generateMipMaps = true;
encoder.OutputOptions.format = CompressionFormat.RGBA;
encoder.OutputOptions.fileFormat = OutputFileFormat.Dds;
Expand All @@ -30,7 +30,7 @@ public void DdsWriteBc1() {
var image = ImageLoader.testLenna;

BcEncoder encoder = new BcEncoder();
encoder.OutputOptions.quality = EncodingQuality.Fast;
encoder.OutputOptions.quality = CompressionQuality.Fast;
encoder.OutputOptions.generateMipMaps = true;
encoder.OutputOptions.format = CompressionFormat.BC1;
encoder.OutputOptions.fileFormat = OutputFileFormat.Dds;
Expand All @@ -45,7 +45,7 @@ public void DdsWriteBc2() {
var image = ImageLoader.testAlpha1;

BcEncoder encoder = new BcEncoder();
encoder.OutputOptions.quality = EncodingQuality.Fast;
encoder.OutputOptions.quality = CompressionQuality.Fast;
encoder.OutputOptions.generateMipMaps = true;
encoder.OutputOptions.format = CompressionFormat.BC2;
encoder.OutputOptions.fileFormat = OutputFileFormat.Dds;
Expand All @@ -60,7 +60,7 @@ public void DdsWriteBc3() {
var image = ImageLoader.testAlpha1;

BcEncoder encoder = new BcEncoder();
encoder.OutputOptions.quality = EncodingQuality.Fast;
encoder.OutputOptions.quality = CompressionQuality.Fast;
encoder.OutputOptions.generateMipMaps = true;
encoder.OutputOptions.format = CompressionFormat.BC3;
encoder.OutputOptions.fileFormat = OutputFileFormat.Dds;
Expand All @@ -75,7 +75,7 @@ public void DdsWriteBc4() {
var image = ImageLoader.testHeight1;

BcEncoder encoder = new BcEncoder();
encoder.OutputOptions.quality = EncodingQuality.Fast;
encoder.OutputOptions.quality = CompressionQuality.Fast;
encoder.OutputOptions.generateMipMaps = true;
encoder.OutputOptions.format = CompressionFormat.BC4;
encoder.OutputOptions.fileFormat = OutputFileFormat.Dds;
Expand All @@ -90,7 +90,7 @@ public void DdsWriteBc5() {
var image = ImageLoader.testRedGreen1;

BcEncoder encoder = new BcEncoder();
encoder.OutputOptions.quality = EncodingQuality.Fast;
encoder.OutputOptions.quality = CompressionQuality.Fast;
encoder.OutputOptions.generateMipMaps = true;
encoder.OutputOptions.format = CompressionFormat.BC5;
encoder.OutputOptions.fileFormat = OutputFileFormat.Dds;
Expand All @@ -105,7 +105,7 @@ public void DdsWriteBc7() {
var image = ImageLoader.testLenna;

BcEncoder encoder = new BcEncoder();
encoder.OutputOptions.quality = EncodingQuality.Fast;
encoder.OutputOptions.quality = CompressionQuality.Fast;
encoder.OutputOptions.generateMipMaps = true;
encoder.OutputOptions.format = CompressionFormat.BC7;
encoder.OutputOptions.fileFormat = OutputFileFormat.Dds;
Expand All @@ -120,7 +120,7 @@ public void DdsWriteCubemap() {
var images = ImageLoader.testCubemap;

BcEncoder encoder = new BcEncoder();
encoder.OutputOptions.quality = EncodingQuality.Fast;
encoder.OutputOptions.quality = CompressionQuality.Fast;
encoder.OutputOptions.generateMipMaps = true;
encoder.OutputOptions.format = CompressionFormat.BC1;
encoder.OutputOptions.fileFormat = OutputFileFormat.Dds;
Expand Down
Loading

0 comments on commit 6d6aa6f

Please sign in to comment.