Debian Codegraph @

src/jb2/jb2coder.h

raw
1 /*
2 * jb2coder.h - coding character positions and JB2 records
3 */
4
5 #ifndef MDJVU_JB2CODER_H
6 #define MDJVU_JB2CODER_H
7
8 #include "bmpcoder.h"
9
10 // struct JB2Rect - a simple rectangle class {{{
11
12 struct JB2Rect
13 {
14 int left, top, width, height;
15 inline JB2Rect() {}
16 inline JB2Rect(int l, int t, int w, int h)
17 : left(l), top(t), width(w), height(h) {}
18 };
19
20 // struct JB2Rect }}}
21
22 // JB2Coder interface {{{
23
24 /* Watcher interface + implementation {{{ */
25
26 struct Watcher : ZPMemoryWatcher
27 {
28 int32 count;
29 Watcher() : count(0) {}
30
31 virtual void handle_allocation()
32 {
33 count++;
34 }
35
36 void reset() {count = 0;}
37 };
38
39 /* Watcher }}} */
40
41 class JB2Coder
42 {
43 public:
44 Watcher watcher;
45 ZPNumContext
46 image_size,
47 matching_symbol_index,
48 symbol_column_number,
49 symbol_row_number,
50 same_line_column_offset,
51 same_line_row_offset,
52 new_line_column_offset,
53 new_line_row_offset,
54 comment_length,
55 comment_octet,
56 required_dictionary_size;
57
58 ZPBitContext eventual_image_refinement, offset_type;
59 JB2Coder();
60 ~JB2Coder();
61
62 protected:
63 ZPNumContext record_type;
64 JB2Rect first, prev3, prev2, prev1;
65 int line_counter;
66 void reset_numcontexts();
67 };
68
69 // JB2Coder interface }}}
70
71 // JB2Decoder interface {{{
72
73 struct JB2Decoder : JB2Coder, JB2BitmapDecoder
74 {
75 ZPDecoder zp;
76 JB2Decoder(FILE *f, int32 chunk_length);
77 JB2RecordType decode_record_type();
78
79 // decodes character position and creates a new blit
80 int32 decode_blit(mdjvu_image_t, int32 shape_index);
81
82 void reset(); // resets numcontexts as required by "reset" record
83
84 private:
85 void decode_character_position(int32 &x, int32 &y, int32 w, int32 h);
86 };
87
88 // JB2Decoder interface }}}
89
90 // JB2Encoder interface {{{
91
92 struct JB2Encoder : JB2Coder, JB2BitmapEncoder
93 {
94 ZPEncoder zp;
95 JB2Encoder(FILE *f);
96
97 // encodes blit position
98 // w and h are passed here in case of substitution
99 void encode_blit(mdjvu_image_t img, int32 blit, int32 w, int32 h);
100
101 void open_record(JB2RecordType);
102 void close_record(); // takes care of the DjVu 3 numcontext reset
103
104 private:
105 void encode_character_position(int x, int y, int w, int h);
106 bool no_symbols_yet;
107 };
108
109 // JB2Encoder interface }}}
110
111 #endif