FluxJpeg.Core.Decoder.JpegComponent.DecodeACRefine C# (CSharp) Method

DecodeACRefine() public method

public DecodeACRefine ( JPEGBinaryReader stream, float dest ) : void
stream FluxJpeg.Core.IO.JPEGBinaryReader
dest float
return void
        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--;
            }
        }