Ejemplo n.º 1
0
        private void ParseBaselineDataInterleaved()
        {
            // Interleaved
            int mcu           = 0;
            int mcusPerColumn = this.frame.McusPerColumn;
            int mcusPerLine   = this.frame.McusPerLine;

            for (int j = 0; j < mcusPerColumn; j++)
            {
                for (int i = 0; i < mcusPerLine; i++)
                {
                    // Scan an interleaved mcu... process components in order
                    for (int k = 0; k < this.componentsLength; k++)
                    {
                        int           order     = this.frame.ComponentOrder[k];
                        JpegComponent component = this.components[order];

                        ref HuffmanTable dcHuffmanTable = ref this.dcHuffmanTables[component.DCHuffmanTableId];
                        ref HuffmanTable acHuffmanTable = ref this.acHuffmanTables[component.ACHuffmanTableId];
                        ref short        fastACRef      = ref this.fastACTables.GetAcTableReference(component);
                        int h = component.HorizontalSamplingFactor;
                        int v = component.VerticalSamplingFactor;

                        int mcuRow = mcu / mcusPerLine;

                        // Scan out an mcu's worth of this component; that's just determined
                        // by the basic H and V specified for the component
                        for (int y = 0; y < v; y++)
                        {
                            int             blockRow  = (mcuRow * v) + y;
                            Span <Block8x8> blockSpan = component.SpectralBlocks.GetRowSpan(blockRow);
                            for (int x = 0; x < h; x++)
                            {
                                if (this.eof)
                                {
                                    return;
                                }

                                int mcuCol   = mcu % mcusPerLine;
                                int blockCol = (mcuCol * h) + x;

                                this.DecodeBlockBaseline(
                                    component,
                                    ref blockSpan[blockCol],
                                    ref dcHuffmanTable,
                                    ref acHuffmanTable,
                                    ref fastACRef);
                            }
                        }
                    }
Ejemplo n.º 2
0
        private unsafe void ParseBaselineDataInterleaved()
        {
            // Interleaved
            int mcu           = 0;
            int mcusPerColumn = this.frame.McusPerColumn;
            int mcusPerLine   = this.frame.McusPerLine;

            // Pre-derive the huffman table to avoid in-loop checks.
            for (int i = 0; i < this.componentsLength; i++)
            {
                int           order     = this.frame.ComponentOrder[i];
                JpegComponent component = this.components[order];

                ref HuffmanTable dcHuffmanTable = ref this.dcHuffmanTables[component.DCHuffmanTableId];
                ref HuffmanTable acHuffmanTable = ref this.acHuffmanTables[component.ACHuffmanTableId];
Ejemplo n.º 3
0
        public unsafe int DecodeHuffman(ref HuffmanTable h)
        {
            this.CheckBits();
            int v      = this.PeekBits(JpegConstants.Huffman.LookupBits);
            int symbol = h.LookaheadValue[v];
            int size   = h.LookaheadSize[v];

            if (size == JpegConstants.Huffman.SlowBits)
            {
                ulong x = this.data << (JpegConstants.Huffman.RegisterSize - this.remainingBits);
                while (x > h.MaxCode[size])
                {
                    size++;
                }

                v      = (int)(x >> (JpegConstants.Huffman.RegisterSize - size));
                symbol = h.Values[(h.ValOffset[size] + v) & 0xFF];
            }

            this.remainingBits -= size;

            return(symbol);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Derives a lookup table for fast AC entropy scan decoding.
 /// This can happen multiple times during progressive decoding but always outside mcu loops.
 /// </summary>
 /// <param name="huffmanTable">The AC Huffman table.</param>
 public void Derive(ref HuffmanTable huffmanTable)
 {
     const int FastBits            = ScanDecoder.FastBits;
     ref short fastACRef           = ref this.Lookahead[0];