コード例 #1
0
        /// <summary>Figure F.16 - Reads the huffman code bit-by-bit.</summary>
        public int Decode(JPEGBinaryReader JPEGStream)
        {
            int   i    = 0;
            short code = (short)JPEGStream.ReadBits(1);

            while (code > maxcode[i])
            {
                i++;
                code <<= 1;
                code  |= (short)JPEGStream.ReadBits(1);
            }
            int val = huffval[code + (valptr[i])];

            if (val < 0)
            {
                val = 256 + val;
            }
            return(val);
        }
コード例 #2
0
        public void DecodeACFirst(JPEGBinaryReader stream, float[] zz)
        {
            if (stream.eob_run > 0)
            {
                stream.eob_run--;
                return;
            }

            for (int k = spectralStart; k <= spectralEnd; k++)
            {
                int s = ACTable.Decode(stream);
                int r = s >> 4;
                s &= 15;


                if (s != 0)
                {
                    k += r;

                    r     = (int)stream.ReadBits(s);
                    s     = (int)HuffmanTable.Extend(r, s);
                    zz[k] = s << successiveLow;
                }
                else
                {
                    if (r != 15)
                    {
                        stream.eob_run = 1 << r;

                        if (r != 0)
                        {
                            stream.eob_run += stream.ReadBits(r);
                        }

                        stream.eob_run--;

                        break;
                    }

                    k += 15;
                }
            }
        }
コード例 #3
0
        public void DecodeACFirst(JPEGBinaryReader stream, float[] zz)
        {
            if (stream.eob_run > 0)
            {
                stream.eob_run--;
                return;
            }
            int num = spectralStart;
            int num3;

            while (true)
            {
                if (num > spectralEnd)
                {
                    return;
                }
                int num2 = ACTable.Decode(stream);
                num3  = num2 >> 4;
                num2 &= 0xF;
                if (num2 != 0)
                {
                    num    += num3;
                    num3    = stream.ReadBits(num2);
                    num2    = HuffmanTable.Extend(num3, num2);
                    zz[num] = num2 << successiveLow;
                }
                else
                {
                    if (num3 != 15)
                    {
                        break;
                    }
                    num += 15;
                }
                num++;
            }
            stream.eob_run = 1 << num3;
            if (num3 != 0)
            {
                stream.eob_run += stream.ReadBits(num3);
            }
            stream.eob_run--;
        }
コード例 #4
0
ファイル: HuffmanTable.cs プロジェクト: jjg0519/OA
        public int Decode(JPEGBinaryReader JPEGStream)
        {
            int   index = 0;
            short num2  = (short)JPEGStream.ReadBits(1);

            while (num2 > this.maxcode[index])
            {
                index++;
                num2 = (short)(num2 << 1);
                num2 = (short)(num2 | ((short)JPEGStream.ReadBits(1)));
            }
            int num3 = this.huffval[num2 + this.valptr[index]];

            if (num3 < 0)
            {
                num3 = 0x100 + num3;
            }
            return(num3);
        }
コード例 #5
0
ファイル: JpegComponent.cs プロジェクト: jjg0519/OA
 internal void decode_ac_coefficients(JPEGBinaryReader JPEGStream, float[] zz)
 {
     for (int i = 1; i < 0x40; i++)
     {
         int t    = this.ACTable.Decode(JPEGStream);
         int num3 = t >> 4;
         t &= 15;
         if (t != 0)
         {
             i    += num3;
             zz[i] = HuffmanTable.Extend(JPEGStream.ReadBits(t), t);
         }
         else
         {
             if (num3 != 15)
             {
                 break;
             }
             i += 15;
         }
     }
 }
コード例 #6
0
ファイル: JpegComponent.cs プロジェクト: jjg0519/OA
 public void DecodeACFirst(JPEGBinaryReader stream, float[] zz)
 {
     if (stream.eob_run > 0)
     {
         stream.eob_run--;
     }
     else
     {
         for (int i = this.spectralStart; i <= this.spectralEnd; i++)
         {
             int t = this.ACTable.Decode(stream);
             int n = t >> 4;
             t &= 15;
             if (t != 0)
             {
                 i    += n;
                 t     = HuffmanTable.Extend(stream.ReadBits(t), t);
                 zz[i] = t << this.successiveLow;
             }
             else
             {
                 if (n != 15)
                 {
                     stream.eob_run = ((int)1) << n;
                     if (n != 0)
                     {
                         stream.eob_run += stream.ReadBits(n);
                     }
                     stream.eob_run--;
                     break;
                 }
                 i += 15;
             }
         }
     }
 }
