ReadBits() public method

Places n bits from the stream, where the most-significant bits from the first byte read end up as the most-significant of the returned n bits.
public ReadBits ( int n ) : int
n int Number of bits to return
return int
コード例 #1
0
ファイル: JpegComponent.cs プロジェクト: JuRogn/OA
 public float decode_dc_coefficient(JPEGBinaryReader JPEGStream)
 {
     int n = this.DCTable.Decode(JPEGStream);
     float num2 = JPEGStream.ReadBits(n);
     num2 = HuffmanTable.Extend((int) num2, n);
     num2 = this.previousDC + num2;
     this.previousDC = num2;
     return num2;
 }
コード例 #2
0
ファイル: JpegComponent.cs プロジェクト: JuRogn/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;
         }
     }
 }
コード例 #3
0
        /// <summary>
        /// Generated from text on F-23, F.13 - Huffman decoded of AC coefficients
        /// on ISO DIS 10918-1. Requirements and Guidelines.
        /// </summary>
        internal void decode_ac_coefficients(JPEGBinaryReader JPEGStream, float[] zz)
        {
            for (int k = 1; k < 64; k++)
            {
                int s = ACTable.Decode(JPEGStream);
                int r = s >> 4;
                s &= 15;


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

                    r = (int)JPEGStream.ReadBits(s);
                    s = (int)HuffmanTable.Extend(r, s);
                    zz[k] = s;
                }
                else
                {
                    if (r != 15)
                    {
                        //throw new JPEGMarkerFoundException();
                        return;
                    }
                    k += 15;
                }
            }
        }
コード例 #4
0
 /// <summary>
 /// Generated from text on F-22, F.2.2.1 - Huffman decoding of DC
 /// coefficients on ISO DIS 10918-1. Requirements and Guidelines.
 /// </summary>
 /// <param name="JPEGStream">Stream that contains huffman bits</param>
 /// <returns>DC coefficient</returns>
 public float decode_dc_coefficient(JPEGBinaryReader JPEGStream)
 {
     int t = DCTable.Decode(JPEGStream);
     float diff = JPEGStream.ReadBits(t);
     diff = HuffmanTable.Extend((int)diff, t);
     diff = (previousDC + diff);
     previousDC = diff;
     return diff;
 }
コード例 #5
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--;
            }
        }
コード例 #6
0
 public void DecodeDCRefine(JPEGBinaryReader stream, float[] dest)
 {
     if (stream.ReadBits(1) == 1)
     {
         dest[0] = (int)dest[0] | (1 << successiveLow);
     }
 }
コード例 #7
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;
                }
            }
        }
コード例 #8
0
        public void DecodeDCFirst(JPEGBinaryReader stream, float[] dest)
        {
            float[] datablock = new float[64];
            int s = DCTable.Decode(stream);
            int r = stream.ReadBits(s);
            s = HuffmanTable.Extend(r, s);
            s = (int)previousDC + s;
            previousDC = s;

            dest[0] = s << successiveLow;
        }
コード例 #9
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;
 }
コード例 #10
0
ファイル: HuffmanTable.cs プロジェクト: JuRogn/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;
 }
コード例 #11
0
ファイル: JpegComponent.cs プロジェクト: JuRogn/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;
             }
         }
     }
 }
コード例 #12
0
ファイル: JpegComponent.cs プロジェクト: JuRogn/OA
 public void DecodeDCFirst(JPEGBinaryReader stream, float[] dest)
 {
     float[] numArray = new float[0x40];
     int t = this.DCTable.Decode(stream);
     t = HuffmanTable.Extend(stream.ReadBits(t), t);
     t = ((int) this.previousDC) + t;
     this.previousDC = t;
     dest[0] = t << this.successiveLow;
 }
コード例 #13
0
ファイル: JpegComponent.cs プロジェクト: JuRogn/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--;
     }
 }