18 using SixLabors.ImageSharp;
19 using SixLabors.ImageSharp.Advanced;
20 using SixLabors.ImageSharp.Processing;
23 using System.Runtime.InteropServices;
38 public RasterImageFile(
string fileName,
bool alpha =
true,
bool interpolate =
true)
44 image = Image.Load<SixLabors.ImageSharp.PixelFormats.Rgba32>(fileName, out SixLabors.ImageSharp.Formats.IImageFormat format);
48 image = Image.Load<SixLabors.ImageSharp.PixelFormats.Rgb24>(fileName, out SixLabors.ImageSharp.Formats.IImageFormat format);
51 image.Mutate(x => x.AutoOrient());
53 int stride = image.Width * (alpha ? 4 : 3);
54 int size = stride * image.Height;
56 IntPtr tbr = Marshal.AllocHGlobal(size);
57 GC.AddMemoryPressure(size);
65 Image<SixLabors.ImageSharp.PixelFormats.Rgba32> img = (Image<SixLabors.ImageSharp.PixelFormats.Rgba32>)image;
67 for (
int y = 0; y < image.Height; y++)
69 Memory<SixLabors.ImageSharp.PixelFormats.Rgba32> row = img.DangerousGetPixelRowMemory(y);
71 Span<SixLabors.ImageSharp.PixelFormats.Rgba32> newRow =
new Span<SixLabors.ImageSharp.PixelFormats.Rgba32>(pointer.ToPointer(), row.Length);
72 row.Span.CopyTo(newRow);
74 pointer = IntPtr.Add(pointer, stride);
79 Image<SixLabors.ImageSharp.PixelFormats.Rgb24> img = (Image<SixLabors.ImageSharp.PixelFormats.Rgb24>)image;
81 for (
int y = 0; y < image.Height; y++)
83 Memory<SixLabors.ImageSharp.PixelFormats.Rgb24> row = img.DangerousGetPixelRowMemory(y);
85 Span<SixLabors.ImageSharp.PixelFormats.Rgb24> newRow =
new Span<SixLabors.ImageSharp.PixelFormats.Rgb24>(pointer.ToPointer(), row.Length);
86 row.Span.CopyTo(newRow);
88 pointer = IntPtr.Add(pointer, stride);
93 this.
Width = image.Width;
94 this.
Height = image.Height;
97 this.
Id = Guid.NewGuid().ToString();
120 image = Image.Load<SixLabors.ImageSharp.PixelFormats.Rgba32>(imageStream, out SixLabors.ImageSharp.Formats.IImageFormat format);
124 image = Image.Load<SixLabors.ImageSharp.PixelFormats.Rgb24>(imageStream, out SixLabors.ImageSharp.Formats.IImageFormat format);
127 image.Mutate(x => x.AutoOrient());
129 int stride = image.Width * (alpha ? 4 : 3);
130 int size = stride * image.Height;
132 IntPtr tbr = Marshal.AllocHGlobal(size);
133 GC.AddMemoryPressure(size);
135 IntPtr pointer = tbr;
141 Image<SixLabors.ImageSharp.PixelFormats.Rgba32> img = (Image<SixLabors.ImageSharp.PixelFormats.Rgba32>)image;
143 for (
int y = 0; y < image.Height; y++)
145 Memory<SixLabors.ImageSharp.PixelFormats.Rgba32> row = img.DangerousGetPixelRowMemory(y);
147 Span<SixLabors.ImageSharp.PixelFormats.Rgba32> newRow =
new Span<SixLabors.ImageSharp.PixelFormats.Rgba32>(pointer.ToPointer(), row.Length);
148 row.Span.CopyTo(newRow);
150 pointer = IntPtr.Add(pointer, stride);
155 Image<SixLabors.ImageSharp.PixelFormats.Rgb24> img = (Image<SixLabors.ImageSharp.PixelFormats.Rgb24>)image;
157 for (
int y = 0; y < image.Height; y++)
159 Memory<SixLabors.ImageSharp.PixelFormats.Rgb24> row = img.DangerousGetPixelRowMemory(y);
161 Span<SixLabors.ImageSharp.PixelFormats.Rgb24> newRow =
new Span<SixLabors.ImageSharp.PixelFormats.Rgb24>(pointer.ToPointer(), row.Length);
162 row.Span.CopyTo(newRow);
164 pointer = IntPtr.Add(pointer, stride);
169 this.
Width = image.Width;
170 this.
Height = image.Height;
173 this.
Id = Guid.NewGuid().ToString();
185 public RasterImageStream(IntPtr imageAddress,
int imageLength,
bool alpha =
true,
bool interpolate =
true)
189 ReadOnlySpan<byte> imageSpan =
new ReadOnlySpan<byte>((
void*)imageAddress, imageLength);
195 image = Image.Load<SixLabors.ImageSharp.PixelFormats.Rgba32>(imageSpan, out SixLabors.ImageSharp.Formats.IImageFormat format);
199 image = Image.Load<SixLabors.ImageSharp.PixelFormats.Rgb24>(imageSpan, out SixLabors.ImageSharp.Formats.IImageFormat format);
202 image.Mutate(x => x.AutoOrient());
204 int stride = image.Width * (alpha ? 4 : 3);
205 int size = stride * image.Height;
207 IntPtr tbr = Marshal.AllocHGlobal(size);
208 GC.AddMemoryPressure(size);
210 IntPtr pointer = tbr;
214 Image<SixLabors.ImageSharp.PixelFormats.Rgba32> img = (Image<SixLabors.ImageSharp.PixelFormats.Rgba32>)image;
216 for (
int y = 0; y < image.Height; y++)
218 Memory<SixLabors.ImageSharp.PixelFormats.Rgba32> row = img.DangerousGetPixelRowMemory(y);
220 Span<SixLabors.ImageSharp.PixelFormats.Rgba32> newRow =
new Span<SixLabors.ImageSharp.PixelFormats.Rgba32>(pointer.ToPointer(), row.Length);
221 row.Span.CopyTo(newRow);
223 pointer = IntPtr.Add(pointer, stride);
228 Image<SixLabors.ImageSharp.PixelFormats.Rgb24> img = (Image<SixLabors.ImageSharp.PixelFormats.Rgb24>)image;
230 for (
int y = 0; y < image.Height; y++)
232 Memory<SixLabors.ImageSharp.PixelFormats.Rgb24> row = img.DangerousGetPixelRowMemory(y);
234 Span<SixLabors.ImageSharp.PixelFormats.Rgb24> newRow =
new Span<SixLabors.ImageSharp.PixelFormats.Rgb24>(pointer.ToPointer(), row.Length);
235 row.Span.CopyTo(newRow);
237 pointer = IntPtr.Add(pointer, stride);
241 this.
Width = image.Width;
242 this.
Height = image.Height;
245 this.
Id = Guid.NewGuid().ToString();