コード例 #7
0
        public void DecodeACRefine(JPEGBinaryReader stream, float[] dest)
        {
            int num  = 1 << successiveLow;
            int num2 = -1 << successiveLow;
            int i    = spectralStart;

            if (stream.eob_run == 0)
            {
                for (; i <= spectralEnd; i++)
                {
                    int num3 = ACTable.Decode(stream);
                    int num4 = num3 >> 4;
                    num3 &= 0xF;
                    if (num3 != 0)
                    {
                        if (num3 != 1)
                        {
                            throw new Exception("Decode Error");
                        }
                        num3 = ((stream.ReadBits(1) != 1) ? num2 : num);
                    }
                    else if (num4 != 15)
                    {
                        stream.eob_run = 1 << num4;
                        if (num4 > 0)
                        {
                            stream.eob_run += stream.ReadBits(num4);
                        }
                        break;
                    }
                    do
                    {
                        if (dest[i] != 0f)
                        {
                            if (stream.ReadBits(1) == 1 && ((int)dest[i] & num) == 0)
                            {
                                if (dest[i] >= 0f)
                                {
                                    dest[i] += num;
                                }
                                else
                                {
                                    dest[i] += num2;
                                }
                            }
                        }
                        else if (--num4 < 0)
                        {
                            break;
                        }
                        i++;
                    }while (i <= spectralEnd);
                    if (num3 != 0 && i < 64)
                    {
                        dest[i] = num3;
                    }
                }
            }
            if (stream.eob_run <= 0)
            {
                return;
            }
            for (; i <= spectralEnd; i++)
            {
                if (dest[i] != 0f && stream.ReadBits(1) == 1 && ((int)dest[i] & num) == 0)
                {
                    if (dest[i] >= 0f)
                    {
                        dest[i] += num;
                    }
                    else
                    {
                        dest[i] += num2;
                    }
                }
            }
            stream.eob_run--;
        }
