예제 #1
0
        public static ProcessImageResult ProcessImage(string imgPath, Stream outStream, ProcessImageSettings settings)
        {
            using var ctx      = new PipelineContext(settings);
            ctx.ImageContainer = WicImageDecoder.Load(imgPath, ctx);

            return(processImage(ctx, outStream));
        }
예제 #2
0
        public static ProcessImageResult ProcessImage(Stream imgStream, Stream outStream, ProcessImageSettings settings)
        {
            using var ctx      = new PipelineContext(settings);
            ctx.ImageContainer = ctx.AddDispose(WicImageDecoder.Load(imgStream));

            return(processImage(ctx, outStream));
        }
예제 #3
0
        public static unsafe ProcessImageResult ProcessImage(ReadOnlySpan <byte> imgBuffer, Stream outStream, ProcessImageSettings settings)
        {
            fixed(byte *pbBuffer = imgBuffer)
            {
                using var ctx      = new PipelineContext(settings);
                ctx.ImageContainer = ctx.AddDispose(WicImageDecoder.Load(pbBuffer, imgBuffer.Length));

                return(processImage(ctx, outStream));
            }
        }
예제 #4
0
        /// <summary>Constructs a new <see cref="ImageFileInfo" /> instance by reading the metadata from an image file header.</summary>
        /// <param name="imgPath">The path to the image file.</param>
        public static ImageFileInfo Load(string imgPath)
        {
            var fi = new FileInfo(imgPath);

            if (!fi.Exists)
            {
                throw new FileNotFoundException("File not found", imgPath);
            }

            using var ctx      = new PipelineContext(new ProcessImageSettings());
            ctx.ImageContainer = WicImageDecoder.Load(imgPath, ctx);

            return(fromWicImage(ctx, fi.Length, fi.LastWriteTimeUtc));
        }
