~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to plug-ins/faxg3/g3.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2008-10-06 13:30:41 UTC
  • mto: This revision was merged to the branch mainline in revision 35.
  • Revision ID: james.westby@ubuntu.com-20081006133041-3panbkcanaymfsmp
Tags: upstream-2.6.0
ImportĀ upstreamĀ versionĀ 2.6.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* #ident "@(#)g3.c     3.1 95/08/30 Copyright (c) Gert Doering" */
2
 
 
3
 
#include "config.h"
4
 
 
5
 
#include <stdlib.h>
6
 
#include <stdio.h>
7
 
 
8
 
#include <glib.h>
9
 
 
10
 
#include "g3.h"
11
 
 
12
 
struct g3code t_white[66] = {
13
 
{ 0,   0, 0x0ac,  8 },
14
 
{ 0,   1, 0x038,  6 },
15
 
{ 0,   2, 0x00e,  4 },
16
 
{ 0,   3, 0x001,  4 },
17
 
{ 0,   4, 0x00d,  4 },
18
 
{ 0,   5, 0x003,  4 },
19
 
{ 0,   6, 0x007,  4 },
20
 
{ 0,   7, 0x00f,  4 },
21
 
{ 0,   8, 0x019,  5 },
22
 
{ 0,   9, 0x005,  5 },
23
 
{ 0,  10, 0x01c,  5 },
24
 
{ 0,  11, 0x002,  5 },
25
 
{ 0,  12, 0x004,  6 },
26
 
{ 0,  13, 0x030,  6 },
27
 
{ 0,  14, 0x00b,  6 },
28
 
{ 0,  15, 0x02b,  6 },
29
 
{ 0,  16, 0x015,  6 },
30
 
{ 0,  17, 0x035,  6 },
31
 
{ 0,  18, 0x072,  7 },
32
 
{ 0,  19, 0x018,  7 },
33
 
{ 0,  20, 0x008,  7 },
34
 
{ 0,  21, 0x074,  7 },
35
 
{ 0,  22, 0x060,  7 },
36
 
{ 0,  23, 0x010,  7 },
37
 
{ 0,  24, 0x00a,  7 },
38
 
{ 0,  25, 0x06a,  7 },
39
 
{ 0,  26, 0x064,  7 },
40
 
{ 0,  27, 0x012,  7 },
41
 
{ 0,  28, 0x00c,  7 },
42
 
{ 0,  29, 0x040,  8 },
43
 
{ 0,  30, 0x0c0,  8 },
44
 
{ 0,  31, 0x058,  8 },
45
 
{ 0,  32, 0x0d8,  8 },
46
 
{ 0,  33, 0x048,  8 },
47
 
{ 0,  34, 0x0c8,  8 },
48
 
{ 0,  35, 0x028,  8 },
49
 
{ 0,  36, 0x0a8,  8 },
50
 
{ 0,  37, 0x068,  8 },
51
 
{ 0,  38, 0x0e8,  8 },
52
 
{ 0,  39, 0x014,  8 },
53
 
{ 0,  40, 0x094,  8 },
54
 
{ 0,  41, 0x054,  8 },
55
 
{ 0,  42, 0x0d4,  8 },
56
 
{ 0,  43, 0x034,  8 },
57
 
{ 0,  44, 0x0b4,  8 },
58
 
{ 0,  45, 0x020,  8 },
59
 
{ 0,  46, 0x0a0,  8 },
60
 
{ 0,  47, 0x050,  8 },
61
 
{ 0,  48, 0x0d0,  8 },
62
 
{ 0,  49, 0x04a,  8 },
63
 
{ 0,  50, 0x0ca,  8 },
64
 
{ 0,  51, 0x02a,  8 },
65
 
{ 0,  52, 0x0aa,  8 },
66
 
{ 0,  53, 0x024,  8 },
67
 
{ 0,  54, 0x0a4,  8 },
68
 
{ 0,  55, 0x01a,  8 },
69
 
{ 0,  56, 0x09a,  8 },
70
 
{ 0,  57, 0x05a,  8 },
71
 
{ 0,  58, 0x0da,  8 },
72
 
{ 0,  59, 0x052,  8 },
73
 
{ 0,  60, 0x0d2,  8 },
74
 
{ 0,  61, 0x04c,  8 },
75
 
{ 0,  62, 0x0cc,  8 },
76
 
{ 0,  63, 0x02c,  8 },
77
 
{ 0, -1, 0, 11 },               /* 11 0-bits == EOL, special handling */
78
 
{ 0, -1, 0, 0 }};               /* end of table */
79
 
 
80
 
/* make-up codes white */
81
 
