예제 #1
0
        private void DecodeDjvuDocument(DjvuReader reader)
        {
            //Check the first 4 bytes
            CheckDjvuHeader(reader);
            DecodeFormChunk(reader);

            BuildPageList();

            if (Navigation == null)
            {
                Navigation = new DocumentNavigator(this);
            }

            ActivePage = Pages.FirstOrDefault();
            LastPage   = Pages.Last();
            FirstPage  = Pages.First();

            // Run the preload in the background with low priority
            //var thread = new Thread(() =>
            //                            {
            //                                // Start after a bit
            //                                Thread.Sleep(5000);
            //                                Pages.ToList().ForEach(x => x.Preload());
            //                            });
            //thread.Priority = ThreadPriority.Lowest;
            //thread.IsBackground = true;
            //thread.Start();
            //Task.Factory.StartNew(() => Parallel.ForEach(Pages, page => page.Preload()), TaskCreationOptions.LongRunning);
        }
예제 #2
0
        protected void Dispose(bool disposing)
        {
            if (_Disposed)
            {
                return;
            }

            if (disposing)
            {
            }

            if (_Reader != null)
            {
                _Reader.Close();
                _Reader = null;
            }

            for (int i = 0; i < _Pages?.Count; i++)
            {
                _Pages[i]?.Dispose();
            }
            _Pages?.Clear();

            _Disposed = true;
        }
예제 #3
0
        public DjvuDocument(string location, int identifier)
        {
            Identifier = identifier;
            _reader    = new DjvuReader(location);
            _name      = Path.GetFileNameWithoutExtension(location);
            _location  = location;

            DecodeDjvuDocument(_reader);
        }
예제 #4
0
        public DjvuDocument(Stream stream, string fileName)
        {
            Identifier = 0;
            _reader    = new DjvuReader(stream);
            _name      = Path.GetFileNameWithoutExtension(fileName);
            _location  = fileName;

            DecodeDjvuDocument(_reader);
        }
예제 #5
0
 /// <summary>
 /// Decodes the available IFF chunks
 /// </summary>
 /// <param name="reader"></param>
 internal void DecodeRootForm(DjvuReader reader)
 {
     RootForm = DjvuParser.GetRootForm(reader, null, this);
     RootForm.Initialize(reader);
     foreach (IDjvuNode chunk in RootForm.Children)
     {
         chunk.Initialize(reader);
     }
 }
예제 #6
0
        public void Load(string filePath, int identifier = 0)
        {
            Identifier = identifier;
            _Reader    = new DjvuReader(filePath);
            _name      = Path.GetFileNameWithoutExtension(filePath);
            _location  = filePath;

            DecodeDjvuDocument(_Reader);
        }
예제 #7
0
        /// <summary>
        /// Checks for a valid file header
        /// </summary>
        /// <param name="reader"></param>
        private void CheckDjvuHeader(DjvuReader reader)
        {
            byte[] header = new byte[4];
            reader.Read(header, 0, 4);

            if (header[0] != 0x41 || header[1] != 0x54 || header[2] != 0x26 || header[3] != 0x54)
            {
                throw new Exception("File header is invalid");
            }
        }
예제 #8
0
        /// <summary>
        /// Clones the reader for parallel reading at the given position
        /// </summary>
        /// <returns></returns>
        public DjvuReader CloneReader(long position, int length)
        {
            DjvuReader newReader = null;

            // Clone the reader
            newReader          = _location != null ? new DjvuReader(_location) : new DjvuReader(BaseStream);
            newReader.Position = position;

            return(newReader.GetFixedLengthStream(length));
        }
예제 #9
0
        /// <summary>
        /// Clones the reader for parallel reading at the given position
        /// </summary>
        /// <returns></returns>
        public DjvuReader CloneReader(long position)
        {
            DjvuReader newReader = null;

            // Clone the reader
            newReader          = _location != null ? new DjvuReader(_location) : new DjvuReader(BaseStream);
            newReader.Position = position;

            return(newReader);
        }
예제 #10
0
        internal void DecodeDjvuDocument(DjvuReader reader)
        {
            //Check the first 4 bytes
            CheckDjvuHeader(reader);
            DecodeRootForm(reader);

            BuildPageList();

            if (Navigation == null)
            {
                Navigation = new DocumentNavigator(this);
            }

            if (Pages?.Count > 0)
            {
                ActivePage = FirstPage = Pages[0];
                LastPage   = Pages[Pages.Count - 1];
            }
        }
예제 #11
0
        /// <summary>
        /// Clones the reader for parallel reading at the given position
        /// </summary>
        /// <returns></returns>
        public IDjvuReader CloneReader(long position)
        {
            DjvuReader newReader = null;

            // TODO Get rid of not properly synchronized clones or synchronize readers

            // Do a deep clone with new BaseStream
            if (_Location != null)
            {
                newReader = new DjvuReader(_Location);
            }
            else
            {
                MemoryStream stream = new MemoryStream((int)BaseStream.Length);
                BaseStream.CopyTo(stream);
                newReader = new DjvuReader(stream);
            }
            newReader.Position = position;
            return(newReader);
        }
예제 #12
0
        /// <summary>
        /// Checks for a valid DjVu AT&T file header
        /// </summary>
        /// <param name="reader"></param>
        internal void CheckDjvuHeader(DjvuReader reader)
        {
            long previousPosition = reader.Position;

            try
            {
                reader.Position = 0;
                const uint expectedHeader = 0x54265441;
                uint       actual         = reader.ReadUInt32();

                if (expectedHeader != actual)
                {
                    throw new DjvuFormatException("DjVu \"AT$T\" file header is invalid");
                }
            }
            finally
            {
                reader.Position = previousPosition + 4;
            }
        }
예제 #13
0
 /// <summary>
 /// Decodes the available IFF chunks
 /// </summary>
 /// <param name="reader"></param>
 private void DecodeFormChunk(DjvuReader reader)
 {
     _formChunk = new FormChunk(reader, null, this);
 }