/// <summary> /// This function allocates and initializes an incremental-decoder object, which /// will output the RGB/A samples specified by '<paramref name="colorspace"/>' into a preallocated /// buffer '<paramref name="output_buffer"/>'. The size of this buffer is at least /// '<paramref name="output_buffer_size"/>' and the stride (distance in bytes between two scanlines) /// is specified by '<paramref name="output_stride"/>' /// </summary> /// <remarks> /// Additionally, <paramref name="output_buffer"/> can be passed NULL in which case the output /// buffer will be allocated automatically when the decoding starts. The /// '<paramref name="colorspace"/>' is taken into account for allocating this buffer. All other /// parameters are ignored. /// </remarks> /// <exception cref="InvalidProgramException">Unknown error occured.</exception> /// <exception cref="NotSupportedException"><paramref name="colorspace"/> is not RGB(A) colorspace</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="colorspace"/> is not a valid value</exception> /// <returns><see cref="WebpImageDecoder"/></returns> public static WebpImageDecoder CreateDecoderForRGBX(ILibwebp library, Colorspace colorspace, IntPtr output_buffer, UIntPtr output_buffer_size, int output_stride) { WebpImageDecoder result; if (colorspace >= Colorspace.MODE_LAST) { throw new ArgumentOutOfRangeException(nameof(colorspace)); } if (colorspace == Colorspace.MODE_YUVA || colorspace == Colorspace.MODE_YUV) { throw new NotSupportedException(); } else { var ptr = library.WebPINewRGB(colorspace, output_buffer, output_buffer_size, output_stride); if (ptr == IntPtr.Zero) { throw new Exception(); } else { result = new WebpImageDecoder(library, false); result.decoder = ptr; } } if (result == null) { throw new InvalidProgramException(); } return(result); }
/// <summary>Decrease the reference count toward the loaded native library.</summary> /// <remarks> /// When reference count reaches 0, the native library will be unloaded. /// Calling this method does not guarantee the native library to be unloaded immediately. /// This method will not dispose any objects (Eg: <seealso cref="WebpImageDecoder"/>) created from this <see cref="WebpFactory"/> instance, either. /// </remarks> public void Dispose() { if (this.disposed) { return; } this.disposed = true; Libwebp.Deinit(this.library); this.library = null; }
/// <summary> /// Initialize a new instance of <see cref="WebpFactory"/> from loaded native library. /// </summary> /// <param name="library">The native library.</param> /// <exception cref="ArgumentException">Throws when the given native library is not from <seealso cref="Libwebp.Init(string)"/>.</exception> public WebpFactory(ILibwebp library) { this.disposed = false; if (library is Libwebp lib) { lib.IncreaseReferenceCount(); this.library = library; } else { throw new ArgumentException(nameof(library)); } }
/// <summary> /// Initialize a new instance of <see cref="WebpFactory"/>. /// </summary> /// <param name="libraryPath">The path to the native library.</param> public WebpFactory(string libraryPath) { this.disposed = false; this.library = Libwebp.Init(libraryPath); }
private WebpImageDecoder(ILibwebp library, in bool dummy)
/// <summary> /// This function allocates and initializes an incremental-decoder object, which /// will output the RGB/A samples specified by '<paramref name="colorspace"/>' into a preallocated internal buffer. /// </summary> /// <remarks> /// Equivalent to <seealso cref="CreateDecoderForRGBX(ILibwebp, Colorspace, IntPtr, UIntPtr, int)"/>, with 'output_buffer' is NULL. /// Use <seealso cref="GetDecodedImage(ref int, out int, out int, out int, out IntPtr)"/> or <seealso cref="GetDecodedImage(ref int, out int, out int, out int, out ReadOnlySpan{byte})"/> /// to obtain the decoded data. /// </remarks> /// <exception cref="InvalidProgramException">Unknown error occured.</exception> /// <exception cref="NotSupportedException"><paramref name="colorspace"/> is not RGB(A) colorspace</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="colorspace"/> is not a valid value</exception> /// <returns><see cref="WebpImageDecoder"/></returns> public static WebpImageDecoder CreateDecoderForRGBX(ILibwebp library, Colorspace colorspace) => CreateDecoderForRGBX(library, colorspace, IntPtr.Zero, UIntPtr.Zero, 0);