Ejemplo n.º 1
0
 public void DecodeDCRefine(JPEGBinaryReader stream, float[] dest)
 {
     if (stream.ReadBits(1) == 1)
     {
         dest[0] = (int)dest[0] | (1 << successiveLow);
     }
 }
Ejemplo n.º 2
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;
                }
            }
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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;
                }
            }
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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;
        }
Ejemplo n.º 7
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;
 }
Ejemplo n.º 8
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;
                }
            }
        }
Ejemplo n.º 9
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;
 }
Ejemplo n.º 10
0
 public void DecodeDCRefine(JPEGBinaryReader stream, float[] dest)
 {
     if (stream.ReadBits(1) == 1)
     {
         dest[0] = (int)dest[0] | (1 << successiveLow);
     }
 }
Ejemplo n.º 11
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;
        }
Ejemplo n.º 12
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--;
            }
        }
Ejemplo n.º 13
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;
                }
            }
        }
Ejemplo n.º 14
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--;
            }
        }