コード例 #8
0
ファイル: JpegFrame.cs プロジェクト: bufang-master/Adventure
        private void DecodeScan(byte numberOfComponents, byte[] componentSelector, int resetInterval, JPEGBinaryReader jpegReader, ref byte marker)
        {
            //TODO: not necessary
            jpegReader.eob_run = 0;

            int mcuIndex      = 0;
            int mcuTotalIndex = 0;

            // This loops through until a MarkerTagFound exception is
            // found, if the marker tag is a RST (Restart Marker) it
            // simply skips it and moves on this system does not handle
            // corrupt data streams very well, it could be improved by
            // handling misplaced restart markers.

            int h = 0, v = 0;
            int x = 0;

            long lastPosition = jpegReader.BaseStream.Position;

            //TODO: replace this with a loop which knows how much data to expect
            while (true)
            {
                #region Inform caller of decode progress

                if (ProgressUpdateMethod != null)
                {
                    if (jpegReader.BaseStream.Position >= lastPosition + JpegDecoder.ProgressUpdateByteInterval)
                    {
                        lastPosition = jpegReader.BaseStream.Position;
                        ProgressUpdateMethod(lastPosition);
                    }
                }

                #endregion

                try
                {
                    // Loop though capturing MCU, instruct each
                    // component to read in its necessary count, for
                    // scaling factors the components automatically
                    // read in how much they need

                    // Sec A.2.2 from CCITT Rec. T.81 (1992 E)
                    bool interleaved = !(numberOfComponents == 1);

                    if (!interleaved)
                    {
                        JpegComponent comp = Scan.GetComponentById(componentSelector[0]);

                        comp.SetBlock(mcuIndex);

                        comp.DecodeMCU(jpegReader, h, v);

                        int mcus_per_line   = mcus_per_row(comp);
                        int blocks_per_line = (int)Math.Ceiling((double)this.Width / (8 * comp.factorH));


                        // TODO: Explain the non-interleaved scan ------

                        h++; x++;

                        if (h == comp.factorH)
                        {
                            h = 0; mcuIndex++;
                        }

                        if ((x % mcus_per_line) == 0)
                        {
                            x = 0;
                            v++;

                            if (v == comp.factorV)
                            {
                                if (h != 0)
                                {
                                    mcuIndex++; h = 0;
                                }
                                v = 0;
                            }
                            else
                            {
                                mcuIndex -= blocks_per_line;

                                // we were mid-block
                                if (h != 0)
                                {
                                    mcuIndex++; h = 0;
                                }
                            }
                        }

                        // -----------------------------------------------
                    }
                    else // Components are interleaved
                    {
                        for (int compIndex = 0; compIndex < numberOfComponents; compIndex++)
                        {
                            JpegComponent comp = Scan.GetComponentById(componentSelector[compIndex]);
                            comp.SetBlock(mcuTotalIndex);

                            for (int j = 0; j < comp.factorV; j++)
                            {
                                for (int i = 0; i < comp.factorH; i++)
                                {
                                    comp.DecodeMCU(jpegReader, i, j);
                                }
                            }
                        }

                        mcuIndex++;
                        mcuTotalIndex++;
                    }
                }
                // We've found a marker, see if the marker is a restart
                // marker or just the next marker in the stream. If
                // it's the next marker in the stream break out of the
                // while loop, if it's just a restart marker skip it
                catch (JPEGMarkerFoundException ex)
                {
                    marker = ex.Marker;

                    // Handle JPEG Restart Markers, this is where the
                    // count of MCU's per interval is compared with
                    // the count actually obtained, if it's short then
                    // pad on some MCU's ONLY for components that are
                    // greater than one. Also restart the DC prediction
                    // to zero.
                    if (marker == JPEGMarker.RST0 ||
                        marker == JPEGMarker.RST1 ||
                        marker == JPEGMarker.RST2 ||
                        marker == JPEGMarker.RST3 ||
                        marker == JPEGMarker.RST4 ||
                        marker == JPEGMarker.RST5 ||
                        marker == JPEGMarker.RST6 ||
                        marker == JPEGMarker.RST7)
                    {
                        for (int compIndex = 0; compIndex < numberOfComponents; compIndex++)
                        {
                            JpegComponent comp = Scan.GetComponentById(componentSelector[compIndex]);
                            if (compIndex > 1)
                            {
                                comp.padMCU(mcuTotalIndex, resetInterval - mcuIndex);
                            }
                            comp.resetInterval();
                        }

                        mcuTotalIndex += (resetInterval - mcuIndex);
                        mcuIndex       = 0;
                    }
                    else
                    {
                        break; // We're at the end of our scan, exit out.
                    }
                }
            }
        }
コード例 #9
0
ファイル: JpegFrame.cs プロジェクト: bufang-master/Adventure
        public void DecodeScanBaseline(byte numberOfComponents, byte[] componentSelector, int resetInterval, JPEGBinaryReader jpegReader, ref byte marker)
        {
            // Set the decode function for all the components
            for (int compIndex = 0; compIndex < numberOfComponents; compIndex++)
            {
                JpegComponent comp = Scan.GetComponentById(componentSelector[compIndex]);
                comp.Decode = comp.DecodeBaseline;
            }

            DecodeScan(numberOfComponents, componentSelector, resetInterval, jpegReader, ref marker);
        }
