Exemplo n.º 1
0
        public void Extract(SequentialReader reader, HuffmanTablesDirectory directory)
        {
            try
            {
                while (reader.Available() > 0)
                {
                    byte header = reader.GetByte();
                    HuffmanTableClass tableClass = HuffmanTable.TypeOf((header & 0xF0) >> 4);
                    int tableDestinationId       = header & 0xF;

                    byte[] lBytes = GetBytes(reader, 16);
                    int    vCount = 0;
                    foreach (byte b in lBytes)
                    {
                        vCount += (b & 0xFF);
                    }
                    byte[] vBytes = GetBytes(reader, vCount);
                    directory.AddTable(new HuffmanTable(tableClass, tableDestinationId, lBytes, vBytes));
                }
            }
            catch (IOException me)
            {
                directory.AddError(me.ToString());
            }
        }
Exemplo n.º 2
0
        public BoxLocation(SequentialReader reader)
        {
            Origin = (ulong)reader.Position;

            // Four bytes for the length
            Length = reader.GetUInt32();

            // Four bytes for the type (4CC, in ASCII)
            Type = reader.GetUInt32();

            // Handle special length values
            Length = Length switch
            {
                // A length of 0 means the box continues until the end of the stream
                0 => (ulong)reader.Available(), // Include 8 bytes for length/type

                // A length of 1 means the length is stored in 64 bits
                1 => reader.GetUInt64(),

                // The length is fine so keep it
                _ => Length
            };
        }
    }