// by Diplomat
#pragma warning disable 0105
using System;
using System.Runtime.InteropServices;
using Devolutions.IronRdp.Diplomat;
#pragma warning restore 0105
namespace Devolutions.IronRdp;
#nullable enable
public partial class DecodedImage: IDisposable
{
private unsafe Raw.DecodedImage* _inner;
public BytesSlice Data
{
get
{
return GetData();
}
}
public ushort Height
{
get
{
return GetHeight();
}
}
public ushort Width
{
get
{
return GetWidth();
}
}
///
/// Creates a managed DecodedImage from a raw handle.
///
///
/// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free).
///
/// This constructor assumes the raw struct is allocated on Rust side.
/// If implemented, the custom Drop implementation on Rust side WILL run on destruction.
///
public unsafe DecodedImage(Raw.DecodedImage* handle)
{
_inner = handle;
}
///
/// A DecodedImage allocated on Rust side.
///
public static DecodedImage New(PixelFormat pixelFormat, ushort width, ushort height)
{
unsafe
{
Raw.PixelFormat pixelFormatRaw;
pixelFormatRaw = (Raw.PixelFormat)pixelFormat;
Raw.DecodedImage* retVal = Raw.DecodedImage.New(pixelFormatRaw, width, height);
return new DecodedImage(retVal);
}
}
///
/// A BytesSlice allocated on Rust side.
///
public BytesSlice GetData()
{
unsafe
{
if (_inner == null)
{
throw new ObjectDisposedException("DecodedImage");
}
Raw.BytesSlice* retVal = Raw.DecodedImage.GetData(_inner);
return new BytesSlice(retVal);
}
}
public ushort GetWidth()
{
unsafe
{
if (_inner == null)
{
throw new ObjectDisposedException("DecodedImage");
}
ushort retVal = Raw.DecodedImage.GetWidth(_inner);
return retVal;
}
}
public ushort GetHeight()
{
unsafe
{
if (_inner == null)
{
throw new ObjectDisposedException("DecodedImage");
}
ushort retVal = Raw.DecodedImage.GetHeight(_inner);
return retVal;
}
}
///
/// Returns the underlying raw handle.
///
public unsafe Raw.DecodedImage* AsFFI()
{
return _inner;
}
///
/// Destroys the underlying object immediately.
///
public void Dispose()
{
unsafe
{
if (_inner == null)
{
return;
}
Raw.DecodedImage.Destroy(_inner);
_inner = null;
GC.SuppressFinalize(this);
}
}
~DecodedImage()
{
Dispose();
}
}