mirror of https://github.com/SixLabors/ImageSharp
Browse Source
Former-commit-id: 0410a102603bdf7911fc5f02a5b660540a45b525 Former-commit-id: c6d66869a91cd30afae4ae28993716fa67a9c1f4 Former-commit-id: 31b7fdd178103ba89133976d86788e5c4de6f20cpull/17/head
15 changed files with 204 additions and 157 deletions
@ -1,63 +0,0 @@ |
|||||
namespace ImageProcessor.Tests |
|
||||
{ |
|
||||
using System.Diagnostics; |
|
||||
using System.IO; |
|
||||
|
|
||||
using Formats; |
|
||||
|
|
||||
using Xunit; |
|
||||
|
|
||||
public class EncoderDecoderTests |
|
||||
{ |
|
||||
[Theory] |
|
||||
[InlineData("../../TestImages/Formats/Jpg/Backdrop.jpg")] |
|
||||
[InlineData("../../TestImages/Formats/Gif/a.gif")] |
|
||||
[InlineData("../../TestImages/Formats/Gif/leaf.gif")] |
|
||||
[InlineData("../../TestImages/Formats/Gif/ani.gif")] |
|
||||
[InlineData("../../TestImages/Formats/Gif/ani2.gif")] |
|
||||
[InlineData("../../TestImages/Formats/Gif/giphy.gif")] |
|
||||
[InlineData("../../TestImages/Formats/Bmp/Car.bmp")] |
|
||||
[InlineData("../../TestImages/Formats/Png/cmyk.png")] |
|
||||
public void DecodeThenEncodeImageFromStreamShouldSucceed(string filename) |
|
||||
{ |
|
||||
if (!Directory.Exists("Encoded")) |
|
||||
{ |
|
||||
Directory.CreateDirectory("Encoded"); |
|
||||
} |
|
||||
|
|
||||
FileStream stream = File.OpenRead(filename); |
|
||||
Stopwatch watch = Stopwatch.StartNew(); |
|
||||
Image image = new Image(stream); |
|
||||
|
|
||||
string encodedFilename = "Encoded/" + Path.GetFileName(filename); |
|
||||
|
|
||||
using (FileStream output = File.OpenWrite(encodedFilename)) |
|
||||
{ |
|
||||
image.Save(output); |
|
||||
} |
|
||||
|
|
||||
Trace.WriteLine($"{filename} : {watch.ElapsedMilliseconds}ms"); |
|
||||
} |
|
||||
|
|
||||
[Theory] |
|
||||
[InlineData("../../TestImages/Formats/Jpg/Backdrop.jpg")] |
|
||||
[InlineData("../../TestImages/Formats/Bmp/Car.bmp")] |
|
||||
[InlineData("../../TestImages/Formats/Png/cmyk.png")] |
|
||||
public void QuantizedImageShouldPreserveMaximumColorPrecision(string filename) |
|
||||
{ |
|
||||
if (!Directory.Exists("Quantized")) |
|
||||
{ |
|
||||
Directory.CreateDirectory("Quantized"); |
|
||||
} |
|
||||
|
|
||||
Image image = new Image(File.OpenRead(filename)); |
|
||||
IQuantizer quantizer = new OctreeQuantizer(); |
|
||||
QuantizedImage quantizedImage = quantizer.Quantize(image); |
|
||||
|
|
||||
using (FileStream output = File.OpenWrite($"Quantized/{ Path.GetFileName(filename) }")) |
|
||||
{ |
|
||||
quantizedImage.ToImage().Save(output); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,4 +1,9 @@ |
|||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> |
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> |
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=colors/@EntryIndexedValue">True</s:Boolean> |
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=colors/@EntryIndexedValue">True</s:Boolean> |
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=formats/@EntryIndexedValue">True</s:Boolean> |
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=formats/@EntryIndexedValue">True</s:Boolean> |
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=numerics/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> |
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=helpers/@EntryIndexedValue">True</s:Boolean> |
||||
|
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=numerics/@EntryIndexedValue">True</s:Boolean> |
||||
|
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=processors/@EntryIndexedValue">True</s:Boolean> |
||||
|
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=processors_005Cfilters/@EntryIndexedValue">True</s:Boolean> |
||||
|
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=processors_005Cformats/@EntryIndexedValue">True</s:Boolean> |
||||
|
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=processors_005Csamplers/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> |
||||
@ -0,0 +1,63 @@ |
|||||
|
namespace ImageProcessor.Tests |
||||
|
{ |
||||
|
using System.Diagnostics; |
||||
|
using System.IO; |
||||
|
|
||||
|
using Formats; |
||||
|
|
||||
|
using Xunit; |
||||
|
|
||||
|
public class EncoderDecoderTests : ProcessorTestBase |
||||
|
{ |
||||
|
[Fact] |
||||
|
public void DecodeThenEncodeImageFromStreamShouldSucceed() |
||||
|
{ |
||||
|
if (!Directory.Exists("Encoded")) |
||||
|
{ |
||||
|
Directory.CreateDirectory("Encoded"); |
||||
|
} |
||||
|
|
||||
|
foreach (string file in Files) |
||||
|
{ |
||||
|
using (FileStream stream = File.OpenRead(file)) |
||||
|
{ |
||||
|
Stopwatch watch = Stopwatch.StartNew(); |
||||
|
Image image = new Image(stream); |
||||
|
|
||||
|
string encodedFilename = "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); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,32 @@ |
|||||
|
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
// <copyright file="ProcessorTestBase.cs" company="James South">
|
||||
|
// Copyright © James South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
|
||||
|
namespace ImageProcessor.Tests |
||||
|
{ |
||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The processor test base.
|
||||
|
/// </summary>
|
||||
|
public abstract class ProcessorTestBase |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// The collection of image files to test against.
|
||||
|
/// </summary>
|
||||
|
public static readonly List<string> Files = new List<string> |
||||
|
{ |
||||
|
"../../TestImages/Formats/Jpg/Backdrop.jpg", |
||||
|
"../../TestImages/Formats/Bmp/Car.bmp", |
||||
|
"../../TestImages/Formats/Png/cmyk.png", |
||||
|
"../../TestImages/Formats/Gif/leaf.gif" |
||||
|
|
||||
|
// { "../../TestImages/Formats/Gif/ani.gif" },
|
||||
|
// { "../../TestImages/Formats/Gif/ani2.gif" },
|
||||
|
// { "../../TestImages/Formats/Gif/giphy.gif" },
|
||||
|
}; |
||||
|
} |
||||
|
} |
||||
|
Before Width: | Height: | Size: 69 B |
Loading…
Reference in new issue