Esempio n. 1
0
        /// <inheritdoc/>
        public override void InjectFrameData(JpegFrame frame, IRawJpegData jpegData)
        {
            MemoryAllocator allocator = this.configuration.MemoryAllocator;

            // iteration data
            IJpegComponent c0 = frame.Components[0];

            const int blockPixelHeight = 8;

            this.blockRowsPerStep = c0.SamplingFactors.Height;
            this.pixelRowsPerStep = this.blockRowsPerStep * blockPixelHeight;

            // pixel buffer for resulting image
            this.pixelBuffer         = allocator.Allocate2D <TPixel>(frame.PixelWidth, frame.PixelHeight);
            this.paddedProxyPixelRow = allocator.Allocate <TPixel>(frame.PixelWidth + 3);

            // component processors from spectral to Rgba32
            var postProcessorBufferSize = new Size(c0.SizeInBlocks.Width * 8, this.pixelRowsPerStep);

            this.componentProcessors = new JpegComponentPostProcessor[frame.Components.Length];
            for (int i = 0; i < this.componentProcessors.Length; i++)
            {
                this.componentProcessors[i] = new JpegComponentPostProcessor(allocator, frame, jpegData, postProcessorBufferSize, frame.Components[i]);
            }

            // single 'stride' rgba32 buffer for conversion between spectral and TPixel
            // this.rgbaBuffer = allocator.Allocate<Vector4>(frame.PixelWidth);
            this.rgbBuffer = allocator.Allocate <byte>(frame.PixelWidth * 3);

            // color converter from Rgba32 to TPixel
            this.colorConverter = this.GetColorConverter(frame, jpegData);
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="JpegComponentPostProcessor"/> class.
        /// </summary>
        public JpegComponentPostProcessor(JpegImagePostProcessor imagePostProcessor, IJpegComponent component)
        {
            this.Component          = component;
            this.ImagePostProcessor = imagePostProcessor;
            this.ColorBuffer        = new Buffer2D <float>(imagePostProcessor.PostProcessorBufferSize);

            this.BlockRowsPerStep = JpegImagePostProcessor.BlockRowsPerStep / this.Component.SubSamplingDivisors.Height;
            this.blockAreaSize    = this.Component.SubSamplingDivisors * 8;
        }
Esempio n. 3
0
 internal static void VerifyComponent(
     IJpegComponent component,
     Size expectedSizeInBlocks,
     Size expectedSamplingFactors,
     Size expectedSubsamplingDivisors)
 {
     Assert.Equal(expectedSizeInBlocks, component.SizeInBlocks);
     Assert.Equal(expectedSamplingFactors, component.SamplingFactors);
     Assert.Equal(expectedSubsamplingDivisors, component.SubSamplingDivisors);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="JpegBlockPostProcessor"/> struct.
        /// </summary>
        /// <param name="decoder">The raw jpeg data.</param>
        /// <param name="component">The raw component.</param>
        public JpegBlockPostProcessor(IRawJpegData decoder, IJpegComponent component)
        {
            int qtIndex = component.QuantizationTableIndex;

            this.DequantiazationTable = decoder.QuantizationTables[qtIndex];
            this.subSamplingDivisors  = component.SubSamplingDivisors;

            this.SourceBlock    = default;
            this.WorkspaceBlock = default;
        }
Esempio n. 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="JpegBlockPostProcessor"/> struct.
        /// </summary>
        public JpegBlockPostProcessor(IRawJpegData decoder, IJpegComponent component)
        {
            int qtIndex = component.QuantizationTableIndex;

            this.DequantiazationTable = ZigZag.CreateDequantizationTable(ref decoder.QuantizationTables[qtIndex]);
            this.subSamplingDivisors  = component.SubSamplingDivisors;

            this.SourceBlock     = default(Block8x8F);
            this.WorkspaceBlock1 = default(Block8x8F);
            this.WorkspaceBlock2 = default(Block8x8F);
        }
Esempio n. 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="JpegBlockPostProcessor"/> struct.
        /// </summary>
        /// <param name="decoder">The raw jpeg data.</param>
        /// <param name="component">The raw component.</param>
        public JpegBlockPostProcessor(IRawJpegData decoder, IJpegComponent component)
        {
            int qtIndex = component.QuantizationTableIndex;

            this.DequantiazationTable = ZigZag.CreateDequantizationTable(ref decoder.QuantizationTables[qtIndex]);
            this.subSamplingDivisors  = component.SubSamplingDivisors;
            this.maximumValue         = (int)MathF.Pow(2, decoder.Precision) - 1;

            this.SourceBlock     = default;
            this.WorkspaceBlock1 = default;
            this.WorkspaceBlock2 = default;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="JpegImagePostProcessor"/> class.
        /// </summary>
        /// <param name="memoryManager">The <see cref="MemoryManager"/> to use for buffer allocations.</param>
        /// <param name="rawJpeg">The <see cref="IRawJpegData"/> representing the uncompressed spectral Jpeg data</param>
        public JpegImagePostProcessor(MemoryManager memoryManager, IRawJpegData rawJpeg)
        {
            this.RawJpeg = rawJpeg;
            IJpegComponent c0 = rawJpeg.Components.First();

            this.NumberOfPostProcessorSteps = c0.SizeInBlocks.Height / BlockRowsPerStep;
            this.PostProcessorBufferSize    = new Size(c0.SizeInBlocks.Width * 8, PixelRowsPerStep);

            this.ComponentProcessors = rawJpeg.Components.Select(c => new JpegComponentPostProcessor(memoryManager, this, c)).ToArray();
            this.rgbaBuffer          = memoryManager.Allocate <Vector4>(rawJpeg.ImageSizeInPixels.Width);
            this.colorConverter      = JpegColorConverter.GetConverter(rawJpeg.ColorSpace);
        }
Esempio n. 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="JpegComponentPostProcessor"/> class.
        /// </summary>
        public JpegComponentPostProcessor(MemoryAllocator memoryAllocator, JpegFrame frame, IRawJpegData rawJpeg, Size postProcessorBufferSize, IJpegComponent component)
        {
            this.frame = frame;

            this.component     = component;
            this.rawJpeg       = rawJpeg;
            this.blockAreaSize = this.component.SubSamplingDivisors * 8;
            this.ColorBuffer   = memoryAllocator.Allocate2DOveraligned <float>(
                postProcessorBufferSize.Width,
                postProcessorBufferSize.Height,
                this.blockAreaSize.Height);

            this.blockRowsPerStep = postProcessorBufferSize.Height / 8 / this.component.SubSamplingDivisors.Height;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="JpegImagePostProcessor"/> class.
        /// </summary>
        /// <param name="configuration">The <see cref="Configuration"/> to configure internal operations.</param>
        /// <param name="rawJpeg">The <see cref="IRawJpegData"/> representing the uncompressed spectral Jpeg data</param>
        public JpegImagePostProcessor(IRawJpegData rawJpeg)
        {
            this.RawJpeg = rawJpeg;
            IJpegComponent c0 = rawJpeg.Components[0];

            this.NumberOfPostProcessorSteps = c0.SizeInBlocks.Height / BlockRowsPerStep;
            this.PostProcessorBufferSize    = new Size(c0.SizeInBlocks.Width * 8, PixelRowsPerStep);

            this.ComponentProcessors = new JpegComponentPostProcessor[rawJpeg.Components.Length];
            for (int i = 0; i < rawJpeg.Components.Length; i++)
            {
                this.ComponentProcessors[i] = new JpegComponentPostProcessor(this, rawJpeg.Components[i]);
            }

            this.rgbaBuffer = MemoryGroup <Vector4> .Allocate(rawJpeg.ImageSizeInPixels.Width);

            this.colorConverter = JpegColorConverter.GetConverter(rawJpeg.ColorSpace, rawJpeg.Precision);
        }
Esempio n. 10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="JpegComponentPostProcessor"/> class.
        /// </summary>
        public JpegComponentPostProcessor(JpegImagePostProcessor imagePostProcessor, IJpegComponent component)
        {
            Buffer2D <float> Allocate2DOveraligned()
            {
                long groupLength = (long)imagePostProcessor.PostProcessorBufferSize.Width * imagePostProcessor.PostProcessorBufferSize.Height;
                MemoryGroup <float> memoryGroup = MemoryGroup <float> .Allocate(
                    groupLength,
                    imagePostProcessor.PostProcessorBufferSize.Width *this.blockAreaSize.Height);

                return(new Buffer2D <float>(memoryGroup, imagePostProcessor.PostProcessorBufferSize.Width, imagePostProcessor.PostProcessorBufferSize.Height));
            }

            this.Component          = component;
            this.ImagePostProcessor = imagePostProcessor;
            this.blockAreaSize      = this.Component.SubSamplingDivisors * 8;
            this.ColorBuffer        = Allocate2DOveraligned();

            this.BlockRowsPerStep = JpegImagePostProcessor.BlockRowsPerStep / this.Component.SubSamplingDivisors.Height;
        }
Esempio n. 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="JpegComponentPostProcessor"/> class.
        /// </summary>
        public JpegComponentPostProcessor(MemoryAllocator memoryAllocator, JpegImagePostProcessor imagePostProcessor, IJpegComponent component)
        {
            this.Component          = component;
            this.ImagePostProcessor = imagePostProcessor;
            this.ColorBuffer        = memoryAllocator.Allocate2D <float>(
                imagePostProcessor.PostProcessorBufferSize.Width,
                imagePostProcessor.PostProcessorBufferSize.Height);

            this.BlockRowsPerStep = JpegImagePostProcessor.BlockRowsPerStep / this.Component.SubSamplingDivisors.Height;
            this.blockAreaSize    = this.Component.SubSamplingDivisors * 8;
        }
Esempio n. 12
0
 internal static void VerifySize(IJpegComponent component, int expectedBlocksX, int expectedBlocksY)
 {
     Assert.Equal(new Size(expectedBlocksX, expectedBlocksY), component.SizeInBlocks);
 }
Esempio n. 13
0
 /// <summary>
 /// Gets a reference to the <see cref="Block8x8"/> at the given row and column index from <see cref="IJpegComponent.SpectralBlocks"/>
 /// </summary>
 public static ref Block8x8 GetBlockReference(this IJpegComponent component, int bx, int by)
 {
     return(ref component.SpectralBlocks[bx, by]);
 }