コード例 #10
0
        public void DecodeScan(byte numberOfComponents, byte[] componentSelector, int resetInterval, JPEGBinaryReader jpegReader, ref byte marker)
        {
            jpegReader.eob_run = 0;
            int  num      = 0;
            int  num2     = 0;
            int  num3     = 0;
            int  num4     = 0;
            int  num5     = 0;
            long position = jpegReader.BaseStream.Position;

            while (true)
            {
                if (ProgressUpdateMethod != null && jpegReader.BaseStream.Position >= position + JpegDecoder.ProgressUpdateByteInterval)
                {
                    position = jpegReader.BaseStream.Position;
                    ProgressUpdateMethod(position);
                }
                try
                {
                    if (numberOfComponents == 1)
                    {
                        JpegComponent componentById = Scan.GetComponentById(componentSelector[0]);
                        componentById.SetBlock(num);
                        componentById.DecodeMCU(jpegReader, num3, num4);
                        int num6 = mcus_per_row(componentById);
                        int num7 = (int)Math.Ceiling((double)(int)Width / (double)(8 * componentById.factorH));
                        num3++;
                        num5++;
                        if (num3 == componentById.factorH)
                        {
                            num3 = 0;
                            num++;
                        }
                        if (num5 % num6 == 0)
                        {
                            num5 = 0;
                            num4++;
                            if (num4 == componentById.factorV)
                            {
                                if (num3 != 0)
                                {
                                    num++;
                                    num3 = 0;
                                }
                                num4 = 0;
                            }
                            else
                            {
                                num -= num7;
                                if (num3 != 0)
                                {
                                    num++;
                                    num3 = 0;
                                }
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < numberOfComponents; i++)
                        {
                            JpegComponent componentById2 = Scan.GetComponentById(componentSelector[i]);
                            componentById2.SetBlock(num2);
                            for (int j = 0; j < componentById2.factorV; j++)
                            {
                                for (int k = 0; k < componentById2.factorH; k++)
                                {
                                    componentById2.DecodeMCU(jpegReader, k, j);
                                }
                            }
                        }
                        num++;
                        num2++;
                    }
                }
                catch (JPEGMarkerFoundException ex)
                {
                    marker = ex.Marker;
                    if (marker != 208 && marker != 209 && marker != 210 && marker != 211 && marker != 212 && marker != 213 && marker != 214 && marker != 215)
                    {
                        return;
                    }
                    for (int l = 0; l < numberOfComponents; l++)
                    {
                        JpegComponent componentById3 = Scan.GetComponentById(componentSelector[l]);
                        if (l > 1)
                        {
                            componentById3.padMCU(num2, resetInterval - num);
                        }
                        componentById3.resetInterval();
                    }
                    num2 += resetInterval - num;
                    num   = 0;
                }
            }
        }
コード例 #11
0
ファイル: JPEGFrame.cs プロジェクト: jjg0519/OA
        //private void DecodeScan(byte numberOfComponents, byte[] componentSelector, int resetInterval, JPEGBinaryReader jpegReader, ref byte marker)
        //{
        //    jpegReader.eob_run = 0;
        //    int idx = 0;
        //    int num2 = 0;
        //    int i = 0;
        //    int j = 0;
        //    int num5 = 0;
        //    long position = jpegReader.BaseStream.Position;
        //    while (true)
        //    {
        //        JpegComponent componentById;
        //        int num9;
        //        if ((this.ProgressUpdateMethod != null) && (jpegReader.BaseStream.Position >= (position + JpegDecoder.ProgressUpdateByteInterval)))
        //        {
        //            position = jpegReader.BaseStream.Position;
        //            this.ProgressUpdateMethod(position);
        //        }
        //        try
        //        {
        //            if (numberOfComponents == 1)
        //            {
        //                componentById = this.Scan.GetComponentById(componentSelector[0]);
        //                componentById.SetBlock(idx);
        //                componentById.DecodeMCU(jpegReader, i, j);
        //                int num7 = this.mcus_per_row(componentById);
        //                int num8 = (int) Math.Ceiling(((double) this.Width) / ((double) (8 * componentById.factorH)));
        //                i++;
        //                num5++;
        //                if (i == componentById.factorH)
        //                {
        //                    i = 0;
        //                    idx++;
        //                }
        //                if ((num5 % num7) == 0)
        //                {
        //                    num5 = 0;
        //                    j++;
        //                    if (j == componentById.factorV)
        //                    {
        //                        if (i != 0)
        //                        {
        //                            idx++;
        //                            i = 0;
        //                        }
        //                        j = 0;
        //                    }
        //                    else
        //                    {
        //                        idx -= num8;
        //                        if (i != 0)
        //                        {
        //                            idx++;
        //                            i = 0;
        //                        }
        //                    }
        //                }
        //            }
        //            else
        //            {
        //                num9 = 0;
        //                while (num9 < numberOfComponents)
        //                {
        //                    componentById = this.Scan.GetComponentById(componentSelector[num9]);
        //                    componentById.SetBlock(num2);
        //                    for (int k = 0; k < componentById.factorV; k++)
        //                    {
        //                        for (int m = 0; m < componentById.factorH; m++)
        //                        {
        //                            componentById.DecodeMCU(jpegReader, m, k);
        //                        }
        //                    }
        //                    num9++;
        //                }
        //                idx++;
        //                num2++;
        //            }
        //        }
        //        catch (JPEGMarkerFoundException exception)
        //        {
        //            marker = exception.Marker;
        //            if (((((marker != 0xd0) && (marker != 0xd1)) && ((marker != 210) && (marker != 0xd3))) && (((marker != 0xd4) && (marker != 0xd5)) && (marker != 0xd6))) && (marker != 0xd7))
        //            {
        //                return;
        //            }
        //            for (num9 = 0; num9 < numberOfComponents; num9++)
        //            {
        //                componentById = this.Scan.GetComponentById(componentSelector[num9]);
        //                if (num9 > 1)
        //                {
        //                    componentById.padMCU(num2, resetInterval - idx);
        //                }
        //                componentById.resetInterval();
        //            }
        //            num2 += resetInterval - idx;
        //            idx = 0;
        //        }
        //    }
        //}

        //public void DecodeScanBaseline(byte numberOfComponents, byte[] componentSelector, int resetInterval, JPEGBinaryReader jpegReader, ref byte marker)
        //{
        //    for (int i = 0; i < numberOfComponents; i++)
        //    {
        //        JpegComponent componentById = this.Scan.GetComponentById(componentSelector[i]);
        //        componentById.Decode = new JpegComponent.DecodeFunction(componentById.DecodeBaseline);
        //    }
        //    this.DecodeScan(numberOfComponents, componentSelector, resetInterval, jpegReader, ref marker);
        //}

        public void DecodeScanProgressive(byte successiveApproximation, byte startSpectralSelection, byte endSpectralSelection, byte numberOfComponents, byte[] componentSelector, int resetInterval, JPEGBinaryReader jpegReader, ref byte marker)
        {
            byte num  = (byte)(successiveApproximation >> 4);
            byte num2 = (byte)(successiveApproximation & 15);

            if ((startSpectralSelection > endSpectralSelection) || (endSpectralSelection > 0x3f))
            {
                throw new Exception("Bad spectral selection.");
            }
            bool flag  = startSpectralSelection == 0;
            bool flag2 = num != 0;

            if (flag)
            {
                if (endSpectralSelection != 0)
                {
                    throw new Exception("Bad spectral selection for DC only scan.");
                }
            }
            else if (numberOfComponents > 1)
            {
                throw new Exception("Too many components for AC scan!");
            }
            for (int i = 0; i < numberOfComponents; i++)
            {
                JpegComponent componentById = this.Scan.GetComponentById(componentSelector[i]);
                componentById.successiveLow = num2;
                if (flag)
                {
                    if (flag2)
                    {
                        componentById.Decode = new JpegComponent.DecodeFunction(componentById.DecodeDCRefine);
                    }
                    else
                    {
                        componentById.Decode = new JpegComponent.DecodeFunction(componentById.DecodeDCFirst);
                    }
                }
                else
                {
                    componentById.spectralStart = startSpectralSelection;
                    componentById.spectralEnd   = endSpectralSelection;
                    if (flag2)
                    {
                        componentById.Decode = new JpegComponent.DecodeFunction(componentById.DecodeACRefine);
                    }
                    else
                    {
                        componentById.Decode = new JpegComponent.DecodeFunction(componentById.DecodeACFirst);
                    }
                }
            }
            //   this.DecodeScan(numberOfComponents, componentSelector, resetInterval, jpegReader, ref marker);
        }
コード例 #12
0
ファイル: JpegComponent.cs プロジェクト: jjg0519/OA
        public void DecodeACRefine(JPEGBinaryReader stream, float[] dest)
        {
            int num           = ((int)1) << this.successiveLow;
            int num2          = ((int)(-1)) << this.successiveLow;
            int spectralStart = this.spectralStart;

            if (stream.eob_run == 0)
            {
                while (spectralStart <= this.spectralEnd)
                {
                    int num4 = this.ACTable.Decode(stream);
                    int n    = num4 >> 4;
                    num4 &= 15;
                    if (num4 != 0)
                    {
                        if (num4 != 1)
                        {
                            throw new Exception("Decode Error");
                        }
                        if (stream.ReadBits(1) == 1)
                        {
                            num4 = num;
                        }
                        else
                        {
                            num4 = num2;
                        }
                    }
                    else if (n != 15)
                    {
                        stream.eob_run = ((int)1) << n;
                        if (n > 0)
                        {
                            stream.eob_run += stream.ReadBits(n);
                        }
                        break;
                    }
                    do
                    {
                        if (dest[spectralStart] != 0f)
                        {
                            if ((stream.ReadBits(1) == 1) && ((((int)dest[spectralStart]) & num) == 0))
                            {
                                if (dest[spectralStart] >= 0f)
                                {
                                    dest[spectralStart] += num;
                                }
                                else
                                {
                                    dest[spectralStart] += num2;
                                }
                            }
                        }
                        else if (--n < 0)
                        {
                            break;
                        }
                        spectralStart++;
                    }while (spectralStart <= this.spectralEnd);
                    if ((num4 != 0) && (spectralStart < 0x40))
                    {
                        dest[spectralStart] = num4;
                    }
                    spectralStart++;
                }
            }
            if (stream.eob_run > 0)
            {
                while (spectralStart <= this.spectralEnd)
                {
                    if (((dest[spectralStart] != 0f) && (stream.ReadBits(1) == 1)) && ((((int)dest[spectralStart]) & num) == 0))
                    {
                        if (dest[spectralStart] >= 0f)
                        {
                            dest[spectralStart] += num;
                        }
                        else
                        {
                            dest[spectralStart] += num2;
                        }
                    }
                    spectralStart++;
                }
                stream.eob_run--;
            }
        }
コード例 #13
0
 public void DecodeScanBaseline(byte numberOfComponents, byte[] componentSelector, int resetInterval, JPEGBinaryReader jpegReader, ref byte marker)
 {
     for (int i = 0; i < numberOfComponents; i++)
     {
         JpegComponent componentById = Scan.GetComponentById(componentSelector[i]);
         componentById.Decode = componentById.DecodeBaseline;
     }
     DecodeScan(numberOfComponents, componentSelector, resetInterval, jpegReader, ref marker);
 }
コード例 #14
0
        public void DecodeScanProgressive(byte successiveApproximation, byte startSpectralSelection, byte endSpectralSelection, byte numberOfComponents, byte[] componentSelector, int resetInterval, JPEGBinaryReader jpegReader, ref byte marker)
        {
            byte b             = (byte)(successiveApproximation >> 4);
            byte successiveLow = (byte)(successiveApproximation & 0xF);

            if (startSpectralSelection > endSpectralSelection || endSpectralSelection > 63)
            {
                throw new Exception("Bad spectral selection.");
            }
            bool flag  = startSpectralSelection == 0;
            bool flag2 = b != 0;

            if (flag)
            {
                if (endSpectralSelection != 0)
                {
                    throw new Exception("Bad spectral selection for DC only scan.");
                }
            }
            else if (numberOfComponents > 1)
            {
                throw new Exception("Too many components for AC scan!");
            }
            for (int i = 0; i < numberOfComponents; i++)
            {
                JpegComponent componentById = Scan.GetComponentById(componentSelector[i]);
                componentById.successiveLow = successiveLow;
                if (flag)
                {
                    if (flag2)
                    {
                        componentById.Decode = componentById.DecodeDCRefine;
                    }
                    else
                    {
                        componentById.Decode = componentById.DecodeDCFirst;
                    }
                    continue;
                }
                componentById.spectralStart = startSpectralSelection;
                componentById.spectralEnd   = endSpectralSelection;
                if (flag2)
                {
                    componentById.Decode = componentById.DecodeACRefine;
                }
                else
                {
                    componentById.Decode = componentById.DecodeACFirst;
                }
            }
            DecodeScan(numberOfComponents, componentSelector, resetInterval, jpegReader, ref marker);
        }
コード例 #15
0
        public void DecodeACRefine(JPEGBinaryReader stream, float[] dest)
        {
            int p1 = 1 << successiveLow;
            int m1 = (-1) << successiveLow;

            int k = spectralStart;

            if (stream.eob_run == 0)
            {
                for (; k <= spectralEnd; k++)
                {
                    #region Decode and check S

                    int s = ACTable.Decode(stream);
                    int r = s >> 4;
                    s &= 15;

                    if (s != 0)
                    {
                        if (s != 1)
                        {
                            throw new Exception("Decode Error");
                        }

                        if (stream.ReadBits(1) == 1)
                        {
                            s = p1;
                        }
                        else
                        {
                            s = m1;
                        }
                    }
                    else
                    {
                        if (r != 15)
                        {
                            stream.eob_run = 1 << r;

                            if (r > 0)
                            {
                                stream.eob_run += stream.ReadBits(r);
                            }
                            break;
                        }
                    } // if (s != 0)

                    #endregion

                    // Apply the update
                    do
                    {
                        if (dest[k] != 0)
                        {
                            if (stream.ReadBits(1) == 1)
                            {
                                if (((int)dest[k] & p1) == 0)
                                {
                                    if (dest[k] >= 0)
                                    {
                                        dest[k] += p1;
                                    }
                                    else
                                    {
                                        dest[k] += m1;
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (--r < 0)
                            {
                                break;
                            }
                        }

                        k++;
                    } while (k <= spectralEnd);

                    if ((s != 0) && k < 64)
                    {
                        dest[k] = s;
                    }
                } // for k = start ... end
            }
            if (stream.eob_run > 0)
            {
                for (; k <= spectralEnd; k++)
                {
                    if (dest[k] != 0)
                    {
                        if (stream.ReadBits(1) == 1)
                        {
                            if (((int)dest[k] & p1) == 0)
                            {
                                if (dest[k] >= 0)
                                {
                                    dest[k] += p1;
                                }
                                else
                                {
                                    dest[k] += m1;
                                }
                            }
                        }
                    }
                }

                stream.eob_run--;
            }
        }
コード例 #16
0
 public void DecodeMCU(JPEGBinaryReader jpegReader, int i, int j)
 {
     Decode(jpegReader, scanMCUs[i, j]);
 }
コード例 #17
0
ファイル: JpegFrame.cs プロジェクト: bufang-master/Adventure
        public void DecodeScanProgressive(byte successiveApproximation, byte startSpectralSelection, byte endSpectralSelection,
                                          byte numberOfComponents, byte[] componentSelector, int resetInterval, JPEGBinaryReader jpegReader, ref byte marker)
        {
            byte successiveHigh = (byte)(successiveApproximation >> 4);
            byte successiveLow  = (byte)(successiveApproximation & 0x0f);

            if ((startSpectralSelection > endSpectralSelection) || (endSpectralSelection > 63))
            {
                throw new Exception("Bad spectral selection.");
            }

            bool dcOnly         = startSpectralSelection == 0;
            bool refinementScan = (successiveHigh != 0);

            if (dcOnly) // DC scan
            {
                if (endSpectralSelection != 0)
                {
                    throw new Exception("Bad spectral selection for DC only scan.");
                }
            }
            else // AC scan
            {
                if (numberOfComponents > 1)
                {
                    throw new Exception("Too many components for AC scan!");
                }
            }

            // Set the decode function for all the components
            // TODO: set this for the scan and let the component figure it out
            for (int compIndex = 0; compIndex < numberOfComponents; compIndex++)
            {
                JpegComponent comp = Scan.GetComponentById(componentSelector[compIndex]);

                comp.successiveLow = successiveLow;

                if (dcOnly)
                {
                    if (refinementScan) // DC refine
                    {
                        comp.Decode = comp.DecodeDCRefine;
                    }
                    else  //               DC first
                    {
                        comp.Decode = comp.DecodeDCFirst;
                    }
                }
                else
                {
                    comp.spectralStart = startSpectralSelection;
                    comp.spectralEnd   = endSpectralSelection;

                    if (refinementScan) // AC refine
                    {
                        comp.Decode = comp.DecodeACRefine;
                    }
                    else  //               AC first
                    {
                        comp.Decode = comp.DecodeACFirst;
                    }
                }
            }

            DecodeScan(numberOfComponents, componentSelector, resetInterval, jpegReader, ref marker);
        }