//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
//
using System.Text;
using Xunit.Abstractions;
// ReSharper disable InconsistentNaming
namespace ImageSharp.Tests
{
using System;
using System.Diagnostics;
using ImageSharp.Formats.Jpg;
public class JpegUtilityTestFixture : MeasureFixture
{
public JpegUtilityTestFixture(ITestOutputHelper output) : base(output)
{
}
// ReSharper disable once InconsistentNaming
public static float[] Create8x8FloatData()
{
float[] result = new float[64];
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
result[i * 8 + j] = i * 10 + j;
}
}
return result;
}
// ReSharper disable once InconsistentNaming
public static int[] Create8x8IntData()
{
int[] result = new int[64];
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
result[i * 8 + j] = i * 10 + j;
}
}
return result;
}
// ReSharper disable once InconsistentNaming
public static int[] Create8x8RandomIntData(int minValue, int maxValue, int seed = 42)
{
Random rnd = new Random(seed);
int[] result = new int[64];
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
result[i * 8 + j] = rnd.Next(minValue, maxValue);
}
}
return result;
}
internal static MutableSpan Create8x8RandomFloatData(int minValue, int maxValue, int seed = 42)
=> new MutableSpan(Create8x8RandomIntData(minValue, maxValue, seed)).ConvertToFloat32MutableSpan();
internal void Print8x8Data(MutableSpan data) => this.Print8x8Data(data.Data);
internal void Print8x8Data(T[] data)
{
StringBuilder bld = new StringBuilder();
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
bld.Append($"{data[i * 8 + j],3} ");
}
bld.AppendLine();
}
this.Output.WriteLine(bld.ToString());
}
internal void PrintLinearData(T[] data) => this.PrintLinearData(new MutableSpan(data), data.Length);
internal void PrintLinearData(MutableSpan data, int count = -1)
{
if (count < 0) count = data.TotalCount;
StringBuilder bld = new StringBuilder();
for (int i = 0; i < count; i++)
{
bld.Append($"{data[i],3} ");
}
this.Output.WriteLine(bld.ToString());
}
protected void Print(string msg)
{
Debug.WriteLine(msg);
this.Output.WriteLine(msg);
}
}
}