vendoring NetVips
This commit is contained in:
parent
36a0f8d39c
commit
33e9d5f43a
41 changed files with 21749 additions and 0 deletions
71
vendor/NetVips/Region.cs
vendored
Normal file
71
vendor/NetVips/Region.cs
vendored
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using NetVips.Internal;
|
||||
|
||||
namespace NetVips;
|
||||
|
||||
/// <summary>
|
||||
/// Wrap a <see cref="VipsRegion"/> object.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A region is a small part of an image. You use regions to read pixels
|
||||
/// out of images without storing the entire image in memory.
|
||||
/// At least libvips 8.8 is needed.
|
||||
/// </remarks>
|
||||
public class Region : VipsObject
|
||||
{
|
||||
private Region(nint pointer) : base(pointer)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Make a region on an image.
|
||||
/// </summary>
|
||||
/// <param name="image"><see cref="Image"/> to create this region on.</param>
|
||||
/// <returns>A new <see cref="Region"/>.</returns>
|
||||
/// <exception cref="VipsException">If unable to make a new region on <paramref name="image"/>.</exception>
|
||||
public static Region New(Image image)
|
||||
{
|
||||
var vi = VipsRegion.New(image);
|
||||
if (vi == IntPtr.Zero)
|
||||
{
|
||||
throw new VipsException("unable to make region");
|
||||
}
|
||||
|
||||
return new Region(vi);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Width of pixels held by region.
|
||||
/// </summary>
|
||||
public int Width => VipsRegion.Width(this);
|
||||
|
||||
/// <summary>
|
||||
/// Height of pixels held by region.
|
||||
/// </summary>
|
||||
public int Height => VipsRegion.Height(this);
|
||||
|
||||
/// <summary>
|
||||
/// Fetch an area of pixels.
|
||||
/// </summary>
|
||||
/// <param name="left">Left edge of area to fetch.</param>
|
||||
/// <param name="top">Top edge of area to fetch.</param>
|
||||
/// <param name="width">Width of area to fetch.</param>
|
||||
/// <param name="height">Height of area to fetch.</param>
|
||||
/// <returns>An array of bytes filled with pixel data.</returns>
|
||||
public byte[] Fetch(int left, int top, int width, int height)
|
||||
{
|
||||
var pointer = VipsRegion.Fetch(this, left, top, width, height, out var size);
|
||||
if (pointer == IntPtr.Zero)
|
||||
{
|
||||
throw new VipsException("unable to fetch from region");
|
||||
}
|
||||
|
||||
var managedArray = new byte[size];
|
||||
Marshal.Copy(pointer, managedArray, 0, (int)size);
|
||||
|
||||
GLib.GFree(pointer);
|
||||
|
||||
return managedArray;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue