public static ProcessImageResult ProcessImage(Stream imgStream, Stream outStream, ProcessImageSettings settings)
        {
            using var ctx      = new PipelineContext(settings);
            ctx.ImageContainer = WicImageContainer.Create(imgStream, ctx.WicContext);

            return(processImage(ctx, outStream));
        }
        public static ProcessImageResult ProcessImage(ReadOnlySpan <byte> imgBuffer, Stream outStream, ProcessImageSettings settings)
        {
            using var ctx      = new PipelineContext(settings);
            ctx.ImageContainer = WicImageContainer.Create(imgBuffer, ctx.WicContext);

            return(processImage(ctx, outStream));
        }
Esempio n. 3
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)
        {
            checkInStream(imgStream);

            var ctx = new PipelineContext(settings);

            ctx.ImageContainer = WicImageContainer.Create(imgStream, ctx.WicContext);

            buildPipeline(ctx, false);
            return(new ProcessingPipeline(ctx));
        }
Esempio n. 4
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)
        {
            checkInStream(imgStream);
            checkOutStream(outStream);

            using var ctx      = new PipelineContext(settings);
            ctx.ImageContainer = WicImageContainer.Create(imgStream, ctx.WicContext);

            buildPipeline(ctx);
            return(WriteOutput(ctx, outStream));
        }
Esempio n. 5
0
        public static WicImageContainer Load(Stream inStream)
        {
            var gch = GCHandle.Alloc(inStream);
            var sti = new IStreamImpl(gch);

            using var ccw = new SafeHandleReleaser(new SafeComCallable <IStreamImpl>(sti));

            var dec = createDecoder((IStream *)ccw.Handle !.DangerousGetHandle());

            return(WicImageContainer.Create(dec, ccw.Detach()));
        }
Esempio n. 6
0
        public static WicImageContainer Load(string fileName)
        {
            using var stm = default(ComPtr <IWICStream>);
            HRESULT.Check(Wic.Factory->CreateStream(stm.GetAddressOf()));

            fixed(char *pname = fileName)
            HRESULT.Check(stm.Get()->InitializeFromFilename((ushort *)pname, GENERIC_READ));

            var dec = createDecoder((IStream *)stm.Get());

            return(WicImageContainer.Create(dec));
        }
Esempio n. 7
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>
        public static ImageFileInfo Load(ReadOnlySpan <byte> imgBuffer, DateTime lastModified)
        {
            if (imgBuffer == default)
            {
                throw new ArgumentNullException(nameof(imgBuffer));
            }

            using var ctx      = new PipelineContext(new ProcessImageSettings());
            ctx.ImageContainer = WicImageContainer.Create(imgBuffer, ctx.WicContext);

            return(fromWicImage(ctx, imgBuffer.Length, lastModified));
        }
Esempio n. 8
0
        /// <inheritdoc cref="BuildPipeline(string, ProcessImageSettings)" />
        /// <param name="imgBuffer">A buffer containing a supported input image container.</param>
        public static ProcessingPipeline BuildPipeline(ReadOnlySpan <byte> imgBuffer, ProcessImageSettings settings)
        {
            if (imgBuffer == default)
            {
                throw new ArgumentNullException(nameof(imgBuffer));
            }

            var ctx = new PipelineContext(settings);

            ctx.ImageContainer = WicImageContainer.Create(imgBuffer, ctx.WicContext);

            buildPipeline(ctx, false);
            return(new ProcessingPipeline(ctx));
        }
Esempio n. 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));
            }

            var ctx = new PipelineContext(settings);

            ctx.ImageContainer = WicImageContainer.Create(imgPath, ctx.WicContext);

            buildPipeline(ctx, false);
            return(new ProcessingPipeline(ctx));
        }
Esempio n. 10
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 = WicImageContainer.Create(imgPath, ctx.WicContext);

            return(fromWicImage(ctx, fi.Length, fi.LastWriteTimeUtc));
        }
Esempio n. 11
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>
        public static ProcessImageResult ProcessImage(ReadOnlySpan <byte> imgBuffer, Stream outStream, ProcessImageSettings settings)
        {
            if (imgBuffer == default)
            {
                throw new ArgumentNullException(nameof(imgBuffer));
            }
            checkOutStream(outStream);

            using var ctx      = new PipelineContext(settings);
            ctx.ImageContainer = WicImageContainer.Create(imgBuffer, ctx.WicContext);

            buildPipeline(ctx);
            return(WriteOutput(ctx, outStream));
        }
