/// <summary> /// Initializes a new instance of the <see cref="HeifImageHandle"/> class. /// </summary> /// <param name="handle">The handle.</param> /// <param name="decodeErrorHandler">The decode error handler.</param> /// <exception cref="ArgumentNullException"><paramref name="handle"/> is null.</exception> internal HeifImageHandle(SafeHeifImageHandle handle, HeifContext.ImageDecodeErrorDelegate decodeErrorHandler = null) { Validate.IsNotNull(handle, nameof(handle)); this.imageHandle = handle; this.decodeErrorHandler = decodeErrorHandler; }
/// <summary> /// Create a <see cref="HeifNclxColorProfile"/> from the specified image handle. /// </summary> /// <param name="handle">The handle.</param> /// <returns>The created profile.</returns> /// <exception cref="HeifException"> /// A LibHeif error occurred. /// </exception> internal static unsafe HeifNclxColorProfile TryCreate(SafeHeifImageHandle handle) { HeifNclxColorProfile profile = null; SafeHeifNclxColorProfile safeNclxProfile = null; try { var error = LibHeifNative.heif_image_handle_get_nclx_color_profile(handle, out safeNclxProfile); if (error.ErrorCode == heif_error_code.Ok) { var nclxProfileV1 = (heif_nclx_color_profile_v1 *)safeNclxProfile.DangerousGetHandle(); profile = new HeifNclxColorProfile(nclxProfileV1->colorPrimaries, nclxProfileV1->transferCharacteristics, nclxProfileV1->matrixCoefficients, nclxProfileV1->fullRange != 0); } else { if (!LibHeifVersion.Is1Point10OrLater || error.ErrorCode != heif_error_code.Color_profile_does_not_exist) { error.ThrowIfError(); } } } finally { safeNclxProfile?.Dispose(); } return(profile); }
/// <summary> /// Create a <see cref="HeifIccColorProfile"/> from the specified image handle. /// </summary> /// <param name="handle">The handle.</param> /// <returns>The created profile.</returns> /// <exception cref="HeifException"> /// A LibHeif error occurred. /// /// -or- /// /// The ICC profile is larger than 2 GB. /// </exception> internal static unsafe HeifIccColorProfile TryCreate(SafeHeifImageHandle handle) { HeifIccColorProfile profile = null; ulong iccProfileSize = LibHeifNative.heif_image_handle_get_raw_color_profile_size(handle).ToUInt64(); if (iccProfileSize > 0) { if (iccProfileSize > int.MaxValue) { ExceptionUtil.ThrowHeifException(Resources.IccProfileLargerThan2Gb); } byte[] iccProfileBytes = new byte[iccProfileSize]; fixed(byte *ptr = iccProfileBytes) { var error = LibHeifNative.heif_image_handle_get_raw_color_profile(handle, ptr); error.ThrowIfError(); } profile = new HeifIccColorProfile(iccProfileBytes, copyToNewArray: false); } return(profile); }
/// <summary> /// Gets the auxiliary image handle. /// </summary> /// <param name="id">The auxiliary image id.</param> /// <returns>The auxiliary image handle.</returns> /// <exception cref="HeifException">A LibHeif error occurred.</exception> /// <exception cref="ObjectDisposedException">The object has been disposed.</exception> /// <seealso cref="GetAuxiliaryImageIds"/> public HeifImageHandle GetAuxiliaryImage(HeifItemId id) { VerifyNotDisposed(); if (LibHeifVersion.Is1Point11OrLater) { HeifImageHandle aux = null; SafeHeifImageHandle auxSafeHandle = null; try { var error = LibHeifNative.heif_image_handle_get_auxiliary_image_handle(this.imageHandle, id, out auxSafeHandle); error.ThrowIfError(); aux = new HeifImageHandle(auxSafeHandle, this.decodeErrorHandler, AuxiliaryImageType.VendorSpecific); auxSafeHandle = null; } finally { auxSafeHandle?.Dispose(); } return(aux); } else { throw new HeifException(Resources.AuxiliaryImageAPINotSupported); } }
/// <summary> /// Initializes a new instance of the <see cref="HeifImageHandle"/> class. /// </summary> /// <param name="handle">The handle.</param> /// <param name="decodeErrorHandler">The decode error handler.</param> /// <param name="auxiliaryImageType">The auxiliary image type.</param> /// <exception cref="ArgumentNullException"><paramref name="handle"/> is null.</exception> private HeifImageHandle(SafeHeifImageHandle handle, HeifContext.ImageDecodeErrorDelegate decodeErrorHandler, AuxiliaryImageType auxiliaryImageType) { Validate.IsNotNull(handle, nameof(handle)); this.imageHandle = handle; this.decodeErrorHandler = decodeErrorHandler; this.auxiliaryImageType = auxiliaryImageType; }
/// <summary> /// Initializes a new instance of the <see cref="HeifNclxColorProfile"/> class. /// </summary> /// <param name="handle">The handle.</param> /// <exception cref="HeifException">A LibHeif error occurred.</exception> internal unsafe HeifNclxColorProfile(SafeHeifImageHandle handle) : base(ColorProfileType.Nclx) { SafeHeifNclxColorProfile safeNclxProfile = null; try { var error = LibHeifNative.heif_image_handle_get_nclx_color_profile(handle, out safeNclxProfile); error.ThrowIfError(); var nclxProfileV1 = (heif_nclx_color_profile_v1 *)safeNclxProfile.DangerousGetHandle(); this.ColorPrimaries = nclxProfileV1->colorPrimaries; this.TransferCharacteristics = nclxProfileV1->transferCharacteristics; this.MatrixCoefficients = nclxProfileV1->matrixCoefficients; this.FullRange = nclxProfileV1->fullRange != 0; } finally { safeNclxProfile?.Dispose(); } }
/// <summary> /// Gets the thumbnail image handle. /// </summary> /// <param name="id">The thumbnail image id.</param> /// <returns>The thumbnail image handle.</returns> /// <exception cref="HeifException">A LibHeif error occurred.</exception> /// <exception cref="ObjectDisposedException">The object has been disposed.</exception> public HeifImageHandle GetThumbnailImage(HeifItemId id) { VerifyNotDisposed(); HeifImageHandle thumbnail = null; SafeHeifImageHandle thumbnailSafeHandle = null; try { var error = LibHeifNative.heif_image_handle_get_thumbnail(this.imageHandle, id, out thumbnailSafeHandle); error.ThrowIfError(); thumbnail = new HeifImageHandle(thumbnailSafeHandle, this.decodeErrorHandler); thumbnailSafeHandle = null; } finally { thumbnailSafeHandle?.Dispose(); } return(thumbnail); }
/// <summary> /// Gets the depth images. /// </summary> /// <param name="id">The depth image id.</param> /// <returns>The meta-data bytes.</returns> /// <exception cref="HeifException">A LibHeif error occurred.</exception> /// <exception cref="ObjectDisposedException">The object has been disposed.</exception> public HeifImageHandle GetDepthImage(HeifItemId id) { VerifyNotDisposed(); HeifImageHandle depth = null; SafeHeifImageHandle depthSafeHandle = null; try { var error = LibHeifNative.heif_image_handle_get_depth_image_handle(this.imageHandle, id, out depthSafeHandle); error.ThrowIfError(); depth = new HeifImageHandle(depthSafeHandle, this.decodeErrorHandler); depthSafeHandle = null; } finally { depthSafeHandle?.Dispose(); } return(depth); }
/// <summary> /// Initializes a new instance of the <see cref="HeifIccColorProfile"/> class. /// </summary> /// <param name="handle">The handle.</param> /// <exception cref="HeifException"> /// A LibHeif error occurred. /// /// -or- /// /// The ICC profile is zero bytes. /// /// -or- /// /// The ICC profile is larger than 2 GB. /// </exception> internal unsafe HeifIccColorProfile(SafeHeifImageHandle handle) : base(ColorProfileType.Icc) { ulong iccProfileSize = LibHeifNative.heif_image_handle_get_raw_color_profile_size(handle).ToUInt64(); if (iccProfileSize == 0) { ExceptionUtil.ThrowHeifException(Resources.IccProfileZeroBytes); } else if (iccProfileSize > int.MaxValue) { ExceptionUtil.ThrowHeifException(Resources.IccProfileLargerThan2Gb); } this.iccProfileBytes = new byte[iccProfileSize]; fixed(byte *ptr = this.iccProfileBytes) { var error = LibHeifNative.heif_image_handle_get_raw_color_profile(handle, ptr); error.ThrowIfError(); } }
/// <summary> /// Initializes a new instance of the <see cref="HeifImageHandle"/> class. /// </summary> /// <param name="handle">The handle.</param> /// <param name="decodeErrorHandler">The decode error handler.</param> /// <exception cref="ArgumentNullException"><paramref name="handle"/> is null.</exception> internal HeifImageHandle(SafeHeifImageHandle handle, HeifContext.ImageDecodeErrorDelegate decodeErrorHandler = null) : this(handle, decodeErrorHandler, AuxiliaryImageType.None) { }