public void ShouldSetTheDefineWhenSetToTrue()
            {
                var defines = new BmpReadDefines
                {
                    IgnoreFileSize = true,
                };

                using (var image = new MagickImage())
                {
                    image.Settings.SetDefines(defines);

                    Assert.Equal("true", image.Settings.GetDefine(MagickFormat.Bmp, "ignore-filesize"));
                }
            }
            public void ShouldNotSetTheDefineWhenSetToFalse()
            {
                var defines = new BmpReadDefines
                {
                    IgnoreFileSize = false,
                };

                using (var image = new MagickImage())
                {
                    image.Settings.SetDefines(defines);

                    Assert.Null(image.Settings.GetDefine(MagickFormat.Bmp, "ignore-filesize"));
                }
            }
Ejemplo n.º 3
0
        public Image <TPixel> Decode <TPixel>(Configuration configuration, Stream stream)
            where TPixel : unmanaged, ImageSharp.PixelFormats.IPixel <TPixel>
        {
            var bmpReadDefines = new BmpReadDefines
            {
                IgnoreFileSize = !this.validate
            };

            var settings = new MagickReadSettings();

            settings.SetDefines(bmpReadDefines);

            using var magickImageCollection = new MagickImageCollection(stream, settings);
            var framesList = new List <ImageFrame <TPixel> >();

            foreach (IMagickImage <ushort> magicFrame in magickImageCollection)
            {
                var frame = new ImageFrame <TPixel>(configuration, magicFrame.Width, magicFrame.Height);
                framesList.Add(frame);

                MemoryGroup <TPixel> framePixels = frame.PixelBuffer.FastMemoryGroup;

                using IUnsafePixelCollection <ushort> pixels = magicFrame.GetPixelsUnsafe();
                if (magicFrame.Depth == 8 || magicFrame.Depth == 1)
                {
                    byte[] data = pixels.ToByteArray(PixelMapping.RGBA);

                    FromRgba32Bytes(configuration, data, framePixels);
                }
                else if (magicFrame.Depth == 16)
                {
                    ushort[]    data  = pixels.ToShortArray(PixelMapping.RGBA);
                    Span <byte> bytes = MemoryMarshal.Cast <ushort, byte>(data.AsSpan());
                    FromRgba64Bytes(configuration, bytes, framePixels);
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }

            return(new Image <TPixel>(configuration, new ImageMetadata(), framesList));
        }
Ejemplo n.º 4
0
        public Image <TPixel> Decode <TPixel>(Configuration configuration, Stream stream)
            where TPixel : unmanaged, ImageSharp.PixelFormats.IPixel <TPixel>
        {
            var bmpReadDefines = new BmpReadDefines
            {
                IgnoreFileSize = !this.validate
            };

            var settings = new MagickReadSettings();

            settings.SetDefines(bmpReadDefines);

            using var magickImage = new MagickImage(stream, settings);
            var result = new Image <TPixel>(configuration, magickImage.Width, magickImage.Height);
            MemoryGroup <TPixel> resultPixels = result.GetRootFramePixelBuffer().FastMemoryGroup;

            using (IUnsafePixelCollection <ushort> pixels = magickImage.GetPixelsUnsafe())
            {
                if (magickImage.Depth == 8)
                {
                    byte[] data = pixels.ToByteArray(PixelMapping.RGBA);

                    FromRgba32Bytes(configuration, data, resultPixels);
                }
                else if (magickImage.Depth == 16)
                {
                    ushort[]    data  = pixels.ToShortArray(PixelMapping.RGBA);
                    Span <byte> bytes = MemoryMarshal.Cast <ushort, byte>(data.AsSpan());
                    FromRgba64Bytes(configuration, bytes, resultPixels);
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }

            return(result);
        }