init commit
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using AForge.Math;
|
||||
|
||||
namespace AForge.Imaging.Textures;
|
||||
|
||||
public class CloudsTexture : ITextureGenerator
|
||||
{
|
||||
private PerlinNoise noise = new PerlinNoise(8, 0.5, 1.0 / 32.0, 1.0);
|
||||
|
||||
private Random rand = new Random();
|
||||
|
||||
private int r;
|
||||
|
||||
public CloudsTexture()
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
public float[,] Generate(int width, int height)
|
||||
{
|
||||
float[,] array = new float[height, width];
|
||||
for (int i = 0; i < height; i++)
|
||||
{
|
||||
for (int j = 0; j < width; j++)
|
||||
{
|
||||
array[i, j] = System.Math.Max(0f, System.Math.Min(1f, (float)noise.Function2D(j + r, i + r) * 0.5f + 0.5f));
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
r = rand.Next(5000);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace AForge.Imaging.Textures;
|
||||
|
||||
public interface ITextureGenerator
|
||||
{
|
||||
float[,] Generate(int width, int height);
|
||||
|
||||
void Reset();
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using AForge.Math;
|
||||
|
||||
namespace AForge.Imaging.Textures;
|
||||
|
||||
public class LabyrinthTexture : ITextureGenerator
|
||||
{
|
||||
private PerlinNoise noise = new PerlinNoise(1, 0.65, 0.0625, 1.0);
|
||||
|
||||
private Random rand = new Random();
|
||||
|
||||
private int r;
|
||||
|
||||
public LabyrinthTexture()
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
public float[,] Generate(int width, int height)
|
||||
{
|
||||
float[,] array = new float[height, width];
|
||||
for (int i = 0; i < height; i++)
|
||||
{
|
||||
for (int j = 0; j < width; j++)
|
||||
{
|
||||
array[i, j] = System.Math.Min(1f, (float)System.Math.Abs(noise.Function2D(j + r, i + r)));
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
r = rand.Next(5000);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using AForge.Math;
|
||||
|
||||
namespace AForge.Imaging.Textures;
|
||||
|
||||
public class MarbleTexture : ITextureGenerator
|
||||
{
|
||||
private PerlinNoise noise = new PerlinNoise(2, 0.65, 1.0 / 32.0, 1.0);
|
||||
|
||||
private Random rand = new Random();
|
||||
|
||||
private int r;
|
||||
|
||||
private double xPeriod = 5.0;
|
||||
|
||||
private double yPeriod = 10.0;
|
||||
|
||||
public double XPeriod
|
||||
{
|
||||
get
|
||||
{
|
||||
return xPeriod;
|
||||
}
|
||||
set
|
||||
{
|
||||
xPeriod = System.Math.Max(2.0, value);
|
||||
}
|
||||
}
|
||||
|
||||
public double YPeriod
|
||||
{
|
||||
get
|
||||
{
|
||||
return yPeriod;
|
||||
}
|
||||
set
|
||||
{
|
||||
yPeriod = System.Math.Max(2.0, value);
|
||||
}
|
||||
}
|
||||
|
||||
public MarbleTexture()
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
public MarbleTexture(double xPeriod, double yPeriod)
|
||||
{
|
||||
this.xPeriod = xPeriod;
|
||||
this.yPeriod = yPeriod;
|
||||
Reset();
|
||||
}
|
||||
|
||||
public float[,] Generate(int width, int height)
|
||||
{
|
||||
float[,] array = new float[height, width];
|
||||
double num = xPeriod / (double)width;
|
||||
double num2 = yPeriod / (double)height;
|
||||
for (int i = 0; i < height; i++)
|
||||
{
|
||||
for (int j = 0; j < width; j++)
|
||||
{
|
||||
array[i, j] = System.Math.Min(1f, (float)System.Math.Abs(System.Math.Sin(((double)j * num + (double)i * num2 + noise.Function2D(j + r, i + r)) * System.Math.PI)));
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
r = rand.Next(5000);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using AForge.Math;
|
||||
|
||||
namespace AForge.Imaging.Textures;
|
||||
|
||||
public class TextileTexture : ITextureGenerator
|
||||
{
|
||||
private PerlinNoise noise = new PerlinNoise(3, 0.65, 0.125, 1.0);
|
||||
|
||||
private Random rand = new Random();
|
||||
|
||||
private int r;
|
||||
|
||||
public TextileTexture()
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
public float[,] Generate(int width, int height)
|
||||
{
|
||||
float[,] array = new float[height, width];
|
||||
for (int i = 0; i < height; i++)
|
||||
{
|
||||
for (int j = 0; j < width; j++)
|
||||
{
|
||||
array[i, j] = System.Math.Max(0f, System.Math.Min(1f, ((float)System.Math.Sin((double)j + noise.Function2D(j + r, i + r)) + (float)System.Math.Sin((double)i + noise.Function2D(j + r, i + r))) * 0.25f + 0.5f));
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
r = rand.Next(5000);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
|
||||
namespace AForge.Imaging.Textures;
|
||||
|
||||
public class TextureTools
|
||||
{
|
||||
private TextureTools()
|
||||
{
|
||||
}
|
||||
|
||||
public unsafe static Bitmap ToBitmap(float[,] texture)
|
||||
{
|
||||
int length = texture.GetLength(1);
|
||||
int length2 = texture.GetLength(0);
|
||||
Bitmap val = Image.CreateGrayscaleImage(length, length2);
|
||||
BitmapData val2 = val.LockBits(new Rectangle(0, 0, length, length2), (ImageLockMode)3, (PixelFormat)198659);
|
||||
byte* ptr = (byte*)val2.Scan0.ToPointer();
|
||||
int num = val2.Stride - length;
|
||||
for (int i = 0; i < length2; i++)
|
||||
{
|
||||
int num2 = 0;
|
||||
while (num2 < length)
|
||||
{
|
||||
*ptr = (byte)(texture[i, num2] * 255f);
|
||||
num2++;
|
||||
ptr++;
|
||||
}
|
||||
ptr += num;
|
||||
}
|
||||
val.UnlockBits(val2);
|
||||
return val;
|
||||
}
|
||||
|
||||
public static float[,] FromBitmap(Bitmap image)
|
||||
{
|
||||
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
|
||||
BitmapData val = image.LockBits(new Rectangle(0, 0, ((Image)image).Width, ((Image)image).Height), (ImageLockMode)1, ((Image)image).PixelFormat);
|
||||
float[,] result = FromBitmap(val);
|
||||
image.UnlockBits(val);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static float[,] FromBitmap(BitmapData imageData)
|
||||
{
|
||||
return FromBitmap(new UnmanagedImage(imageData));
|
||||
}
|
||||
|
||||
public unsafe static float[,] FromBitmap(UnmanagedImage image)
|
||||
{
|
||||
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
||||
//IL_000b: Invalid comparison between Unknown and I4
|
||||
if ((int)image.PixelFormat != 198659)
|
||||
{
|
||||
throw new UnsupportedImageFormatException("Only grayscale (8 bpp indexed images) are supported.");
|
||||
}
|
||||
int width = image.Width;
|
||||
int height = image.Height;
|
||||
float[,] array = new float[height, width];
|
||||
byte* ptr = (byte*)image.ImageData.ToPointer();
|
||||
int num = image.Stride - width;
|
||||
for (int i = 0; i < height; i++)
|
||||
{
|
||||
int num2 = 0;
|
||||
while (num2 < width)
|
||||
{
|
||||
array[i, num2] = (float)(int)(*ptr) / 255f;
|
||||
num2++;
|
||||
ptr++;
|
||||
}
|
||||
ptr += num;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using AForge.Math;
|
||||
|
||||
namespace AForge.Imaging.Textures;
|
||||
|
||||
public class WoodTexture : ITextureGenerator
|
||||
{
|
||||
private PerlinNoise noise = new PerlinNoise(8, 0.5, 1.0 / 32.0, 0.05);
|
||||
|
||||
private Random rand = new Random();
|
||||
|
||||
private int r;
|
||||
|
||||
private double rings = 12.0;
|
||||
|
||||
public double Rings
|
||||
{
|
||||
get
|
||||
{
|
||||
return rings;
|
||||
}
|
||||
set
|
||||
{
|
||||
rings = System.Math.Max(3.0, value);
|
||||
}
|
||||
}
|
||||
|
||||
public WoodTexture()
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
public WoodTexture(double rings)
|
||||
{
|
||||
this.rings = rings;
|
||||
Reset();
|
||||
}
|
||||
|
||||
public float[,] Generate(int width, int height)
|
||||
{
|
||||
float[,] array = new float[height, width];
|
||||
int num = width / 2;
|
||||
int num2 = height / 2;
|
||||
for (int i = 0; i < height; i++)
|
||||
{
|
||||
for (int j = 0; j < width; j++)
|
||||
{
|
||||
double num3 = (double)(j - num) / (double)width;
|
||||
double num4 = (double)(i - num2) / (double)height;
|
||||
array[i, j] = System.Math.Min(1f, (float)System.Math.Abs(System.Math.Sin((System.Math.Sqrt(num3 * num3 + num4 * num4) + noise.Function2D(j + r, i + r)) * System.Math.PI * 2.0 * rings)));
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
r = rand.Next(5000);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user