Example #1
0
        public JpegArithmeticSequentialScanDecoder(JpegDecoder decoder, JpegFrameHeader frameHeader) : base(decoder)
        {
            _frameHeader = frameHeader;

            // Compute maximum sampling factor
            int maxHorizontalSampling = 1;
            int maxVerticalSampling   = 1;

            foreach (JpegFrameComponentSpecificationParameters currentFrameComponent in frameHeader.Components !)
            {
                maxHorizontalSampling = Math.Max(maxHorizontalSampling, currentFrameComponent.HorizontalSamplingFactor);
                maxVerticalSampling   = Math.Max(maxVerticalSampling, currentFrameComponent.VerticalSamplingFactor);
            }
            _maxHorizontalSampling = maxHorizontalSampling;
            _maxVerticalSampling   = maxVerticalSampling;

            _restartInterval = decoder.GetRestartInterval();
            _mcusPerLine     = (frameHeader.SamplesPerLine + 8 * maxHorizontalSampling - 1) / (8 * maxHorizontalSampling);
            _mcusPerColumn   = (frameHeader.NumberOfLines + 8 * maxVerticalSampling - 1) / (8 * maxVerticalSampling);
            _levelShift      = 1 << (frameHeader.SamplePrecision - 1);

            // Pre-allocate the JpegDecodeComponent instances
            _components = new JpegArithmeticDecodingComponent[frameHeader.NumberOfComponents];
            for (int i = 0; i < _components.Length; i++)
            {
                _components[i] = new JpegArithmeticDecodingComponent();
            }
        }
        public JpegArithmeticProgressiveScanDecoder(JpegDecoder decoder, JpegFrameHeader frameHeader) : base(decoder)
        {
            _frameHeader = frameHeader;

            // Compute maximum sampling factor
            int maxHorizontalSampling = 1;
            int maxVerticalSampling   = 1;

            foreach (JpegFrameComponentSpecificationParameters currentFrameComponent in frameHeader.Components !)
            {
                maxHorizontalSampling = Math.Max(maxHorizontalSampling, currentFrameComponent.HorizontalSamplingFactor);
                maxVerticalSampling   = Math.Max(maxVerticalSampling, currentFrameComponent.VerticalSamplingFactor);
            }

            _mcusPerLine   = (frameHeader.SamplesPerLine + 8 * maxHorizontalSampling - 1) / (8 * maxHorizontalSampling);
            _mcusPerColumn = (frameHeader.NumberOfLines + 8 * maxVerticalSampling - 1) / (8 * maxVerticalSampling);
            _levelShift    = 1 << (frameHeader.SamplePrecision - 1);

            JpegBlockOutputWriter?outputWriter = decoder.GetOutputWriter();

            if (outputWriter is null)
            {
                ThrowInvalidDataException("Output writer is not set.");
            }
            _outputWriter = outputWriter;
            _allocator    = new JpegBlockAllocator(decoder.MemoryPool);
            _allocator.Allocate(frameHeader);

            // Pre-allocate the JpegDecodeComponent instances
            _components = new JpegArithmeticDecodingComponent[frameHeader.NumberOfComponents];
            for (int i = 0; i < _components.Length; i++)
            {
                _components[i] = new JpegArithmeticDecodingComponent();
            }
        }
Example #3
0
 private void ReadBlock(ref JpegBitReader reader, JpegArithmeticDecodingComponent component, ref JpegBlock8x8 destinationBlock)
 {
     ref short destinationRef = ref Unsafe.As <JpegBlock8x8, short>(ref destinationBlock);