Esempio n. 1
0
 bool ParseSegmentHeader(BitReader br)
 {
     m_segment_hdr.UseSegment = br.GetNextBit() != 0;
     if (m_segment_hdr.UseSegment)
     {
         m_segment_hdr.UpdateMap = br.GetNextBit() != 0;
         if (0 != br.GetNextBit())
         {   // update data
             m_segment_hdr.AbsoluteDelta = br.GetNextBit() != 0;
             for (int s = 0; s < NumMbSegments; ++s)
             {
                 m_segment_hdr.Quantizer[s] = (byte)(br.GetNextBit() != 0 ? br.GetSignedValue (7) : 0);
             }
             for (int s = 0; s < NumMbSegments; ++s)
             {
                 m_segment_hdr.FilterStrength[s] = (byte)(br.GetNextBit() != 0 ? br.GetSignedValue (6) : 0);
             }
         }
         if (m_segment_hdr.UpdateMap)
         {
             for (int s = 0; s < TreeProbs; ++s)
             {
                 m_proba.Segments[s] = (byte)(br.GetNextBit() != 0 ? br.GetBits (8) : 255);
             }
         }
     }
     else
     {
         m_segment_hdr.UpdateMap = false;
     }
     return !br.Eof;
 }
Esempio n. 2
0
        void ParseQuant(BitReader br)
        {
            int base_q0 = br.GetBits (7);
            int dqy1_dc = br.GetNextBit() != 0 ? br.GetSignedValue (4) : 0;
            int dqy2_dc = br.GetNextBit() != 0 ? br.GetSignedValue (4) : 0;
            int dqy2_ac = br.GetNextBit() != 0 ? br.GetSignedValue (4) : 0;
            int dquv_dc = br.GetNextBit() != 0 ? br.GetSignedValue (4) : 0;
            int dquv_ac = br.GetNextBit() != 0 ? br.GetSignedValue (4) : 0;

            for (int i = 0; i < NumMbSegments; ++i)
            {
                int q;
                if (m_segment_hdr.UseSegment)
                {
                    q = m_segment_hdr.Quantizer[i];
                    if (!m_segment_hdr.AbsoluteDelta)
                        q += base_q0;
                }
                else if (i > 0)
                {
                    m_dqm[i] = m_dqm[0];
                    continue;
                }
                else
                {
                    q = base_q0;
                }
                var m = m_dqm[i];
                m.y1_mat[0] = kDcTable[Clip (q + dqy1_dc, 127)];
                m.y1_mat[1] = kAcTable[Clip (q + 0,       127)];

                m.y2_mat[0] = kDcTable[Clip (q + dqy2_dc, 127)] * 2;
                // For all x in [0..284], x*155/100 is bitwise equal to (x*101581) >> 16.
                // The smallest precision for that is '(x*6349) >> 12' but 16 is a good
                // word size.
                m.y2_mat[1] = (kAcTable[Clip (q + dqy2_ac, 127)] * 101581) >> 16;
                if (m.y2_mat[1] < 8) m.y2_mat[1] = 8;

                m.uv_mat[0] = kDcTable[Clip (q + dquv_dc, 117)];
                m.uv_mat[1] = kAcTable[Clip (q + dquv_ac, 127)];

                m.uv_quant = q + dquv_ac;   // for dithering strength evaluation
            }
        }
Esempio n. 3
0
 void ParseProba(BitReader br)
 {
     for (int t = 0; t < NumTypes; ++t)
     {
         for (int b = 0; b < NumBands; ++b)
         for (int c = 0; c < NumCtx; ++c)
         for (int p = 0; p < NumProbas; ++p)
         {
             int v = br.GetBit (CoeffsUpdateProba[t,b,c,p]) != 0 ?
                 br.GetBits (8) : CoeffsProba0[t,b,c,p];
             m_proba.Bands[t,b].Probas[c][p] = (byte)v;
         }
         for (int b = 0; b < 16 + 1; ++b)
         {
             m_proba.BandsPtr[t][b] = m_proba.Bands[t,kBands[b]];
         }
     }
     m_use_skip_proba = br.GetNextBit() != 0;
     if (m_use_skip_proba)
         m_skip_p = br.GetBits (8);
 }
Esempio n. 4
0
 bool ParsePartitions(BitReader br, int size)
 {
     long part_end = m_input.BaseStream.Position + size;
     int size_left = size;
     m_num_parts = 1 << br.GetBits (2);
     int last_part = m_num_parts - 1;
     if (size < 3 * last_part)
         return false;
     long part_start = m_input.BaseStream.Position + last_part * 3;
     size_left -= last_part * 3;
     for (int p = 0; p < last_part; ++p)
     {
         int psize = ReadInt24();
         var sz_pos = m_input.BaseStream.Position;
         if (psize > size_left) psize = size_left;
         m_input.BaseStream.Position = part_start;
         m_parts[p] = new BitReader (m_input, psize);
         part_start += psize;
         size_left -= psize;
         m_input.BaseStream.Position = sz_pos;
     }
     m_input.BaseStream.Position = part_start;
     m_parts[last_part] = new BitReader (m_input, size_left);
     return part_start < part_end;
 }
Esempio n. 5
0
 bool ParseFilterHeader(BitReader br)
 {
     m_filter_hdr.Simple     = br.GetNextBit() != 0;
     m_filter_hdr.Level      = br.GetBits (6);
     m_filter_hdr.Sharpness  = br.GetBits (3);
     m_filter_hdr.UseLfDelta = br.GetNextBit() != 0;
     if (m_filter_hdr.UseLfDelta)
     {
         if (0 != br.GetNextBit())
         {   // update lf-delta?
             for (int i = 0; i < NumRefLfDeltas; ++i)
             {
                 if (0 != br.GetNextBit())
                     m_filter_hdr.RefLfDelta[i] = br.GetSignedValue (6);
             }
             for (int i = 0; i < NumModeLfDeltas; ++i)
             {
                 if (0 != br.GetNextBit())
                     m_filter_hdr.ModeLfDelta[i] = br.GetSignedValue (6);
             }
         }
     }
     m_filter_type = (0 == m_filter_hdr.Level) ? 0 : m_filter_hdr.Simple ? 1 : 2;
     return !br.Eof;
 }
 protected static void DeserializeId(BitReader br, UniqueId uid)
 {
     if (uid.Type == UniqueIdType.Steam)
     {
         uid.Id = br.ReadBytes(8);
     }
     else if (uid.Type == UniqueIdType.PS4)
     {
         uid.Id = br.ReadBytes(32);
     }
     else if (uid.Type == UniqueIdType.Unknown)
     {
         uid.Id = br.ReadBytes(3); // Will be 0
         if (uid.Id.Sum(x => x) != 0)
         {
             throw new Exception("Unknown id isn't 0, might be lost");
         }
     }
     else if (uid.Type == UniqueIdType.Xbox)
     {
         uid.Id = br.ReadBytes(8);
     }
     else
     {
         throw new ArgumentException(string.Format("Invalid type: {0}. Next bits are {1}", ((int)uid.Type).ToString(), br.GetBits(br.Position, Math.Min(4096, br.Length - br.Position)).ToBinaryString()));
     }
     uid.PlayerNumber = br.ReadByte();
 }