struct g3code m_white[28] = {
82
 
{ 0,  64, 0x01b,  5 },
83
 
{ 0, 128, 0x009,  5 },
84
 
{ 0, 192, 0x03a,  6 },
85
 
{ 0, 256, 0x076,  7 },
86
 
{ 0, 320, 0x06c,  8 },
87
 
{ 0, 384, 0x0ec,  8 },
88
 
{ 0, 448, 0x026,  8 },
89
 
{ 0, 512, 0x0a6,  8 },
90
 
{ 0, 576, 0x016,  8 },
91
 
{ 0, 640, 0x0e6,  8 },
92
 
{ 0, 704, 0x066,  9 },
93
 
{ 0, 768, 0x166,  9 },
94
 
{ 0, 832, 0x096,  9 },
95
 
{ 0, 896, 0x196,  9 },
96
 
{ 0, 960, 0x056,  9 },
97
 
{ 0,1024, 0x156,  9 },
98
 
{ 0,1088, 0x0d6,  9 },
99
 
{ 0,1152, 0x1d6,  9 },
100
 
{ 0,1216, 0x036,  9 },
101
 
{ 0,1280, 0x136,  9 },
102
 
{ 0,1344, 0x0b6,  9 },
103
 
{ 0,1408, 0x1b6,  9 },
104
 
{ 0,1472, 0x032,  9 },
105
 
{ 0,1536, 0x132,  9 },
106
 
{ 0,1600, 0x0b2,  9 },
107
 
{ 0,1664, 0x006,  6 },
108
 
{ 0,1728, 0x1b2,  9 },
109
 
{ 0,  -1, 0, 0} };
110
 
 
111
 
 
112
 
struct g3code t_black[66] = {
113
 
{ 0,   0, 0x3b0, 10 },
114
 
{ 0,   1, 0x002,  3 },
115
 
{ 0,   2, 0x003,  2 },
116
 
{ 0,   3, 0x001,  2 },
117
 
{ 0,   4, 0x006,  3 },
118
 
{ 0,   5, 0x00c,  4 },
119
 
{ 0,   6, 0x004,  4 },
120
 
{ 0,   7, 0x018,  5 },
121
 
{ 0,   8, 0x028,  6 },
122
 
{ 0,   9, 0x008,  6 },
123
 
{ 0,  10, 0x010,  7 },
124
 
{ 0,  11, 0x050,  7 },
125
 
{ 0,  12, 0x070,  7 },
126
 
{ 0,  13, 0x020,  8 },
127
 
{ 0,  14, 0x0e0,  8 },
128
 
{ 0,  15, 0x030,  9 },
129
 
{ 0,  16, 0x3a0, 10 },
130
 
{ 0,  17, 0x060, 10 },
131
 
{ 0,  18, 0x040, 10 },
132
 
{ 0,  19, 0x730, 11 },
133
 
{ 0,  20, 0x0b0, 11 },
134
 
{ 0,  21, 0x1b0, 11 },
135
 
{ 0,  22, 0x760, 11 },
136
 
{ 0,  23, 0x0a0, 11 },
137
 
{ 0,  24, 0x740, 11 },
138
 
{ 0,  25, 0x0c0, 11 },
139
 
{ 0,  26, 0x530, 12 },
140
 
{ 0,  27, 0xd30, 12 },
141
 
{ 0,  28, 0x330, 12 },
142
 
{ 0,  29, 0xb30, 12 },
143
 
{ 0,  30, 0x160, 12 },
144
 
{ 0,  31, 0x960, 12 },
145
 
{ 0,  32, 0x560, 12 },
146
 
{ 0,  33, 0xd60, 12 },
147
 
{ 0,  34, 0x4b0, 12 },
148
 
{ 0,  35, 0xcb0, 12 },
149
 
{ 0,  36, 0x2b0, 12 },
150
 
{ 0,  37, 0xab0, 12 },
151
 
{ 0,  38, 0x6b0, 12 },
152
 
{ 0,  39, 0xeb0, 12 },
153
 
{ 0,  40, 0x360, 12 },
154
 
{ 0,  41, 0xb60, 12 },
155
 
{ 0,  42, 0x5b0, 12 },
156
 
{ 0,  43, 0xdb0, 12 },
157
 
{ 0,  44, 0x2a0, 12 },
158
 
{ 0,  45, 0xaa0, 12 },
159
 
{ 0,  46, 0x6a0, 12 },
160
 
{ 0,  47, 0xea0, 12 },
161
 
{ 0,  48, 0x260, 12 },
162
 
{ 0,  49, 0xa60, 12 },
163
 
{ 0,  50, 0x4a0, 12 },
164
 
{ 0,  51, 0xca0, 12 },
165
 
{ 0,  52, 0x240, 12 },
166
 
{ 0,  53, 0xec0, 12 },
167
 
{ 0,  54, 0x1c0, 12 },
168
 
{ 0,  55, 0xe40, 12 },
169
 
{ 0,  56, 0x140, 12 },
170
 
{ 0,  57, 0x1a0, 12 },
171
 
{ 0,  58, 0x9a0, 12 },
172
 
{ 0,  59, 0xd40, 12 },
173
 
{ 0,  60, 0x340, 12 },
174
 
{ 0,  61, 0x5a0, 12 },
175
 
{ 0,  62, 0x660, 12 },
176
 
{ 0,  63, 0xe60, 12 },
177
 
{ 0,  -1, 0x000, 11 },
178
 
{ 0,  -1, 0, 0 } };
179
 
 
180
 
