/// <summary> /// Decodes this instance to a <see cref="HeifImage"/>. /// </summary> /// <param name="colorspace">The destination image color space.</param> /// <param name="chroma">The chroma.</param> /// <param name="options">The decoding options.</param> /// <returns>The decoded image.</returns> /// <exception cref="HeifException"> /// A LibHeif error occurred. /// /// -or- /// /// The color profile type is not supported. /// </exception> /// <exception cref="ObjectDisposedException">The object has been disposed.</exception> public HeifImage Decode(HeifColorspace colorspace, HeifChroma chroma, HeifDecodingOptions options = null) { VerifyNotDisposed(); HeifImage image = null; SafeHeifImage safeHeifImage = null; var imageHandleColorProfile = GetImageHandleColorProfile(); try { heif_error error; if (options != null) { using (var safeHeifDecodingOptions = options.CreateDecodingOptions()) { error = LibHeifNative.heif_decode_image(this.imageHandle, out safeHeifImage, colorspace, chroma, safeHeifDecodingOptions); } } else { error = LibHeifNative.heif_decode_image(this.imageHandle, out safeHeifImage, colorspace, chroma, IntPtr.Zero); } if (error.IsError) { if (this.decodeErrorHandler != null) { this.decodeErrorHandler.Invoke(error); } else { error.ThrowIfError(); } } // Passing the image handle width and height works around a bug with the // heif_image_get_primary_height method in some versions of libheif. image = new HeifImage(safeHeifImage, this.Width, this.Height, imageHandleColorProfile); safeHeifImage = null; } finally { safeHeifImage?.Dispose(); } return(image); }
/// <summary> /// Initializes a new instance of the <see cref="HeifImage"/> class. /// </summary> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="colorspace">The color space.</param> /// <param name="chroma">The chroma.</param> /// <exception cref="ArgumentOutOfRangeException"> /// <paramref name="width"/> is less than or equal to zero. /// /// -or- /// /// <paramref name="height"/> is less than or equal to zero. /// </exception> /// <exception cref="HeifException"> /// A LibHeif error occurred. /// /// -or- /// /// The LibHeif version is not supported. /// </exception> public HeifImage(int width, int height, HeifColorspace colorspace, HeifChroma chroma) { Validate.IsPositive(width, nameof(width)); Validate.IsPositive(height, nameof(height)); LibHeifVersion.ThrowIfNotSupported(); var error = LibHeifNative.heif_image_create(width, height, colorspace, chroma, out this.image); error.ThrowIfError(); // The caller can set a color profile after the image has been created. this.cachedImageColorProfile = null; this.fetchedColorProfileFromImage = true; this.sync = new object(); this.Width = width; this.Height = height; this.Colorspace = colorspace; this.Chroma = chroma; }
internal static extern heif_error heif_decode_image(SafeHeifImageHandle inHandle, out SafeHeifImage outImage, HeifColorspace colorspace, HeifChroma chroma, IntPtr options_MustBeZero);
internal static extern heif_error heif_decode_image(SafeHeifImageHandle inHandle, out SafeHeifImage outImage, HeifColorspace colorspace, HeifChroma chroma, SafeHeifDecodingOptions options);
public static extern IntPtr HeifDecodeImage(HeifImageHandlePointer inHandle, ref HeifImagePointer outImg, HeifColorspace colorspace, HeifChroma chroma, HeifDecodingOptionsPointer options);
internal static extern heif_error heif_image_create(int width, int height, HeifColorspace colorspace, HeifChroma chroma, out SafeHeifImage image);