-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkflow.cs
More file actions
72 lines (60 loc) · 2.31 KB
/
workflow.cs
File metadata and controls
72 lines (60 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System.Runtime.InteropServices;
using ImSh = SixLabors.ImageSharp;
using static SixLabors.ImageSharp.ImageExtensions;
namespace Frontend;
using Rgba32 = SixLabors.ImageSharp.PixelFormats.Rgba32;
[StructLayout(LayoutKind.Explicit)]
public unsafe struct MyColor //Na mojej architekturze tożsame (nawet co do paddingu) z Rgba32
{
[FieldOffset(0)]
public byte r;
[FieldOffset(1)]
public byte g;
[FieldOffset(2)]
public byte b;
[FieldOffset(3)]
public byte a;
// Pójdę za to do piekła, ale bardzo nie chcę tworzyć nowych obiektów typu Rgba32, skoro już
// włożyłem wysiłek w znalezienie API pozwalającego wrappować istniejącą tablicę w obrazek.
public static unsafe explicit operator Rgba32(MyColor color)
{
return *(Rgba32*)&color;
}
};
public unsafe class Program
{
[DllImport("ImageGenerator.dll", EntryPoint = "GenerateImage")]
public static extern void GenerateImage([In, Out] Rgba32[] color, int width, int height, delegate*<float, bool> tryReportCallback);
public static bool Report(float progress)
{
//Console.WriteLine(progress);
return true;
}
static void Main(string[] args)
{
const int width = 1024;
const int height = 1024;
Rgba32[] array = new Rgba32[width * height];
delegate*<float, bool> tryReportCallback = &Report;
//GenerateImage(array, width, height, tryReportCallback);
Console.WriteLine("1");
//Rgba32 pixels = ConvertAll<MyColor, Rgba32>(array, )
ImSh.Image<Rgba32> image = ImSh.Image.WrapMemory(new Memory<Rgba32>(array), width, height);
for (int i = 0; i < width; i++)
{
int red = (255 * i) / width;
for (int j = 0; j < height; j++)
{
int blue = (255 * j) / height;
array[i * width + j].R = (byte)red;
array[i * width + j].G = (byte)(127 - Math.Floor(126 * Math.Sin(Math.PI * 0.01 * i)));//(byte)((red * blue) / 255);
array[i * width + j].B = (byte)blue;
array[i * width + j].A = 255;
}
}
//image.DangerousTryGetSinglePixelMemory(out Memory<ImSh::PixelFormats.Rgba32> memory);
//var span = memory.Span;
image.Save("Image_0.jpeg");
image.Dispose();
}
}