mirror of https://github.com/SixLabors/ImageSharp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.0 KiB
68 lines
2.0 KiB
namespace ImageProcessor.Tests
|
|
{
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
|
|
using Formats;
|
|
|
|
using Xunit;
|
|
|
|
public class EncoderDecoderTests : ProcessorTestBase
|
|
{
|
|
[Fact]
|
|
public void DecodeThenEncodeImageFromStreamShouldSucceed()
|
|
{
|
|
if (!Directory.Exists("TestOutput/Encoded"))
|
|
{
|
|
Directory.CreateDirectory("TestOutput/Encoded");
|
|
}
|
|
|
|
foreach (FileInfo file in new DirectoryInfo("TestOutput/Encoded").GetFiles())
|
|
{
|
|
file.Delete();
|
|
}
|
|
|
|
foreach (string file in Files)
|
|
{
|
|
using (FileStream stream = File.OpenRead(file))
|
|
{
|
|
Stopwatch watch = Stopwatch.StartNew();
|
|
Image image = new Image(stream);
|
|
|
|
string encodedFilename = "TestOutput/Encoded/" + Path.GetFileName(file);
|
|
|
|
using (FileStream output = File.OpenWrite(encodedFilename))
|
|
{
|
|
image.Save(output);
|
|
}
|
|
|
|
Trace.WriteLine($"{file} : {watch.ElapsedMilliseconds}ms");
|
|
}
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void QuantizedImageShouldPreserveMaximumColorPrecision()
|
|
{
|
|
if (!Directory.Exists("Quantized"))
|
|
{
|
|
Directory.CreateDirectory("Quantized");
|
|
}
|
|
|
|
foreach (string file in Files)
|
|
{
|
|
using (FileStream stream = File.OpenRead(file))
|
|
{
|
|
Image image = new Image(stream);
|
|
IQuantizer quantizer = new OctreeQuantizer();
|
|
QuantizedImage quantizedImage = quantizer.Quantize(image);
|
|
|
|
using (FileStream output = File.OpenWrite($"Quantized/{Path.GetFileName(file)}"))
|
|
{
|
|
quantizedImage.ToImage().Save(output);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|