Beispiel #1
0
        public static void AssertRectangleInSource(
            IPixelSource source, Rectangle rectangle, string rectParamName)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            // Rectangle.Contains would suffice, but exception details would suffer
            AssertNonEmptyRectangle(rectangle, rectParamName);

            if (rectangle.Width > source.Width)
            {
                throw new ArgumentOutOfRangeException(rectParamName + ".Width");
            }
            if (rectangle.Height > source.Height)
            {
                throw new ArgumentOutOfRangeException(rectParamName + ".Height");
            }

            if (rectangle.X + rectangle.Width > source.Width)
            {
                throw new ArgumentOutOfRangeException(rectParamName + ".X");
            }
            if (rectangle.Y + rectangle.Height > source.Height)
            {
                throw new ArgumentOutOfRangeException(rectParamName + ".Y");
            }
        }
Beispiel #2
0
 public WicDecoder(IPixelSource imgSource, WicProcessingContext ctx)
 {
     init(null, ctx);
     ContainerFormat = FileFormat.Unknown;
     FrameCount      = 1;
     ctx.Source      = imgSource.AsPixelSource();
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="PixelAccessor{TPixel}"/> class.
        /// </summary>
        /// <param name="image">The image to provide pixel access for.</param>
        public PixelAccessor(IPixelSource <TPixel> image)
        {
            Guard.NotNull(image, nameof(image));
            Guard.MustBeGreaterThan(image.PixelBuffer.Width, 0, "image width");
            Guard.MustBeGreaterThan(image.PixelBuffer.Height, 0, "image height");

            this.SetPixelBufferUnsafe(image.PixelBuffer, false);
        }
Beispiel #4
0
 public PixelSourceFromIPixelSource(IPixelSource source) : base()
 {
     realSource = source;
     WicSource  = this.AsIWICBitmapSource();
     Format     = PixelFormat.Cache[source.Format];
     Width      = (uint)source.Width;
     Height     = (uint)source.Height;
 }
Beispiel #5
0
        /// <summary>
        /// Gets the width and height of the pixel source as a <see cref="Rectangle"/>.
        /// </summary>
        /// <returns>The buffer bounds at point (0, 0).</returns>
        public static Rectangle GetBounds(this IPixelSource source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            return(new Rectangle(Point.Zero, source.GetSize()));
        }
Beispiel #6
0
        /// <summary>
        /// Gets the width and height of the pixel source as a <see cref="Size"/>.
        /// </summary>
        public static Size GetSize(this IPixelSource source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            return(new Size(source.Width, source.Height));
        }
        /// <summary>
        /// Converts a 8x8 image area inside 'pixels' at position (x,y) placing the result members of the structure (<see cref="Y"/>, <see cref="Cb"/>, <see cref="Cr"/>)
        /// </summary>
        public void Convert(IPixelSource <TPixel> pixels, int x, int y)
        {
            this.pixelBlock.LoadAndStretchEdges(pixels, x, y);

            Span <Rgb24> rgbSpan = this.rgbBlock.AsSpanUnsafe();

            PixelOperations <TPixel> .Instance.ToRgb24(this.pixelBlock.AsSpanUnsafe(), rgbSpan, 64);

            ref float yBlockStart  = ref Unsafe.As <Block8x8F, float>(ref this.Y);
Beispiel #8
0
        public void Init(IPixelSource source)
        {
            if (source.Format != Consts.GUID_WICPixelFormat24bppBGR && source.Format != Consts.GUID_WICPixelFormat32bppBGRA)
            {
                throw new NotSupportedException("Pixel format must be BGR or BGRA");
            }

            this.source = source;
            channels    = PixelFormat.Cache[source.Format].ChannelCount;
        }
Beispiel #9
0
 /// <summary>
 /// Load a DICOM file
 /// </summary>
 /// <returns></returns>
 public async Task <bool> OpenDicomFileAsync()
 {
     _pixelSource = new DicomModel();
     if (await _pixelSource.OpenFileAsync()) // open
     {
         StorageSize = new Size(_pixelSource.Width, _pixelSource.Height);
         StorageFile = _pixelSource.File;
         return(true);
     }
     return(false);
 }
Beispiel #10
0
        /// <summary>Constructs a new processing pipeline from which pixels can be retrieved.</summary>
        /// <param name="imgSource">A custom pixel source to use as input.</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(IPixelSource imgSource, ProcessImageSettings settings)
        {
            if (imgSource is null)
            {
                throw new ArgumentNullException(nameof(imgSource));
            }

            var ctx = new WicProcessingContext(settings);
            var dec = new WicDecoder(imgSource, ctx);

            buildPipeline(ctx, false);
            return(new ProcessingPipeline(ctx));
        }
        public void Init(IPixelSource source)
        {
            if (source.Format != Consts.GUID_WICPixelFormat24bppBGR && source.Format != Consts.GUID_WICPixelFormat32bppBGRA && source.Format != Consts.GUID_WICPixelFormat32bppPBGRA &&
                source.Format != PixelFormat.Bgr48BppLinearUQ15.FormatGuid && source.Format != PixelFormat.Bgra64BppLinearUQ15.FormatGuid && source.Format != PixelFormat.Pbgra64BppLinearUQ15.FormatGuid &&
                source.Format != PixelFormat.Bgrx128BppFloat.FormatGuid && source.Format != PixelFormat.Bgrx128BppLinearFloat.FormatGuid &&
                source.Format != PixelFormat.Pbgra128BppFloat.FormatGuid && source.Format != PixelFormat.Bgra128BppLinearFloat.FormatGuid && source.Format != PixelFormat.Pbgra128BppLinearFloat.FormatGuid
                )
            {
                throw new NotSupportedException("Pixel format must be BGR or BGRA");
            }

            this.source = source;
            format      = PixelFormat.Cache[source.Format];
        }
Beispiel #12
0
        /// <summary>All-in-one processing of an image according to the specified <paramref name="settings" />.</summary>
        /// <param name="imgSource">A custom pixel source to use as input.</param>
        /// <param name="outStream">The stream to which the output image will be written.</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(IPixelSource imgSource, Stream outStream, ProcessImageSettings settings)
        {
            if (imgSource is null)
            {
                throw new ArgumentNullException(nameof(imgSource));
            }
            checkOutStream(outStream);

            using (var ctx = new WicProcessingContext(settings))
            {
                var dec = new WicDecoder(imgSource, ctx);
                buildPipeline(ctx);
                return(executePipeline(ctx, outStream));
            }
        }
        /// <inheritdoc cref="BuildPipeline(string, ProcessImageSettings)" />
        /// <param name="imgSource">A custom pixel source to use as input.</param>
        public static ProcessingPipeline BuildPipeline(IPixelSource imgSource, ProcessImageSettings settings)
        {
            if (imgSource is null)
            {
                throw new ArgumentNullException(nameof(imgSource));
            }

            var ctx = new PipelineContext(settings)
            {
                ImageContainer = new PixelSourceContainer(imgSource),
                Source         = imgSource.AsPixelSource()
            };

            buildPipeline(ctx, false);
            return(new ProcessingPipeline(ctx));
        }
        /// <inheritdoc cref="ProcessImage(string, Stream, ProcessImageSettings)" />
        /// <param name="imgSource">A custom pixel source to use as input.</param>
        public static ProcessImageResult ProcessImage(IPixelSource imgSource, Stream outStream, ProcessImageSettings settings)
        {
            if (imgSource is null)
            {
                throw new ArgumentNullException(nameof(imgSource));
            }
            checkOutStream(outStream);

            using var ctx = new PipelineContext(settings)
                  {
                      ImageContainer = new PixelSourceContainer(imgSource),
                      Source         = imgSource.AsPixelSource()
                  };

            buildPipeline(ctx);
            return(WriteOutput(ctx, outStream));
        }
 /// <summary>
 /// Returns a reference to the 0th element of the Pixel buffer.
 /// Such a reference can be used for pinning but must never be dereferenced.
 /// </summary>
 /// <param name="source">The source image frame</param>
 /// <returns>A reference to the element.</returns>
 private static ref TPixel DangerousGetPinnableReferenceToPixelBuffer <TPixel>(IPixelSource <TPixel> source)
     where TPixel : struct, IPixel <TPixel>
 => ref MemoryMarshal.GetReference(source.PixelBuffer.GetSpan());
 /// <summary>
 /// Gets the span to the backing buffer at the given row.
 /// </summary>
 /// <typeparam name="TPixel">The type of the pixel.</typeparam>
 /// <param name="source">The source.</param>
 /// <param name="row">The row.</param>
 /// <returns>
 /// The span returned from Pixel source
 /// </returns>
 private static Span <TPixel> GetSpan <TPixel>(IPixelSource <TPixel> source, int row)
     where TPixel : struct, IPixel <TPixel>
 => GetSpan(source.PixelBuffer, row);
 /// <summary>
 /// Gets the span to the backing buffer.
 /// </summary>
 /// <typeparam name="TPixel">The type of the pixel.</typeparam>
 /// <param name="source">The source.</param>
 /// <returns>The span returned from Pixel source</returns>
 private static Span <TPixel> GetSpan <TPixel>(IPixelSource <TPixel> source)
     where TPixel : struct, IPixel <TPixel>
 => source.PixelBuffer.GetSpan();
Beispiel #18
0
 /// <summary>
 /// Returns a reference to the 0th element of the Pixel buffer.
 /// Such a reference can be used for pinning but must never be dereferenced.
 /// </summary>
 /// <param name="source">The source image frame</param>
 /// <returns>A reference to the element.</returns>
 private static ref TPixel DangerousGetPinnableReferenceToPixelBuffer <TPixel>(IPixelSource <TPixel> source)
     where TPixel : struct, IPixel <TPixel>
 => ref source.PixelBuffer.Span.DangerousGetPinnableReference();
Beispiel #19
0
 public PixelSourceContainer(IPixelSource source) => frame = new PixelSourceFrame(source);
 /// <summary>
 /// Locks the image providing access to the pixels.
 /// <remarks>
 /// It is imperative that the accessor is correctly disposed off after use.
 /// </remarks>
 /// </summary>
 /// <typeparam name="TPixel">The type of the pixel.</typeparam>
 /// <param name="frame">The frame.</param>
 /// <returns>
 /// The <see cref="PixelAccessor{TPixel}" />
 /// </returns>
 internal static PixelAccessor <TPixel> Lock <TPixel>(this IPixelSource <TPixel> frame)
     where TPixel : struct, IPixel <TPixel>
 {
     return(new PixelAccessor <TPixel>(frame));
 }
 void IPixelTransform.Init(IPixelSource source) => throw new NotImplementedException();
Beispiel #22
0
 public PixelSourceContainer(IPixelSource source) => pixelSource = source;
Beispiel #23
0
 public PixelSourceFrame(IPixelSource source) => PixelSource = source;