struct g3code m_black[28] = {
181
 
{ 0,  64, 0x3c0, 10 },
182
 
{ 0, 128, 0x130, 12 },
183
 
{ 0, 192, 0x930, 12 },
184
 
{ 0, 256, 0xda0, 12 },
185
 
{ 0, 320, 0xcc0, 12 },
186
 
{ 0, 384, 0x2c0, 12 },
187
 
{ 0, 448, 0xac0, 12 },
188
 
{ 0, 512, 0x6c0, 13 },
189
 
{ 0, 576,0x16c0, 13 },
190
 
{ 0, 640, 0xa40, 13 },
191
 
{ 0, 704,0x1a40, 13 },
192
 
{ 0, 768, 0x640, 13 },
193
 
{ 0, 832,0x1640, 13 },
194
 
{ 0, 896, 0x9c0, 13 },
195
 
{ 0, 960,0x19c0, 13 },
196
 
{ 0,1024, 0x5c0, 13 },
197
 
{ 0,1088,0x15c0, 13 },
198
 
{ 0,1152, 0xdc0, 13 },
199
 
{ 0,1216,0x1dc0, 13 },
200
 
{ 0,1280, 0x940, 13 },
201
 
{ 0,1344,0x1940, 13 },
202
 
{ 0,1408, 0x540, 13 },
203
 
{ 0,1472,0x1540, 13 },
204
 
{ 0,1536, 0xb40, 13 },
205
 
{ 0,1600,0x1b40, 13 },
206
 
{ 0,1664, 0x4c0, 13 },
207
 
{ 0,1728,0x14c0, 13 },
208
 
{ 0,  -1, 0, 0 } };
209
 
 
210
 
void tree_add_node( struct g3_tree *p, struct g3code * g3c,
211
 
                        int bit_code, int bit_length )
212
 
{
213
 
int i;
214
 
 
215
 
    if ( bit_length <= FBITS )          /* leaf (multiple bits) */
216
 
    {
217
 
        g3c->nr_bits = bit_length;      /* leaf tag */
218
 
 
219
 
        if ( bit_length == FBITS )      /* full width */
220
 
        {
221
 
            p->nextb[ bit_code ] = (struct g3_tree *) g3c;
222
 
        }
223
 
        else                            /* fill bits */
224
 
          for ( i=0; i< ( 1 << (FBITS-bit_length)); i++ )
225
 
          {
226
 
            p->nextb[ bit_code + ( i << bit_length ) ] = (struct g3_tree *) g3c;
227
 
          }
228
 
    }
229
 
    else                                /* node */
230
 
    {
231
 
    struct g3_tree *p2;
232
 
 
233
 
        p2 = p->nextb[ bit_code & BITM ];
234
 
        if ( p2 == 0 )                  /* no sub-node exists */
235
 
        {
236
 
            p2 = p->nextb[ bit_code & BITM ] =
237
 
                ( struct g3_tree * ) calloc( 1, sizeof( struct g3_tree ));
238
 
            if ( p2 == NULL ) { perror( "malloc 3" ); exit(11); }
239
 
            p2->nr_bits = 0;            /* node tag */
240
 
 
241
 
        }
242
 
        if ( p2->nr_bits != 0 )
243
 
        {
244
 
            g_printerr ("internal table setup error\n" ); exit(6);
245
 
        }
246
 
        tree_add_node( p2, g3c, bit_code >> FBITS, bit_length - FBITS );
247
 
    }
248
 
}
249
 
 
250
 
void build_tree (struct g3_tree ** p, struct g3code * c )
251
 
{
252
 
    if ( *p == NULL )
253
 
    {
254
 
        (*p) = (struct g3_tree *) calloc( 1, sizeof(struct g3_tree) );
255
 
        if ( *p == NULL ) { perror( "malloc(1)" ); exit(10); }
256
 
 
257
 
        (*p)->nr_bits=0;
258
 
    }
259
 
 
260
 
    while ( c->bit_length != 0 )
261
 
    {
262
 
        tree_add_node( *p, c, c->bit_code, c->bit_length );
263
 
        c++;
264
 
    }
265
 
}
266
 
 
267
 
void init_byte_tab (int reverse, int byte_tab[] )
268
 
{
269
 
int i;
270
 
    if ( reverse ) for ( i=0; i<256; i++ ) byte_tab[i] = i;
271
 
    else
272
 
      for ( i=0; i<256; i++ )
273
 
             byte_tab[i] = ( ((i & 0x01) << 7) | ((i & 0x02) << 5) |
274
 
                             ((i & 0x04) << 3) | ((i & 0x08) << 1) |
275
 
                             ((i & 0x10) >> 1) | ((i & 0x20) >> 3) |
276
 
                             ((i & 0x40) >> 5) | ((i & 0x80) >> 7) );
277
 
}