コード例 #1
0
        /// <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);
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HeifNclxColorProfile"/> class.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <exception cref="HeifException">A LibHeif error occurred.</exception>
        internal unsafe HeifNclxColorProfile(SafeHeifImage image) : base(ColorProfileType.Nclx)
        {
            SafeHeifNclxColorProfile safeNclxProfile = null;

            try
            {
                var error = LibHeifNative.heif_image_get_nclx_color_profile(image, 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();
            }
        }