Ejemplo n.º 1
0
        /// <summary>
        /// Converts a 8x8 image area inside 'pixels' at position (x, y) to Rgb24.
        /// </summary>
        public void Convert(int x, int y, ref RowOctet <TPixel> currentRows)
        {
            YCbCrForwardConverter <TPixel> .LoadAndStretchEdges(currentRows, this.pixelSpan, new Point(x, y), SampleSize, this.samplingAreaSize);

            PixelOperations <TPixel> .Instance.ToRgb24(this.config, this.pixelSpan, this.rgbSpan);

            ref Block8x8F redBlock   = ref this.R;
        /// <summary>
        /// Converts a 8x8 image area inside 'pixels' at position (x,y) placing the result members of the structure (<see cref="Y"/>)
        /// </summary>
        public void Convert(ImageFrame <TPixel> frame, int x, int y, ref RowOctet <TPixel> currentRows)
        {
            this.pixelBlock.LoadAndStretchEdges(frame.PixelBuffer, x, y, ref currentRows);

            Span <L8> l8Span = this.l8Block.AsSpanUnsafe();

            PixelOperations <TPixel> .Instance.ToL8(frame.GetConfiguration(), this.pixelBlock.AsSpanUnsafe(), l8Span);

            ref Block8x8F yBlock  = ref this.Y;
Ejemplo n.º 3
0
        /// <summary>
        /// Encodes the image with no subsampling.
        /// </summary>
        /// <typeparam name="TPixel">The pixel format.</typeparam>
        /// <param name="pixels">The pixel accessor providing access to the image pixels.</param>
        /// <param name="cancellationToken">The token to monitor for cancellation.</param>
        private void Encode444 <TPixel>(Image <TPixel> pixels, CancellationToken cancellationToken)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            // TODO: Need a JpegScanEncoder<TPixel> class or struct that encapsulates the scan-encoding implementation. (Similar to JpegScanDecoder.)
            // (Partially done with YCbCrForwardConverter<TPixel>)
            Block8x8F temp1 = default;
            Block8x8F temp2 = default;

            Block8x8F onStackLuminanceQuantTable   = this.luminanceQuantTable;
            Block8x8F onStackChrominanceQuantTable = this.chrominanceQuantTable;

            var unzig = ZigZag.CreateUnzigTable();

            // ReSharper disable once InconsistentNaming
            int prevDCY = 0, prevDCCb = 0, prevDCCr = 0;

            var pixelConverter = YCbCrForwardConverter <TPixel> .Create();

            ImageFrame <TPixel> frame       = pixels.Frames.RootFrame;
            Buffer2D <TPixel>   pixelBuffer = frame.PixelBuffer;

            for (int y = 0; y < pixels.Height; y += 8)
            {
                cancellationToken.ThrowIfCancellationRequested();
                var currentRows = new RowOctet <TPixel>(pixelBuffer, y);

                for (int x = 0; x < pixels.Width; x += 8)
                {
                    pixelConverter.Convert(frame, x, y, currentRows);

                    prevDCY = this.WriteBlock(
                        QuantIndex.Luminance,
                        prevDCY,
                        ref pixelConverter.Y,
                        ref temp1,
                        ref temp2,
                        ref onStackLuminanceQuantTable,
                        ref unzig);
                    prevDCCb = this.WriteBlock(
                        QuantIndex.Chrominance,
                        prevDCCb,
                        ref pixelConverter.Cb,
                        ref temp1,
                        ref temp2,
                        ref onStackChrominanceQuantTable,
                        ref unzig);
                    prevDCCr = this.WriteBlock(
                        QuantIndex.Chrominance,
                        prevDCCr,
                        ref pixelConverter.Cr,
                        ref temp1,
                        ref temp2,
                        ref onStackChrominanceQuantTable,
                        ref unzig);
                }
            }
        }
Ejemplo n.º 4
0
        /// <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(Buffer2D <Pixel> pixelBuffer, int x, int y, ref RowOctet <Pixel> currentRows)
        {
            this.pixelBlock.LoadAndStretchEdges(pixelBuffer, x, y, ref currentRows);

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

            this.ToRgb24(this.pixelBlock.AsSpanUnsafe(), this.rgbBlock.AsSpanUnsafe());

            ref Block8x8F yBlock  = ref this.Y;
        public static void LoadAndStretchEdges(RowOctet <TPixel> source, Span <TPixel> dest, Point start, Size sampleSize, Size totalSize)
        {
            DebugGuard.MustBeBetweenOrEqualTo(start.X, 0, totalSize.Width - 1, nameof(start.X));
            DebugGuard.MustBeBetweenOrEqualTo(start.Y, 0, totalSize.Height - 1, nameof(start.Y));

            int width  = Math.Min(sampleSize.Width, totalSize.Width - start.X);
            int height = Math.Min(sampleSize.Height, totalSize.Height - start.Y);

            uint byteWidth       = (uint)(width * Unsafe.SizeOf <TPixel>());
            int  remainderXCount = sampleSize.Width - width;

            ref byte blockStart     = ref MemoryMarshal.GetReference(MemoryMarshal.Cast <TPixel, byte>(dest));
Ejemplo n.º 6
0
        public void Convert(int x, int y, ref RowOctet <TPixel> currentRows, int idx)
        {
            YCbCrForwardConverter <TPixel> .LoadAndStretchEdges(currentRows, this.pixelSpan, new Point(x, y), SampleSize, this.samplingAreaSize);

            PixelOperations <TPixel> .Instance.ToRgb24(this.config, this.pixelSpan, this.rgbSpan);

            if (RgbToYCbCrConverterVectorized.IsSupported)
            {
                RgbToYCbCrConverterVectorized.Convert420(this.rgbSpan, ref this.YLeft, ref this.YRight, ref this.Cb, ref this.Cr, idx);
            }
            else
            {
                this.colorTables.Convert420(this.rgbSpan, ref this.YLeft, ref this.YRight, ref this.Cb, ref this.Cr, idx);
            }
        }
Ejemplo n.º 7
0
        public void LoadAndStretchCorners_FromOrigo <TPixel>(TestImageProvider <TPixel> provider)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            using (Image <TPixel> s = provider.GetImage())
            {
                var d        = default(GenericBlock8x8 <TPixel>);
                var rowOctet = new RowOctet <TPixel>(s.GetRootFramePixelBuffer(), 0);
                d.LoadAndStretchEdges(s.Frames.RootFrame.PixelBuffer, 0, 0, rowOctet);

                TPixel a = s.Frames.RootFrame[0, 0];
                TPixel b = d[0, 0];

                Assert.Equal(s[0, 0], d[0, 0]);
                Assert.Equal(s[1, 0], d[1, 0]);
                Assert.Equal(s[7, 0], d[7, 0]);
                Assert.Equal(s[0, 1], d[0, 1]);
                Assert.Equal(s[1, 1], d[1, 1]);
                Assert.Equal(s[7, 0], d[7, 0]);
                Assert.Equal(s[0, 7], d[0, 7]);
                Assert.Equal(s[7, 7], d[7, 7]);
            }
        }
Ejemplo n.º 8
0
        public void LoadAndStretchCorners_WithOffset <TPixel>(TestImageProvider <TPixel> provider)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            using (Image <TPixel> s = provider.GetImage())
            {
                var d = default(GenericBlock8x8 <TPixel>);
                RowOctet <TPixel> rowOctet = default;
                rowOctet.Update(s.GetRootFramePixelBuffer(), 7);

                d.LoadAndStretchEdges(s.Frames.RootFrame.PixelBuffer, 6, 7, ref rowOctet);

                Assert.Equal(s[6, 7], d[0, 0]);
                Assert.Equal(s[6, 8], d[0, 1]);
                Assert.Equal(s[7, 8], d[1, 1]);

                Assert.Equal(s[6, 9], d[0, 2]);
                Assert.Equal(s[6, 9], d[0, 3]);
                Assert.Equal(s[6, 9], d[0, 7]);

                Assert.Equal(s[7, 9], d[1, 2]);
                Assert.Equal(s[7, 9], d[1, 3]);
                Assert.Equal(s[7, 9], d[1, 7]);

                Assert.Equal(s[9, 9], d[3, 2]);
                Assert.Equal(s[9, 9], d[3, 3]);
                Assert.Equal(s[9, 9], d[3, 7]);

                Assert.Equal(s[9, 7], d[3, 0]);
                Assert.Equal(s[9, 7], d[4, 0]);
                Assert.Equal(s[9, 7], d[7, 0]);

                Assert.Equal(s[9, 9], d[3, 2]);
                Assert.Equal(s[9, 9], d[4, 2]);
                Assert.Equal(s[9, 9], d[7, 2]);

                Assert.Equal(s[9, 9], d[4, 3]);
                Assert.Equal(s[9, 9], d[7, 7]);
            }
        }