/// <summary>
        /// Read all image frames.
        /// </summary>
        /// <param name="data">The span of bytes to read the image data from.</param>
        /// <param name="readSettings">The settings to use when reading the image.</param>
        /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
        public void Read(ReadOnlySpan <byte> data, IMagickReadSettings <QuantumType>?readSettings)
        {
            Throw.IfEmpty(nameof(data), data);

            Clear();
            AddImages(data, readSettings, false);
        }
        /// <summary>
        /// Read only metadata and not the pixel data from all image frames.
        /// </summary>
        /// <param name="data">The sequence of bytes to read the image data from.</param>
        /// <param name="readSettings">The settings to use when reading the image.</param>
        /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
        public void Ping(ReadOnlySequence <byte> data, IMagickReadSettings <QuantumType>?readSettings)
        {
            Throw.IfEmpty(nameof(data), data);

            Clear();
            AddImages(data, readSettings, true);
        }
Beispiel #3
0
        /// <summary>
        /// Returns the format information. The header of the image in the span of bytes is used to
        /// determine the format.
        /// </summary>
        /// <param name="data">The span of bytes to read the image header from.</param>
        /// <returns>The format information.</returns>
        public static MagickFormatInfo?Create(ReadOnlySpan <byte> data)
        {
            Throw.IfEmpty(nameof(data), data);

            var instance = new NativeMagickFormatInfo();

            instance.GetInfoWithBlob(data, data.Length);

            return(Create(instance));
        }
Beispiel #4
0
        private void CheckValues <T>(int x, int y, int width, int height, ReadOnlySpan <T> values)
        {
            CheckIndex(x, y);
            Throw.IfEmpty(nameof(values), values);
            Throw.IfFalse(nameof(values), values.Length % Channels == 0, $"Values should have {Channels} channels.");

            int length = values.Length;
            int max    = width * height * Channels;

            Throw.IfTrue(nameof(values), length > max, "Too many values specified.");

            length = (x * y * Channels) + length;
            max    = Image.Width * Image.Height * Channels;
            Throw.IfTrue(nameof(values), length > max, "Too many values specified.");
        }
Beispiel #5
0
        /// <summary>
        /// Read single image frame.
        /// </summary>
        /// <param name="data">The span of quantum to read the image data from.</param>
        /// <param name="settings">The pixel settings to use when reading the image.</param>
        /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
        public void ReadPixels(ReadOnlySpan <QuantumType> data, IPixelReadSettings <QuantumType>?settings)
        {
            Throw.IfEmpty(nameof(data), data);
            Throw.IfNull(nameof(settings), settings);
            Throw.IfTrue(nameof(settings), string.IsNullOrEmpty(settings.Mapping), "Pixel storage mapping should be defined.");
            Throw.IfTrue(nameof(settings), settings.StorageType != StorageType.Quantum, $"Storage type should be {nameof(StorageType.Quantum)}.");

            var newReadSettings = CreateReadSettings(settings.ReadSettings);

            SetSettings(newReadSettings);

            var count          = data.Length;
            var expectedLength = GetExpectedLength(settings);

            Throw.IfTrue(nameof(data), count < expectedLength, "The count is " + count + " but should be at least " + expectedLength + ".");

            _nativeInstance.ReadPixels(settings.ReadSettings.Width !.Value, settings.ReadSettings.Height !.Value, settings.Mapping, settings.StorageType, data, 0);
        }
Beispiel #6
0
        /// <summary>
        /// Read single image frame.
        /// </summary>
        /// <param name="data">The sequence of bytes to read the image data from.</param>
        /// <param name="readSettings">The settings to use when reading the image.</param>
        /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
        public void Read(ReadOnlySequence <byte> data, IMagickReadSettings <QuantumType>?readSettings)
        {
            Throw.IfEmpty(nameof(data), data);

            Read(data, readSettings, false);
        }
Beispiel #7
0
        /// <summary>
        /// Reads only metadata and not the pixel data.
        /// </summary>
        /// <param name="data">The span of bytes to read the information from.</param>
        /// <param name="readSettings">The settings to use when reading the image.</param>
        /// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
        public void Ping(ReadOnlySpan <byte> data, IMagickReadSettings <QuantumType>?readSettings)
        {
            Throw.IfEmpty(nameof(data), data);

            Read(data, readSettings, true);
        }