/// <summary> /// Gets image color profile. /// </summary> /// <returns>The image color profile.</returns> /// <exception cref="HeifException"> /// The color profile type is not supported. /// /// -or- /// /// A LibHeif error occurred. /// </exception> private unsafe HeifColorProfile GetImageColorProfile() { HeifColorProfile profile = null; var colorProfileType = LibHeifNative.heif_image_get_color_profile_type(this.image); switch (colorProfileType) { case heif_color_profile_type.None: break; case heif_color_profile_type.Nclx: profile = new HeifNclxColorProfile(this.image); break; case heif_color_profile_type.IccProfile: case heif_color_profile_type.RestrictedIcc: profile = new HeifIccColorProfile(this.image); break; default: throw new HeifException(Resources.ColorProfileTypeNotSupported); } return(profile); }
/// <summary> /// Initializes a new instance of the <see cref="HeifImage" /> class. /// </summary> /// <param name="image">The image.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="imageHandleColorProfile">The image handle color profile.</param> internal HeifImage(SafeHeifImage image, int width, int height, HeifColorProfile imageHandleColorProfile) { Validate.IsNotNull(image, nameof(image)); this.image = image; this.cachedImageColorProfile = imageHandleColorProfile; this.fetchedColorProfileFromImage = this.cachedImageColorProfile != null; this.sync = new object(); this.Width = width; this.Height = height; this.Colorspace = LibHeifNative.heif_image_get_colorspace(image); this.Chroma = LibHeifNative.heif_image_get_chroma_format(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; }