Пример #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 JpegHuffmanLosslessScanDecoder(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);
            }

            _restartInterval = decoder.GetRestartInterval();
            _mcusPerLine     = (frameHeader.SamplesPerLine + maxHorizontalSampling - 1) / maxHorizontalSampling;
            _mcusPerColumn   = (frameHeader.NumberOfLines + maxVerticalSampling - 1) / maxVerticalSampling;

            JpegBlockOutputWriter?outputWriter = decoder.GetOutputWriter();

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

            // Pre-allocate the JpegDecodeComponent instances
            _components = new JpegHuffmanDecodingComponent[frameHeader.NumberOfComponents];
            for (int i = 0; i < _components.Length; i++)
            {
                _components[i] = new JpegHuffmanDecodingComponent();
            }
        }