36 lines
769 B
C#
36 lines
769 B
C#
using SkiaSharp;
|
|
|
|
namespace DigitalImageProcessing
|
|
{
|
|
internal enum SamplerMethod
|
|
{
|
|
None = 0,
|
|
Repeat = 1,
|
|
Mirror = 2,
|
|
Clamp = 3,
|
|
}
|
|
internal class Sampler
|
|
{
|
|
private SKBitmap bitmap;
|
|
public SamplerMethod Method { get; set; }
|
|
public Sampler(SKBitmap bitmap)
|
|
{
|
|
this.bitmap = bitmap;
|
|
}
|
|
public SKColor this[int x, int y]
|
|
{
|
|
get
|
|
{
|
|
return Method switch
|
|
{
|
|
SamplerMethod.None => bitmap.GetPixel(x, y),
|
|
SamplerMethod.Repeat => bitmap.GetPixel((x + bitmap.Width) % bitmap.Width, (y + bitmap.Height) % bitmap.Height),
|
|
|
|
SamplerMethod.Clamp => bitmap.GetPixel(int.Clamp(x, 0, bitmap.Width - 1), int.Clamp(y, 0, bitmap.Height - 1)),
|
|
SamplerMethod.Mirror or _ => throw new NotImplementedException(),
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}
|