コード例 #1
0
        /// <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);
        }
コード例 #2
0
ファイル: HeifImage.cs プロジェクト: 0xC0000054/libheif-sharp
        /// <summary>
        /// Updates the cached color profiles while locked.
        /// </summary>
        /// <exception cref="HeifException">
        /// The color profile type is not supported.
        ///
        /// -or-
        ///
        /// A LibHeif error occurred.
        /// </exception>
        private void UpdateCachedColorProfilesWhileLocked()
        {
            if (LibHeifVersion.Is1Point12OrLater)
            {
                this.cachedIccColorProfile  = HeifIccColorProfile.TryCreate(this.image);
                this.cachedNclxColorProfile = HeifNclxColorProfile.TryCreate(this.image);
            }
            else
            {
                // LibHeif version 1.11 and earlier will crash when retrieving the NCLX color
                // profile if the image does not have one.
                var colorProfileType = LibHeifNative.heif_image_get_color_profile_type(this.image);

                switch (colorProfileType)
                {
                case heif_color_profile_type.None:
                    this.cachedIccColorProfile  = null;
                    this.cachedNclxColorProfile = null;
                    break;

                case heif_color_profile_type.Nclx:
                    this.cachedIccColorProfile  = null;
                    this.cachedNclxColorProfile = HeifNclxColorProfile.TryCreate(this.image);
                    break;

                case heif_color_profile_type.IccProfile:
                case heif_color_profile_type.RestrictedIcc:
                    this.cachedIccColorProfile  = HeifIccColorProfile.TryCreate(this.image);
                    this.cachedNclxColorProfile = null;
                    break;

                default:
                    throw new HeifException(Resources.ColorProfileTypeNotSupported);
                }
            }
        }