示例#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());
            }
        }
示例#2
0
        public DirectoryList ReadJpegSegments(IEnumerable <JpegSegment> segments)
        {
            // This Extract structure is a little different since we only want
            // to return one HuffmanTablesDirectory for one-to-many segments
            HuffmanTablesDirectory directory = null;

            foreach (var segment in segments)
            {
                if (directory == null)
                {
                    directory = new HuffmanTablesDirectory();
                }

                Extract(new SequentialByteArrayReader(segment.Bytes), directory);
            }

            if (directory != null)
            {
                return new List <Directory>()
                       {
                           directory
                       }
            }
            ;

            return(Directory.EmptyList);
        }