Esempio n. 12
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));
            }
            checkOutStream(outStream);

            using var ctx      = new PipelineContext(settings);
            ctx.ImageContainer = WicImageContainer.Create(imgPath, ctx.WicContext);

            buildPipeline(ctx);
            return(WriteOutput(ctx, outStream));
        }
        /// <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 = WicImageContainer.Create(imgStream, ctx.WicContext);

            buildPipeline(ctx, false);
            return(new ProcessingPipeline(ctx));
        }
Esempio n. 14
0
        unsafe public static WicImageContainer Load(byte *pbBuffer, int cbBuffer, PipelineContext ctx, bool ownCopy = false)
        {
            var istm = ctx.WicContext.AddRef(Wic.Factory.CreateStream());
            var ptr  = (IntPtr)pbBuffer;

            if (ownCopy)
            {
                ptr = ctx.WicContext.AddUnmanagedMemory(cbBuffer).DangerousGetHandle();
                Buffer.MemoryCopy(pbBuffer, ptr.ToPointer(), cbBuffer, cbBuffer);
            }

            istm.InitializeFromMemory(ptr, (uint)cbBuffer);

            var dec = createDecoder(stm => Wic.Factory.CreateDecoderFromStream(stm, null, WICDecodeOptions.WICDecodeMetadataCacheOnDemand), istm);

            return(WicImageContainer.Create(dec, ctx));
        }
Esempio n. 15
0
        public static WicImageContainer Load(byte *pbBuffer, int cbBuffer, bool ownCopy = false)
        {
            using var stream = default(ComPtr <IWICStream>);
            HRESULT.Check(Wic.Factory->CreateStream(stream.GetAddressOf()));
            var ptr = (IntPtr)pbBuffer;

            using var mem = default(SafeHandleReleaser);
            if (ownCopy)
            {
                ptr = mem.Attach(new SafeHGlobalHandle(cbBuffer)).DangerousGetHandle();
                Buffer.MemoryCopy(pbBuffer, ptr.ToPointer(), cbBuffer, cbBuffer);
            }

            HRESULT.Check(stream.Get()->InitializeFromMemory((byte *)ptr, (uint)cbBuffer));

            var dec = createDecoder((IStream *)stream.Get());

            return(WicImageContainer.Create(dec, mem.Detach()));
        }
Esempio n. 16
0
        /// <summary>Constructs a new <see cref="ImageFileInfo" /> instance by reading the metadata from an image file exposed by a <see cref="Stream" />.</summary>
        /// <param name="imgStream">The stream containing the image data.</param>
        /// <param name="lastModified">The last modified date of the image container.</param>
        public static ImageFileInfo Load(Stream imgStream, DateTime lastModified)
        {
            if (imgStream is null)
            {
                throw new ArgumentNullException(nameof(imgStream));
            }
            if (!imgStream.CanSeek || !imgStream.CanRead)
            {
                throw new ArgumentException("Input Stream must allow Seek and Read", nameof(imgStream));
            }
            if (imgStream.Length <= 0 || imgStream.Position >= imgStream.Length)
            {
                throw new ArgumentException("Input Stream is empty or positioned at its end", nameof(imgStream));
            }

            using var ctx      = new PipelineContext(new ProcessImageSettings());
            ctx.ImageContainer = WicImageContainer.Create(imgStream, ctx.WicContext);

            return(fromWicImage(ctx, imgStream.Length, lastModified));
        }
Esempio n. 17
0
        public static WicImageContainer Load(Stream inStream, PipelineContext ctx)
        {
            var dec = createDecoder(stm => Wic.Factory.CreateDecoderFromStream(stm, null, WICDecodeOptions.WICDecodeMetadataCacheOnDemand), inStream.AsIStream());

            return(WicImageContainer.Create(dec, ctx));
        }
Esempio n. 18
0
        public static WicImageContainer Load(string fileName, PipelineContext ctx)
        {
            var dec = createDecoder(fn => Wic.Factory.CreateDecoderFromFilename(fn, null, GenericAccessRights.GENERIC_READ, WICDecodeOptions.WICDecodeMetadataCacheOnDemand), fileName);

            return(WicImageContainer.Create(dec, ctx));
        }