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.
60 lines
1.9 KiB
60 lines
1.9 KiB
// <copyright file="PhotometricInterpretationTestBase.cs" company="James Jackson-South">
|
|
// Copyright (c) James Jackson-South and contributors.
|
|
// Licensed under the Apache License, Version 2.0.
|
|
// </copyright>
|
|
|
|
namespace ImageSharp.Tests
|
|
{
|
|
using System;
|
|
using Xunit;
|
|
|
|
public abstract class PhotometricInterpretationTestBase
|
|
{
|
|
public static Rgba32[][] Offset(Rgba32[][] input, int xOffset, int yOffset, int width, int height)
|
|
{
|
|
int inputHeight = input.Length;
|
|
int inputWidth = input[0].Length;
|
|
|
|
Rgba32[][] output = new Rgba32[height][];
|
|
|
|
for (int y = 0; y < output.Length; y++)
|
|
{
|
|
output[y] = new Rgba32[width];
|
|
}
|
|
|
|
for (int y = 0; y < inputHeight; y++)
|
|
{
|
|
for (int x = 0; x < inputWidth; x++)
|
|
{
|
|
output[y + yOffset][x + xOffset] = input[y][x];
|
|
}
|
|
}
|
|
|
|
return output;
|
|
}
|
|
|
|
public static void AssertDecode(Rgba32[][] expectedResult, Action<PixelAccessor<Rgba32>> decodeAction)
|
|
{
|
|
int resultWidth = expectedResult[0].Length;
|
|
int resultHeight = expectedResult.Length;
|
|
Image<Rgba32> image = new Image<Rgba32>(resultWidth, resultHeight);
|
|
|
|
using (PixelAccessor<Rgba32> pixels = image.Lock())
|
|
{
|
|
decodeAction(pixels);
|
|
}
|
|
|
|
using (PixelAccessor<Rgba32> pixels = image.Lock())
|
|
{
|
|
for (int y = 0; y < resultHeight; y++)
|
|
{
|
|
for (int x = 0; x < resultWidth; x++)
|
|
{
|
|
Assert.True(expectedResult[y][x] == pixels[x, y],
|
|
$"Pixel ({x}, {y}) should be {expectedResult[y][x]} but was {pixels[x,y]}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|