Ejemplo n.º 1
0
        /// <summary>
        /// Create a <see cref="HeifIccColorProfile"/> from the specified image.
        /// </summary>
        /// <param name="image">The image.</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(SafeHeifImage image)
        {
            HeifIccColorProfile profile = null;

            ulong iccProfileSize = LibHeifNative.heif_image_get_raw_color_profile_size(image).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_get_raw_color_profile(image, ptr);

                    error.ThrowIfError();
                }

                profile = new HeifIccColorProfile(iccProfileBytes, copyToNewArray: false);
            }

            return(profile);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HeifIccColorProfile"/> class.
        /// </summary>
        /// <param name="image">The image.</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(SafeHeifImage image) : base(ColorProfileType.Icc)
        {
            ulong iccProfileSize = LibHeifNative.heif_image_get_raw_color_profile_size(image).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_get_raw_color_profile(image, ptr);

                error.ThrowIfError();
            }
        }