Beispiel #1
0
 bool UnpackSVariant(byte[] output, int dst, int channels, GrpVariant method)
 {
     if (GrpVariant.Default == method)
     {
         UnpackSv2(output, dst, channels);
     }
     else
     {
         UnpackSv1(output, dst, channels);
     }
     return(m_input.PeekByte() == -1); // rather loose test, but whatever
 }
Beispiel #2
0
        public void UnpackS(byte[] output, int dst, int channels)
        {
            try
            {
                if (UnpackSVariant(output, dst, channels, LastUsedMethod))
                {
                    return;
                }
            }
            catch { /* ignore parse errors */ }
            var method = GetOppositeVariant();

            m_input.Position = 0;
            if (UnpackSVariant(output, dst, channels, method))
            {
                LastUsedMethod = method;
            }
        }
Beispiel #3
0
        public void UnpackHDJ(byte[] output, int dst)
        {
            try
            {
                if (UnpackHDJVariant(output, dst, LastUsedMethod))
                {
                    return;
                }
            }
            catch { /* ignore unpack errors */ }
            var method = GetOppositeVariant();

            m_input.Position = 0;
            if (!UnpackHDJVariant(output, dst, method))
            {
                throw new InvalidFormatException();
            }
            LastUsedMethod = method;
        }
Beispiel #4
0
        private bool UnpackHDJVariant(byte[] output, int dst, GrpVariant method)
        {
            ResetBits();
            int  word_count = 0;
            int  byte_count = 0;
            uint next_byte  = 0;
            uint next_word  = 0;

            while (dst < output.Length)
            {
                if (GetNextBit() != 0)
                {
                    int  count      = 0;
                    bool long_count = false;
                    int  offset;
                    if (GetNextBit() != 0)
                    {
                        if (0 == word_count)
                        {
                            next_word  = m_input.ReadUInt32();
                            word_count = 2;
                        }
                        count       = (int)((next_word >> 13) & 7) + 3;
                        offset      = (int)(next_word | 0xFFFFE000);
                        next_word >>= 16;
                        --word_count;
                        long_count = 10 == count;
                    }
                    else
                    {
                        if (method == GrpVariant.Default)
                        {
                            count = GetBits(2);
                        }
                        if (0 == byte_count)
                        {
                            next_byte  = m_input.ReadUInt32();
                            byte_count = 4;
                        }
                        if (method != GrpVariant.Default)
                        {
                            count = GetBits(2);
                        }
                        count      += 2;
                        long_count  = 5 == count;
                        offset      = (int)(next_byte | 0xFFFFFF00);
                        next_byte >>= 8;
                        --byte_count;
                    }
                    if (long_count)
                    {
                        int n = 0;
                        while (GetNextBit() != 0)
                        {
                            ++n;
                        }

                        if (n != 0)
                        {
                            count += GetBits(n) + 1;
                        }
                    }
                    int src = dst + offset;
                    if (src < 0 || src >= dst || dst + count > output.Length)
                    {
                        return(false);
                    }
                    Binary.CopyOverlapped(output, src, dst, count);
                    dst += count;
                }
                else
                {
                    if (0 == byte_count)
                    {
                        next_byte  = m_input.ReadUInt32();
                        byte_count = 4;
                    }
                    output[dst++] = (byte)next_byte;
                    next_byte   >>= 8;
                    --byte_count;
                }
            }
            return(true);
        }