00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 #ifndef _DJVUFILE_H
00058 #define _DJVUFILE_H
00059 #ifdef HAVE_CONFIG_H
00060 #include "config.h"
00061 #endif
00062 #if NEED_GNUG_PRAGMAS
00063 # pragma interface
00064 #endif
00065
00066
00067 #include "DjVuInfo.h"
00068 #include "DjVuPalette.h"
00069 #include "DjVuPort.h"
00070
00071 #ifdef HAVE_NAMESPACES
00072 namespace DJVU {
00073 # ifdef NOT_DEFINED // Just to fool emacs c++ mode
00074 }
00075 #endif
00076 #endif
00077
00078 class DjVuTXT;
00079 class ByteStream;
00080 class DataPool;
00081 class JB2Image;
00082 class JB2Dict;
00083 class IW44Image;
00084 class IFFByteStream;
00085 class GPixmap;
00086 class DjVuNavDir;
00087
00088
00109
00201 class DjVuFile : public DjVuPort
00202 {
00203 public:
00204 enum { DECODING=1, DECODE_OK=2, DECODE_FAILED=4, DECODE_STOPPED=8,
00205 DATA_PRESENT=16, ALL_DATA_PRESENT=32, INCL_FILES_CREATED=64,
00206 MODIFIED=128, DONT_START_DECODE=256, STOPPED=512,
00207 BLOCKED_STOPPED=1024, CAN_COMPRESS=2048, NEEDS_COMPRESSION=4096 };
00208 enum { STARTED=1, FINISHED=2 };
00209
00212
00213 GP<DjVuInfo> info;
00215 GP<IW44Image> bg44;
00217 GP<GPixmap> bgpm;
00219 GP<JB2Image> fgjb;
00221 GP<JB2Dict> fgjd;
00223 GP<GPixmap> fgpm;
00225 GP<DjVuPalette> fgbc;
00227 GP<ByteStream> anno;
00229 GP<ByteStream> text;
00231 GP<ByteStream> meta;
00233 GP<DjVuNavDir> dir;
00235 GUTF8String description;
00237 GUTF8String mimetype;
00239 int file_size;
00241
00242 protected:
00244 DjVuFile(void);
00245 public:
00246 virtual ~DjVuFile(void);
00247
00261 void init(const GP<ByteStream> & str);
00262
00264 static GP<DjVuFile> create( const GP<ByteStream> & str,
00265 const ErrorRecoveryAction recover_action=ABORT,
00266 const bool verbose_eof=true);
00267
00297 void init(const GURL & url, GP<DjVuPort> port=0);
00298
00300 static GP<DjVuFile> create(
00301 const GURL & url, GP<DjVuPort> port=0,
00302 const ErrorRecoveryAction recover_action=ABORT,
00303 const bool verbose_eof=true);
00304
00308 void disable_standard_port(void);
00309
00319 GP<DjVuNavDir> find_ndir(void);
00320
00342 long get_flags(void) const;
00344 bool is_decoding(void) const;
00346 bool is_decode_ok(void) const;
00348 bool is_decode_failed(void) const;
00351 bool is_decode_stopped(void) const;
00353 bool is_data_present(void) const;
00356 bool is_all_data_present(void) const;
00360 bool are_incl_files_created(void) const;
00361 bool is_modified(void) const;
00362 bool needs_compression(void) const;
00363 bool can_compress(void) const;
00364 void set_modified(bool m);
00365 void set_needs_compression(bool m);
00366 void set_can_compress(bool m);
00368
00370 GURL get_url(void) const;
00371
00378 void start_decode(void);
00382 bool resume_decode(const bool sync=false);
00387 void stop_decode(bool sync);
00407 void stop(bool only_blocked);
00410 void wait_for_finish(void);
00422 GP<DjVuNavDir> decode_ndir(void);
00424 void reset(void);
00434 void process_incl_chunks(void);
00436
00437
00438 unsigned int get_memory_usage(void) const;
00439
00452 GPList<DjVuFile> get_included_files(bool only_created=true);
00453
00458 void insert_file(const GUTF8String &id, int chunk_num=1);
00460 void unlink_file(const GUTF8String &id);
00463 static GP<DataPool> unlink_file(const GP<DataPool> & data, const GUTF8String &name);
00464
00466 int get_chunks_number(void);
00468 GUTF8String get_chunk_name(int chunk_num);
00470 bool contains_chunk(const GUTF8String &chunk_name);
00471
00490 GP<ByteStream> get_merged_anno(int * max_level_ptr=0);
00491
00500 GP<ByteStream> get_anno(void);
00501
00510 GP<ByteStream> get_text(void);
00511
00520 GP<ByteStream> get_meta(void);
00521
00529 GP<ByteStream> get_merged_anno(const GList<GURL> & ignore_list,
00530 int * max_level_ptr);
00531
00533 void remove_anno(void);
00534
00536 void remove_text(void);
00537
00539 void remove_meta(void);
00540
00544 bool contains_anno(void);
00545
00549 bool contains_text(void);
00550
00554 bool contains_meta(void);
00555
00557 void change_info(GP<DjVuInfo> info, const bool do_reset=false);
00558
00560 void change_text(GP<DjVuTXT> txt, const bool do_reset=false);
00561
00563 void change_meta(const GUTF8String &meta, const bool do_reset=false);
00564
00577 GP<ByteStream> get_djvu_bytestream(const bool included_too, const bool no_ndir=true);
00578
00581 GP<DataPool> get_djvu_data(const bool included_too, const bool no_ndir=true );
00583
00584
00585 GP<DataPool> get_init_data_pool(void) const { return data_pool; };
00586
00587
00588 void move(const GURL & dir_url);
00589
00592 void set_name(const GUTF8String &name);
00593
00594
00595 GSafeFlags & get_safe_flags(void);
00596
00597
00598 void merge_anno(ByteStream &out);
00599
00600
00601 void get_text(ByteStream &out);
00602
00603
00604 void get_meta(ByteStream &out);
00605
00606
00607 void rebuild_data_pool(void);
00608
00609
00610 virtual bool inherits(const GUTF8String &class_name) const;
00611 virtual void notify_chunk_done(const DjVuPort * source, const GUTF8String &name);
00612 virtual void notify_file_flags_changed(const DjVuFile * source,
00613 long set_mask, long clr_mask);
00614 virtual void set_recover_errors(const ErrorRecoveryAction=ABORT);
00615 virtual void set_verbose_eof(const bool verbose_eof=true);
00616 virtual void report_error(const GException &ex,const bool=true);
00617 static void set_decode_codec(GP<GPixmap> (*codec)(ByteStream &bs));
00618
00619 protected:
00620 GURL url;
00621 GP<DataPool> data_pool;
00622
00623 GPList<DjVuFile> inc_files_list;
00624 GCriticalSection inc_files_lock;
00625 GCriticalSection anno_lock;
00626 GCriticalSection text_lock;
00627 GCriticalSection meta_lock;
00628 ErrorRecoveryAction recover_errors;
00629 bool verbose_eof;
00630 int chunks_number;
00631 private:
00632 bool initialized;
00633 GSafeFlags flags;
00634
00635 GThread * decode_thread;
00636 GP<DataPool> decode_data_pool;
00637 GP<DjVuFile> decode_life_saver;
00638
00639 GP<DjVuPort> simple_port;
00640
00641 GMonitor chunk_mon, finish_mon;
00642
00643
00644 static void static_decode_func(void *);
00645 void decode_func(void);
00646 void decode(const GP<ByteStream> &str);
00647 GUTF8String decode_chunk(const GUTF8String &chkid,
00648 const GP<ByteStream> &str, bool djvi, bool djvu, bool iw44);
00649 int get_dpi(int w, int h);
00650
00651
00652 static GP<JB2Dict> static_get_fgjd(void *);
00653 GP<JB2Dict> get_fgjd(int block=0);
00654
00655
00656 void wait_for_chunk(void);
00657 bool wait_for_finish(bool self);
00658
00659
00660 GP<DjVuFile> process_incl_chunk(ByteStream & str, int file_num=-1);
00661
00662
00663 static void static_trigger_cb(void *);
00664 void trigger_cb(void);
00665
00666
00667 static void progress_cb(int pos, void *);
00668 static void get_merged_anno(const GP<DjVuFile> & file,
00669 const GP<ByteStream> &str_out, const GList<GURL> & ignore_list,
00670 int level, int & max_level, GMap<GURL, void *> & map);
00671 static void get_anno(const GP<DjVuFile> & file,
00672 const GP<ByteStream> &str_out);
00673 static void get_text(const GP<DjVuFile> & file,
00674 const GP<ByteStream> &str_out);
00675 static void get_meta(const GP<DjVuFile> & file,
00676 const GP<ByteStream> &str_out);
00677
00678 void check() const;
00679 GP<DjVuNavDir>find_ndir(GMap<GURL, void *> & map);
00680 GP<DjVuNavDir>decode_ndir(GMap<GURL, void *> & map);
00681 void add_djvu_data(IFFByteStream & str,
00682 GMap<GURL, void *> & map,
00683 const bool included_too, const bool no_ndir=true);
00684 void move(GMap<GURL, void *> & map, const GURL & dir_url);
00685 private:
00686 static void decode(ByteStream *);
00687 static GUTF8String decode_chunk(const GUTF8String &, ByteStream *,bool,bool,bool);
00688 static void get_merged_anno(const GP<DjVuFile> &,ByteStream *,
00689 const GList<GURL> &, int, int &, GMap<GURL, void *> &);
00690 static void get_text(const GP<DjVuFile> &,ByteStream *);
00691 static void get_meta(const GP<DjVuFile> &,ByteStream *);
00692
00693 };
00694
00695 inline long
00696 DjVuFile::get_flags(void) const
00697 {
00698 return flags;
00699 }
00700
00701 inline GSafeFlags &
00702 DjVuFile::get_safe_flags(void)
00703 {
00704 return flags;
00705 }
00706
00707 inline bool
00708 DjVuFile::is_decoding(void) const
00709 {
00710 return (flags & DECODING)!=0;
00711 }
00712
00713 inline bool
00714 DjVuFile::is_decode_ok(void) const
00715 {
00716 return (flags & DECODE_OK)!=0;
00717 }
00718
00719 inline bool
00720 DjVuFile::is_decode_failed(void) const
00721 {
00722 return (flags & DECODE_FAILED)!=0;
00723 }
00724
00725 inline bool
00726 DjVuFile::is_decode_stopped(void) const
00727 {
00728 return (flags & DECODE_STOPPED)!=0;
00729 }
00730
00731 inline bool
00732 DjVuFile::is_data_present(void) const
00733 {
00734 return (flags & DATA_PRESENT)!=0;
00735 }
00736
00737 inline bool
00738 DjVuFile::is_all_data_present(void) const
00739 {
00740 return (flags & ALL_DATA_PRESENT)!=0;
00741 }
00742
00743 inline bool
00744 DjVuFile::are_incl_files_created(void) const
00745 {
00746 return (flags & INCL_FILES_CREATED)!=0;
00747 }
00748
00749 inline bool
00750 DjVuFile::is_modified(void) const
00751 {
00752 return (flags & MODIFIED)!=0;
00753 }
00754
00755 inline void
00756 DjVuFile::set_modified(bool m)
00757 {
00758 flags=m ? (flags | MODIFIED) : (flags & ~MODIFIED);
00759 }
00760
00761 inline bool
00762 DjVuFile::needs_compression(void) const
00763 {
00764 return (flags & NEEDS_COMPRESSION)!=0;
00765 }
00766
00767 inline void
00768 DjVuFile::set_needs_compression(bool m)
00769 {
00770 if (m) flags=flags | NEEDS_COMPRESSION;
00771 else flags=flags & ~NEEDS_COMPRESSION;
00772 }
00773
00774 inline bool
00775 DjVuFile::can_compress(void) const
00776 {
00777 return (flags & CAN_COMPRESS)!=0;
00778 }
00779
00780 inline void
00781 DjVuFile::set_can_compress(bool m)
00782 {
00783 if(info)
00784 {
00785 info->compressable=m;
00786 }
00787 if (m)
00788 {
00789 flags=flags | CAN_COMPRESS;
00790 } else
00791 {
00792 flags=flags & ~CAN_COMPRESS;
00793 }
00794 }
00795
00796 inline void
00797 DjVuFile::disable_standard_port(void)
00798 {
00799 simple_port=0;
00800 }
00801
00802 inline bool
00803 DjVuFile::inherits(const GUTF8String &class_name) const
00804 {
00805 return
00806 (GUTF8String("DjVuFile") == class_name) ||
00807 DjVuPort::inherits(class_name);
00808
00809
00810 }
00811
00812 inline void
00813 DjVuFile::wait_for_finish(void)
00814 {
00815 while(wait_for_finish(1))
00816 EMPTY_LOOP;
00817 }
00818
00819 inline GURL
00820 DjVuFile::get_url(void) const
00821 {
00822 return url;
00823 }
00824
00825 inline void
00826 DjVuFile::set_verbose_eof
00827 (const bool verbose)
00828 {
00829 verbose_eof=verbose;
00830 }
00831
00832 inline void
00833 DjVuFile::set_recover_errors
00834 (const ErrorRecoveryAction action)
00835 {
00836 recover_errors=action;
00837 }
00838
00840
00841
00842 #ifdef HAVE_NAMESPACES
00843 }
00844 # ifndef NOT_USING_DJVU_NAMESPACE
00845 using namespace DJVU;
00846 # endif
00847 #endif
00848 #endif