예제 #5
0
        /// <summary>Constructs a new <see cref="ImageFileInfo" /> instance by reading the metadata from an image file contained in a <see cref="ReadOnlySpan{T}" />.</summary>
        /// <param name="imgBuffer">The buffer containing the image data.</param>
        /// <param name="lastModified">The last modified date of the image container.</param>
        unsafe public static ImageFileInfo Load(ReadOnlySpan <byte> imgBuffer, DateTime lastModified)
        {
            if (imgBuffer == default)
            {
                throw new ArgumentNullException(nameof(imgBuffer));

                fixed(byte *pbBuffer = imgBuffer)
                {
                    using var ctx      = new PipelineContext(new ProcessImageSettings());
                    ctx.ImageContainer = WicImageDecoder.Load(pbBuffer, imgBuffer.Length, ctx);

                    return(fromWicImage(ctx, imgBuffer.Length, lastModified));
                }
        }
예제 #6
0
        /// <inheritdoc cref="BuildPipeline(string, ProcessImageSettings)" />
        /// <param name="imgStream">A stream containing a supported input image container. The stream must allow Seek and Read.</param>
        public static ProcessingPipeline BuildPipeline(Stream imgStream, ProcessImageSettings settings)
        {
            if (settings is null)
            {
                throw new ArgumentNullException(nameof(settings));
            }
            checkInStream(imgStream);

            var ctx = new PipelineContext(settings);

            ctx.ImageContainer = WicImageDecoder.Load(imgStream, ctx);

            buildPipeline(ctx, false);
            return(new ProcessingPipeline(ctx));
        }
예제 #7
0
        /// <inheritdoc cref="ProcessImage(string, Stream, ProcessImageSettings)" />
        /// <param name="imgStream">A stream containing a supported input image container. The stream must allow Seek and Read.</param>
        public static ProcessImageResult ProcessImage(Stream imgStream, Stream outStream, ProcessImageSettings settings)
        {
            if (settings is null)
            {
                throw new ArgumentNullException(nameof(settings));
            }
            checkInStream(imgStream);
            checkOutStream(outStream);

            using var ctx      = new PipelineContext(settings);
            ctx.ImageContainer = WicImageDecoder.Load(imgStream, ctx);

            buildPipeline(ctx);
            return(WriteOutput(ctx, outStream));
        }
예제 #8
0
        /// <summary>Constructs a new <see cref="ImageFileInfo" /> instance by reading the metadata from an image file header.</summary>
        /// <param name="imgPath">The path to the image file.</param>
        public static ImageFileInfo Load(string imgPath)
        {
            var fi = new FileInfo(imgPath);

            if (!fi.Exists)
            {
                throw new FileNotFoundException("File not found", imgPath);
            }

            using var fs       = File.OpenRead(imgPath);
            using var stb      = new StreamBufferInjector(fs);
            using var ctx      = new PipelineContext(new ProcessImageSettings());
            ctx.ImageContainer = ctx.AddDispose(WicImageDecoder.Load(fs));

            return(fromWicImage(ctx, fi.Length, fi.LastWriteTimeUtc));
        }
예제 #9
0
        /// <summary>Constructs a new processing pipeline from which pixels can be retrieved.</summary>
        /// <param name="imgPath">The path to a file containing the input image.</param>
        /// <param name="settings">The settings for this processing operation.</param>
        /// <returns>A <see cref="ProcessingPipeline" /> containing the <see cref="IPixelSource" />, settings used, and basic instrumentation for the pipeline.</returns>
        public static ProcessingPipeline BuildPipeline(string imgPath, ProcessImageSettings settings)
        {
            if (imgPath is null)
            {
                throw new ArgumentNullException(nameof(imgPath));
            }
            if (settings is null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            var ctx = new PipelineContext(settings);

            ctx.ImageContainer = WicImageDecoder.Load(imgPath, ctx);

            buildPipeline(ctx, false);
            return(new ProcessingPipeline(ctx));
        }
예제 #10
0
        /// <inheritdoc cref="BuildPipeline(string, ProcessImageSettings)" />
        /// <param name="imgBuffer">A buffer containing a supported input image container.</param>
        unsafe public static ProcessingPipeline BuildPipeline(ReadOnlySpan <byte> imgBuffer, ProcessImageSettings settings)
        {
            if (imgBuffer == default)
            {
                throw new ArgumentNullException(nameof(imgBuffer));
            }
            if (settings is null)
            {
                throw new ArgumentNullException(nameof(settings));

                fixed(byte *pbBuffer = imgBuffer)
                {
                    var ctx = new PipelineContext(settings);

                    ctx.ImageContainer = WicImageDecoder.Load(pbBuffer, imgBuffer.Length, ctx, true);

                    buildPipeline(ctx, false);
                    return(new ProcessingPipeline(ctx));
                }
        }
예제 #11
0
        /// <summary>All-in-one processing of an image according to the specified <paramref name="settings" />.</summary>
        /// <param name="imgPath">The path to a file containing the input image.</param>
        /// <param name="outStream">The stream to which the output image will be written. The stream must allow Seek and Write.</param>
        /// <param name="settings">The settings for this processing operation.</param>
        /// <returns>A <see cref="ProcessImageResult" /> containing the settings used and basic instrumentation for the pipeline.</returns>
        public static ProcessImageResult ProcessImage(string imgPath, Stream outStream, ProcessImageSettings settings)
        {
            if (imgPath is null)
            {
                throw new ArgumentNullException(nameof(imgPath));
            }
            if (settings is null)
            {
                throw new ArgumentNullException(nameof(settings));
            }
            checkOutStream(outStream);

            using var fs       = File.OpenRead(imgPath);
            using var stb      = new StreamBufferInjector(fs);
            using var ctx      = new PipelineContext(settings);
            ctx.ImageContainer = ctx.AddDispose(WicImageDecoder.Load(fs));

            buildPipeline(ctx);
            return(WriteOutput(ctx, outStream));
        }
예제 #12
0
#pragma warning disable 1573 // not all params have docs

        /// <inheritdoc cref="ProcessImage(string, Stream, ProcessImageSettings)" />
        /// <param name="imgBuffer">A buffer containing a supported input image container.</param>
        unsafe public static ProcessImageResult ProcessImage(ReadOnlySpan <byte> imgBuffer, Stream outStream, ProcessImageSettings settings)
        {
            if (imgBuffer == default)
            {
                throw new ArgumentNullException(nameof(imgBuffer));
            }
            if (settings is null)
            {
                throw new ArgumentNullException(nameof(settings));
            }
            checkOutStream(outStream);

            fixed(byte *pbBuffer = imgBuffer)
            {
                using var ctx      = new PipelineContext(settings);
                ctx.ImageContainer = WicImageDecoder.Load(pbBuffer, imgBuffer.Length, ctx);

                buildPipeline(ctx);
                return(WriteOutput(ctx, outStream));
            }
        }
예제 #13
0
        /// <summary>Constructs a new processing pipeline from which pixels can be retrieved.</summary>
        /// <param name="imgPath">The path to a file containing the input image.</param>
        /// <param name="settings">The settings for this processing operation.</param>
        /// <returns>A <see cref="ProcessingPipeline" /> containing the <see cref="IPixelSource" />, settings used, and basic instrumentation for the pipeline.</returns>
        public static ProcessingPipeline BuildPipeline(string imgPath, ProcessImageSettings settings)
        {
            if (imgPath is null)
            {
                throw new ArgumentNullException(nameof(imgPath));
            }
            if (settings is null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            var ctx = new PipelineContext(settings);

            var fs = ctx.AddDispose(File.OpenRead(imgPath));

            ctx.AddDispose(new StreamBufferInjector(fs));
            ctx.ImageContainer = ctx.AddDispose(WicImageDecoder.Load(fs));

            buildPipeline(ctx, false);
            return(new ProcessingPipeline(ctx));
        }