~ubuntu-branches/ubuntu/precise/v4l-utils/precise

« back to all changes in this revision

Viewing changes to lib/libv4lconvert/spca561-decompress.c

  • Committer: Bazaar Package Importer
  • Author(s): Gregor Jasny
  • Date: 2010-02-28 19:44:15 UTC
  • Revision ID: james.westby@ubuntu.com-20100228194415-067hdj8rvawj91zw
Tags: upstream-0.7.90
ImportĀ upstreamĀ versionĀ 0.7.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 
 
3
# Spca561decoder (C) 2005 Andrzej Szombierski [qq@kuku.eu.org]
 
4
 
 
5
# This program is free software; you can redistribute it and/or modify
 
6
# it under the terms of the GNU Lesser General Public License as published by
 
7
# the Free Software Foundation; either version 2.1 of the License, or
 
8
# (at your option) any later version.
 
9
#
 
10
# This program is distributed in the hope that it will be useful,
 
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
# GNU Lesser General Public License for more details.
 
14
#
 
15
# You should have received a copy of the GNU Lesser General Public License
 
16
# along with this program; if not, write to the Free Software
 
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 
 
19
# Note this code was originally licensed under the GNU GPL instead of the
 
20
# GNU LGPL, its license has been changed with permission, see the permission
 
21
# mail at the end of this file.
 
22
 
 
23
*/
 
24
 
 
25
/*
 
26
 *      Decoder for compressed spca561 images
 
27
 *      It was developed for "Labtec WebCam Elch 2(SPCA561A)" (046d:0929)
 
28
 *      but it might work with other spca561 cameras
 
29
 */
 
30
#include <string.h>
 
31
#include "libv4lconvert-priv.h"
 
32
 
 
33
/*fixme: not reentrant */
 
34
static unsigned int bit_bucket;
 
35
static const unsigned char *input_ptr;
 
36
 
 
37
static inline void refill(int *bitfill)
 
38
{
 
39
        if (*bitfill < 8) {
 
40
                bit_bucket = (bit_bucket << 8) | *(input_ptr++);
 
41
                *bitfill += 8;
 
42
        }
 
43
}
 
44
 
 
45
static inline int nbits(int *bitfill, int n)
 
46
{
 
47
        bit_bucket = (bit_bucket << 8) | *(input_ptr++);
 
48
        *bitfill -= n;
 
49
        return (bit_bucket >> (*bitfill & 0xff)) & ((1 << n) - 1);
 
50
}
 
51
 
 
52
static inline int _nbits(int *bitfill, int n)
 
53
{
 
54
        *bitfill -= n;
 
55
        return (bit_bucket >> (*bitfill & 0xff)) & ((1 << n) - 1);
 
56
}
 
57
 
 
58
static int fun_A(int *bitfill)
 
59
{
 
60
        int ret;
 
61
        static int tab[] = {
 
62
                12, 13, 14, 15, 16, 17, 18, 19, -12, -13, -14, -15,
 
63
                -16, -17, -18, -19, -19
 
64
        };
 
65
 
 
66
        ret = tab[nbits(bitfill, 4)];
 
67
 
 
68
        refill(bitfill);
 
69
        return ret;
 
70
}
 
71
static int fun_B(int *bitfill)
 
72
{
 
73
        static int tab1[] =
 
74
            { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 31, 31,
 
75
                31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
 
76
                    16, 17,
 
77
                18,
 
78
                19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30
 
79
        };
 
80
        static int tab[] =
 
81
            { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, -5,
 
82
                -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16, -17,
 
83
                    -18, -19
 
84
        };
 
85
        unsigned int tmp;
 
86
 
 
87
        tmp = nbits(bitfill, 7) - 68;
 
88
        refill(bitfill);
 
89
        if (tmp > 47)
 
90
                return 0xff;
 
91
        return tab[tab1[tmp]];
 
92
}
 
93
static int fun_C(int *bitfill, int gkw)
 
94
{
 
95
        static int tab1[] =
 
96
            { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 23, 23, 23, 23, 23, 23,
 
97
                23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
 
98
                    12, 13,
 
99
                14,
 
100
                15, 16, 17, 18, 19, 20, 21, 22
 
101
        };
 
102
        static int tab[] =
 
103
            { 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, -9, -10, -11,
 
104
                -12, -13, -14, -15, -16, -17, -18, -19
 
105
        };
 
106
        unsigned int tmp;
 
107
 
 
108
        if (gkw == 0xfe) {
 
109
                if (nbits(bitfill, 1) == 0)
 
110
                        return 7;
 
111
                else
 
112
                        return -8;
 
113
        }
 
114
 
 
115
        if (gkw != 0xff)
 
116
                return 0xff;
 
117
 
 
118
        tmp = nbits(bitfill, 7) - 72;
 
119
        if (tmp > 43)
 
120
                return 0xff;
 
121
 
 
122
        refill(bitfill);
 
123
        return tab[tab1[tmp]];
 
124
}
 
125
static int fun_D(int *bitfill, int gkw)
 
126
{
 
127
        if (gkw == 0xfd) {
 
128
                if (nbits(bitfill, 1) == 0)
 
129
                        return 12;
 
130
                return -13;
 
131
        }
 
132
 
 
133
        if (gkw == 0xfc) {
 
134
                if (nbits(bitfill, 1) == 0)
 
135
                        return 13;
 
136
                return -14;
 
137
        }
 
138
 
 
139
        if (gkw == 0xfe) {
 
140
                switch (nbits(bitfill, 2)) {
 
141
                case 0:
 
142
                        return 14;
 
143
                case 1:
 
144
                        return -15;
 
145
                case 2:
 
146
                        return 15;
 
147
                case 3:
 
148
                        return -16;
 
149
                }
 
150
        }
 
151
 
 
152
        if (gkw == 0xff) {
 
153
                switch (nbits(bitfill, 3)) {
 
154
                case 4:
 
155
                        return 16;
 
156
                case 5:
 
157
                        return -17;
 
158
                case 6:
 
159
                        return 17;
 
160
                case 7:
 
161
                        return -18;
 
162
                case 2:
 
163
                        return _nbits(bitfill, 1) ? 0xed : 0x12;
 
164
                case 3:
 
165
                        (*bitfill)--;
 
166
                        return 18;
 
167
                }
 
168
                return 0xff;
 
169
        }
 
170
        return gkw;
 
171
}
 
172
 
 
173
static int fun_E(int cur_byte, int *bitfill)
 
174
{
 
175
        static int tab0[] = { 0, -1, 1, -2, 2, -3, 3, -4 };
 
176
        static int tab1[] = { 4, -5, 5, -6, 6, -7, 7, -8 };
 
177
        static int tab2[] = { 8, -9, 9, -10, 10, -11, 11, -12 };
 
178
        static int tab3[] = { 12, -13, 13, -14, 14, -15, 15, -16 };
 
179
        static int tab4[] = { 16, -17, 17, -18, 18, -19, 19, -19 };
 
180
 
 
181
        if ((cur_byte & 0xf0) >= 0x80) {
 
182
                *bitfill -= 4;
 
183
                return tab0[(cur_byte >> 4) & 7];
 
184
        }
 
185
        if ((cur_byte & 0xc0) == 0x40) {
 
186
                *bitfill -= 5;
 
187
                return tab1[(cur_byte >> 3) & 7];
 
188
 
 
189
        }
 
190
        if ((cur_byte & 0xe0) == 0x20) {
 
191
                *bitfill -= 6;
 
192
                return tab2[(cur_byte >> 2) & 7];
 
193
 
 
194
        }
 
195
        if ((cur_byte & 0xf0) == 0x10) {
 
196
                *bitfill -= 7;
 
197
                return tab3[(cur_byte >> 1) & 7];
 
198
 
 
199
        }
 
200
        if ((cur_byte & 0xf8) == 8) {
 
201
                *bitfill -= 8;
 
202
                return tab4[cur_byte & 7];
 
203
        }
 
204
        return 0xff;
 
205
}
 
206
 
 
207
static int fun_F(int cur_byte, int *bitfill)
 
208
{
 
209
        *bitfill -= 5;
 
210
        switch (cur_byte & 0xf8) {
 
211
        case 0x80:
 
212
                return 0;
 
213
        case 0x88:
 
214
                return -1;
 
215
        case 0x90:
 
216
                return 1;
 
217
        case 0x98:
 
218
                return -2;
 
219
        case 0xa0:
 
220
                return 2;
 
221
        case 0xa8:
 
222
                return -3;
 
223
        case 0xb0:
 
224
                return 3;
 
225
        case 0xb8:
 
226
                return -4;
 
227
        case 0xc0:
 
228
                return 4;
 
229
        case 0xc8:
 
230
                return -5;
 
231
        case 0xd0:
 
232
                return 5;
 
233
        case 0xd8:
 
234
                return -6;
 
235
        case 0xe0:
 
236
                return 6;
 
237
        case 0xe8:
 
238
                return -7;
 
239
        case 0xf0:
 
240
                return 7;
 
241
        case 0xf8:
 
242
                return -8;
 
243
        }
 
244
 
 
245
        *bitfill -= 1;
 
246
        switch (cur_byte & 0xfc) {
 
247
        case 0x40:
 
248
                return 8;
 
249
        case 0x44:
 
250
                return -9;
 
251
        case 0x48:
 
252
                return 9;
 
253
        case 0x4c:
 
254
                return -10;
 
255
        case 0x50:
 
256
                return 10;
 
257
        case 0x54:
 
258
                return -11;
 
259
        case 0x58:
 
260
                return 11;
 
261
        case 0x5c:
 
262
                return -12;
 
263
        case 0x60:
 
264
                return 12;
 
265
        case 0x64:
 
266
                return -13;
 
267
        case 0x68:
 
268
                return 13;
 
269
        case 0x6c:
 
270
                return -14;
 
271
        case 0x70:
 
272
                return 14;
 
273
        case 0x74:
 
274
                return -15;
 
275
        case 0x78:
 
276
                return 15;
 
277
        case 0x7c:
 
278
                return -16;
 
279
        }
 
280
 
 
281
        *bitfill -= 1;
 
282
        switch (cur_byte & 0xfe) {
 
283
        case 0x20:
 
284
                return 16;
 
285
        case 0x22:
 
286
                return -17;
 
287
        case 0x24:
 
288
                return 17;
 
289
        case 0x26:
 
290
                return -18;
 
291
        case 0x28:
 
292
                return 18;
 
293
        case 0x2a:
 
294
                return -19;
 
295
        case 0x2c:
 
296
                return 19;
 
297
        }
 
298
 
 
299
        *bitfill += 7;
 
300
        return 0xff;
 
301
}
 
302
 
 
303
static int internal_spca561_decode(int width, int height,
 
304
                                   const unsigned char *inbuf,
 
305
                                   unsigned char *outbuf)
 
306
{
 
307
        /* buffers */
 
308
        static int accum[8 * 8 * 8];
 
309
        static int i_hits[8 * 8 * 8];
 
310
 
 
311
        static const int nbits_A[] =
 
312
            { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 
313
                1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 
314
                    1, 1,
 
315
                1, 1, 1, 1, 1,
 
316
                1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 
317
                    1, 1,
 
318
                1, 1, 1, 1, 1,
 
319
                1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 
320
                    1, 1,
 
321
                1, 1, 1, 1, 1,
 
322
                1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 
323
                    1, 1,
 
324
                1, 1, 1, 1, 1,
 
325
                8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 0, 0, 7, 7,
 
326
                    7, 7,
 
327
                7, 7, 7, 7, 7,
 
328
                7, 7, 7, 7, 7, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
 
329
                    3, 3,
 
330
                3, 3, 3, 3, 3,
 
331
                3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
 
332
                    5, 5,
 
333
                5, 5, 5, 5, 5,
 
334
                5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 3, 3, 3, 3, 3,
 
335
                    3, 3,
 
336
                3, 3, 3, 3, 3,
 
337
                3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
 
338
        };
 
339
        static const int tab_A[] =
 
340
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
341
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
342
                    0, 0,
 
343
                0, 0, 0, 0,
 
344
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
345
                    0, 0,
 
346
                0, 0, 0, 0,
 
347
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
348
                    0, 0,
 
349
                0, 0, 0, 0,
 
350
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
351
                    0, 0,
 
352
                0, 0, 0, 0,
 
353
                0, 0, 0, 0, 11, -11, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,
 
354
                    10, 10,
 
355
                255, 254, -4,
 
356
                -4, -5, -5, -6, -6, -7, -7, -8, -8, -9, -9, -10, -10, -1,
 
357
                    -1, -1,
 
358
                -1, -1, -1,
 
359
                -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
 
360
                    -1, -1,
 
361
                -1, -1,
 
362
                -1, -1, -1, -1, -1, -1, -1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3,
 
363
                    3, 3, 3,
 
364
                3, 3, 3,
 
365
                -2, -2, -2, -2, -2, -2, -2, -2, -3, -3, -3, -3, -3, -3, -3,
 
366
                    -3, 1,
 
367
                1, 1, 1, 1,
 
368
                1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 
369
                    1, 1,
 
370
                1, 1, 1, 1,
 
371
                1
 
372
        };
 
373
 
 
374
        static const int nbits_B[] =
 
375
            { 0, 8, 7, 7, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4,
 
376
                4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3,
 
377
                    3, 3,
 
378
                3, 3, 3, 3, 3,
 
379
                3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2,
 
380
                    2, 2,
 
381
                2, 2, 2, 2, 2,
 
382
                2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
 
383
                    2, 2,
 
384
                2, 2, 2, 2, 2,
 
385
                2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
 
386
                    2, 2,
 
387
                2, 2, 2, 2, 2,
 
388
                1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 
389
                    1, 1,
 
390
                1, 1, 1, 1, 1,
 
391
                1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 
392
                    1, 1,
 
393
                1, 1, 1, 1, 1,
 
394
                1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 
395
                    1, 1,
 
396
                1, 1, 1, 1, 1,
 
397
                1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 
398
                    1, 1,
 
399
                1, 1, 1, 1, 1,
 
400
                1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 
401
        };
 
402
        static const int tab_B[] =
 
403
            { 0xff, -4, 3, 3, -3, -3, -3, -3, 2, 2, 2, 2, 2, 2, 2, 2, -2,
 
404
                -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
 
405
                    1, 1,
 
406
                1, 1, 1, 1,
 
407
                1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 
408
                    1, 1,
 
409
                1, 1, 1, 1,
 
410
                -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
 
411
                    -1, -1,
 
412
                -1, -1,
 
413
                -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
 
414
                    -1, -1,
 
415
                -1, -1,
 
416
                -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
 
417
                    -1, -1,
 
418
                -1, -1,
 
419
                -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
420
                    0, 0, 0,
 
421
                0, 0, 0, 0,
 
422
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
423
                    0, 0,
 
424
                0, 0, 0, 0,
 
425
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
426
                    0, 0,
 
427
                0, 0, 0, 0,
 
428
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
429
                    0, 0,
 
430
                0, 0, 0, 0,
 
431
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
432
                    0, 0,
 
433
                0, 0, 0, 0,
 
434
                0, 0, 0, 0, 0, 0, 0,
 
435
        };
 
436
 
 
437
        static const int nbits_C[] =
 
438
            { 0, 0, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5,
 
439
                5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
 
440
                    4, 4,
 
441
                4, 4, 4, 4, 4,
 
442
                4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3,
 
443
                    3, 3,
 
444
                3, 3, 3, 3, 3,
 
445
                3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
 
446
                    3, 3,
 
447
                3, 3, 3, 3, 3,
 
448
                3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
 
449
                    3, 3,
 
450
                3, 3, 3, 3, 3,
 
451
                2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
 
452
                    2, 2,
 
453
                2, 2, 2, 2, 2,
 
454
                2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
 
455
                    2, 2,
 
456
                2, 2, 2, 2, 2,
 
457
                2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
 
458
                    2, 2,
 
459
                2, 2, 2, 2, 2,
 
460
                2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
 
461
                    2, 2,
 
462
                2, 2, 2, 2, 2,
 
463
                2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
 
464
        };
 
465
        static const int tab_C[] =
 
466
            { 0xff, 0xfe, 6, -7, 5, 5, -6, -6, 4, 4, 4, 4, -5, -5, -5, -5,
 
467
                3, 3, 3, 3, 3, 3, 3, 3, -4, -4, -4, -4, -4, -4, -4, -4, 2,
 
468
                    2, 2, 2,
 
469
                2, 2, 2,
 
470
                2, 2, 2, 2, 2, 2, 2, 2, 2, -3, -3, -3, -3, -3, -3, -3, -3,
 
471
                    -3, -3,
 
472
                -3, -3, -3,
 
473
                -3, -3, -3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 
474
                    1, 1,
 
475
                1, 1, 1, 1,
 
476
                1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -2, -2, -2, -2, -2, -2, -2,
 
477
                    -2, -2,
 
478
                -2, -2, -2,
 
479
                -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
 
480
                    -2, -2,
 
481
                -2, -2,
 
482
                -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
483
                    0, 0, 0,
 
484
                0, 0, 0, 0,
 
485
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
486
                    0, 0,
 
487
                0, 0, 0, 0,
 
488
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1,
 
489
                    -1, -1,
 
490
                -1, -1, -1,
 
491
                -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
 
492
                    -1, -1,
 
493
                -1, -1,
 
494
                -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
 
495
                    -1, -1,
 
496
                -1, -1,
 
497
                -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
 
498
                    -1,
 
499
        };
 
500
 
 
501
        static const int nbits_D[] =
 
502
            { 0, 0, 0, 0, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6,
 
503
                6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5,
 
504
                    5, 5,
 
505
                5, 5, 5, 5, 5,
 
506
                5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4,
 
507
                    4, 4,
 
508
                4, 4, 4, 4, 4,
 
509
                4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
 
510
                    4, 4,
 
511
                4, 4, 4, 4, 4,
 
512
                4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
 
513
                    4, 4,
 
514
                4, 4, 4, 4, 4,
 
515
                3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
 
516
                    3, 3,
 
517
                3, 3, 3, 3, 3,
 
518
                3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
 
519
                    3, 3,
 
520
                3, 3, 3, 3, 3,
 
521
                3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
 
522
                    3, 3,
 
523
                3, 3, 3, 3, 3,
 
524
                3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
 
525
                    3, 3,
 
526
                3, 3, 3, 3, 3,
 
527
                3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
 
528
        };
 
529
        static const int tab_D[] =
 
530
            { 0xff, 0xfe, 0xfd, 0xfc, 10, -11, 11, -12, 8, 8, -9, -9, 9, 9,
 
531
                -10, -10, 6, 6, 6, 6, -7, -7, -7, -7, 7, 7, 7, 7, -8, -8,
 
532
                    -8, -8,
 
533
                4, 4, 4, 4,
 
534
                4, 4, 4, 4, -5, -5, -5, -5, -5, -5, -5, -5, 5, 5, 5, 5, 5,
 
535
                    5, 5, 5,
 
536
                -6, -6,
 
537
                -6, -6, -6, -6, -6, -6, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
 
538
                    2, 2,
 
539
                2, 2, -3,
 
540
                -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3,
 
541
                    3, 3,
 
542
                3, 3, 3, 3,
 
543
                3, 3, 3, 3, 3, 3, 3, 3, 3, 3, -4, -4, -4, -4, -4, -4, -4,
 
544
                    -4, -4,
 
545
                -4, -4, -4,
 
546
                -4, -4, -4, -4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
547
                    0, 0, 0,
 
548
                0, 0, 0, 0,
 
549
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1,
 
550
                    -1, -1,
 
551
                -1, -1, -1,
 
552
                -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
 
553
                    -1, -1,
 
554
                -1, -1,
 
555
                -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 
556
                    1, 1, 1,
 
557
                1, 1, 1,
 
558
                1, 1, 1, 1, 1, 1, 1, 1, 1, -2, -2, -2, -2, -2, -2, -2, -2,
 
559
                    -2, -2,
 
560
                -2, -2, -2,
 
561
                -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
 
562
                    -2, -2,
 
563
                -2, -2
 
564
        };
 
565
 
 
566
        /* a_curve[19 + i] = ... [-19..19] => [-160..160] */
 
567
        static const int a_curve[] =
 
568
            { -160, -144, -128, -112, -98, -88, -80, -72, -64, -56, -48,
 
569
                -40, -32, -24, -18, -12, -8, -5, -2, 0, 2, 5, 8, 12, 18,
 
570
                    24, 32,
 
571
                40, 48, 56, 64,
 
572
                72, 80, 88, 98, 112, 128, 144, 160
 
573
        };
 
574
        /* clamp0_255[256 + i] = min(max(i,255),0) */
 
575
        static const unsigned char clamp0_255[] =
 
576
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
577
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
578
                    0, 0,
 
579
                0, 0, 0, 0, 0, 0, 0, 0, 0,
 
580
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
581
                    0, 0,
 
582
                0, 0, 0, 0, 0, 0, 0, 0, 0,
 
583
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
584
                    0, 0,
 
585
                0, 0, 0, 0, 0, 0, 0, 0, 0,
 
586
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
587
                    0, 0,
 
588
                0, 0, 0, 0, 0, 0, 0, 0, 0,
 
589
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
590
                    0, 0,
 
591
                0, 0, 0, 0, 0, 0, 0, 0, 0,
 
592
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
593
                    0, 0,
 
594
                0, 0, 0, 0, 0, 0, 0, 0, 0,
 
595
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
596
                    0, 0,
 
597
                0, 0, 0, 0, 0, 0, 0, 0, 0,
 
598
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
599
                    1, 2,
 
600
                3, 4, 5, 6, 7, 8, 9, 10,
 
601
                11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
 
602
                    26, 27,
 
603
                28, 29, 30, 31, 32, 33,
 
604
                34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
 
605
                    49, 50,
 
606
                51, 52, 53, 54, 55, 56,
 
607
                57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
 
608
                    72, 73,
 
609
                74, 75, 76, 77, 78, 79,
 
610
                80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
 
611
                    95, 96,
 
612
                97, 98, 99, 100, 101,
 
613
                102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113,
 
614
                    114,
 
615
                115, 116, 117, 118, 119,
 
616
                120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131,
 
617
                    132,
 
618
                133, 134, 135, 136, 137,
 
619
                138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
 
620
                    150,
 
621
                151, 152, 153, 154, 155,
 
622
                156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167,
 
623
                    168,
 
624
                169, 170, 171, 172, 173,
 
625
                174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185,
 
626
                    186,
 
627
                187, 188, 189, 190, 191,
 
628
                192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203,
 
629
                    204,
 
630
                205, 206, 207, 208, 209,
 
631
                210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221,
 
632
                    222,
 
633
                223, 224, 225, 226, 227,
 
634
                228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
 
635
                    240,
 
636
                241, 242, 243, 244, 245,
 
637
                246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 255, 255,
 
638
                    255,
 
639
                255, 255, 255, 255, 255,
 
640
                255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
 
641
                    255,
 
642
                255, 255, 255, 255, 255,
 
643
                255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
 
644
                    255,
 
645
                255, 255, 255, 255, 255,
 
646
                255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
 
647
                    255,
 
648
                255, 255, 255, 255, 255,
 
649
                255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
 
650
                    255,
 
651
                255, 255, 255, 255, 255,
 
652
                255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
 
653
                    255,
 
654
                255, 255, 255, 255, 255,
 
655
                255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
 
656
                    255,
 
657
                255, 255, 255, 255, 255,
 
658
                255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
 
659
                    255,
 
660
                255, 255, 255, 255, 255,
 
661
                255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
 
662
                    255,
 
663
                255, 255, 255, 255, 255,
 
664
                255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
 
665
                    255,
 
666
                255, 255, 255, 255, 255,
 
667
                255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
 
668
                    255,
 
669
                255, 255, 255, 255, 255,
 
670
                255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
 
671
                    255,
 
672
                255, 255, 255, 255, 255,
 
673
                255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
 
674
                    255,
 
675
                255, 255, 255, 255, 255,
 
676
                255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
 
677
                    255,
 
678
                255, 255, 255, 255, 255,
 
679
                255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
 
680
                    255,
 
681
                255
 
682
        };
 
683
        /* abs_clamp15[19 + i] = min(abs(i), 15) */
 
684
        static const int abs_clamp15[] =
 
685
            { 15, 15, 15, 15, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3,
 
686
                2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
 
687
                    15, 15,
 
688
                15
 
689
        };
 
690
        /* diff_encoding[256 + i] = ... */
 
691
        static const int diff_encoding[] =
 
692
            { 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
 
693
                7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
 
694
                    7, 7,
 
695
                7, 7, 7, 7, 7, 7, 7,
 
696
                7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
 
697
                    7, 7,
 
698
                7, 7, 7, 7, 7, 7, 7,
 
699
                7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
 
700
                    7, 7,
 
701
                7, 7, 7, 7, 7, 7, 7,
 
702
                7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
 
703
                    7, 7,
 
704
                7, 7, 7, 7, 7, 7, 7,
 
705
                7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
 
706
                    7, 7,
 
707
                7, 7, 7, 7, 7, 7, 7,
 
708
                7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
 
709
                    7, 7,
 
710
                7, 7, 7, 7, 7, 7, 7,
 
711
                7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
 
712
                    7, 7,
 
713
                7, 7, 7, 7, 7, 7, 7,
 
714
                7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 5, 5, 5, 5, 5, 5, 5,
 
715
                    5, 5,
 
716
                5, 5, 5, 5, 5, 3, 3,
 
717
                3, 3, 1, 1, 0, 2, 2, 4, 4, 4, 4, 6, 6, 6, 6, 6, 6, 6, 6, 6,
 
718
                    6, 6,
 
719
                6, 6, 6, 6, 6, 6, 6,
 
720
                6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
 
721
                    6, 6,
 
722
                6, 6, 6, 6, 6, 6, 6,
 
723
                6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
 
724
                    6, 6,
 
725
                6, 6, 6, 6, 6, 6, 6,
 
726
                6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
 
727
                    6, 6,
 
728
                6, 6, 6, 6, 6, 6, 6,
 
729
                6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
 
730
                    6, 6,
 
731
                6, 6, 6, 6, 6, 6, 6,
 
732
                6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
 
733
                    6, 6,
 
734
                6, 6, 6, 6, 6, 6, 6,
 
735
                6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
 
736
                    6, 6,
 
737
                6, 6, 6, 6, 6, 6, 6,
 
738
                6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
 
739
                    6, 6,
 
740
                6, 6, 6, 6, 6, 6, 6,
 
741
                6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
 
742
                    6, 6,
 
743
                6, 6, 6, 6, 6, 6
 
744
        };
 
745
 
 
746
        int block;
 
747
        int bitfill = 0;
 
748
        int xwidth = width + 6;
 
749
        int off_up_right = 2 - 2 * xwidth;
 
750
        int off_up_left = -2 - 2 * xwidth;
 
751
        int pixel_U = 0, saved_pixel_UR = 0;
 
752
        int pixel_x = 0, pixel_y = 2;
 
753
        unsigned char *output_ptr = outbuf;
 
754
 
 
755
        memset(i_hits, 0, sizeof(i_hits));
 
756
        memset(accum, 0, sizeof(accum));
 
757
 
 
758
        memcpy(outbuf + xwidth * 2 + 3, inbuf + 0x14, width);
 
759
        memcpy(outbuf + xwidth * 3 + 3, inbuf + 0x14 + width, width);
 
760
 
 
761
        input_ptr = inbuf + 0x14 + width * 2;
 
762
        output_ptr = outbuf + (xwidth) * 4 + 3;
 
763
 
 
764
        bit_bucket = 0;
 
765
 
 
766
        for (block = 0; block < ((height - 2) * width) / 32; ++block) {
 
767
                int b_it, var_7 = 0;
 
768
                int cur_byte;
 
769
 
 
770
                refill(&bitfill);
 
771
 
 
772
                cur_byte = (bit_bucket >> (bitfill & 7)) & 0xff;
 
773
 
 
774
                if ((cur_byte & 0x80) == 0) {
 
775
                        var_7 = 0;
 
776
                        bitfill--;
 
777
                } else if ((cur_byte & 0xC0) == 0x80) {
 
778
                        var_7 = 1;
 
779
                        bitfill -= 2;
 
780
                } else if ((cur_byte & 0xc0) == 0xc0) {
 
781
                        var_7 = 2;
 
782
                        bitfill -= 2;
 
783
                }
 
784
 
 
785
                for (b_it = 0; b_it < 32; b_it++) {
 
786
                        int index;
 
787
                        int pixel_L, pixel_UR, pixel_UL;
 
788
                        int multiplier;
 
789
                        int dL, dC, dR;
 
790
                        int gkw;        /* God knows what */
 
791
 
 
792
                        refill(&bitfill);
 
793
                        cur_byte = bit_bucket >> (bitfill & 7) & 0xff;
 
794
 
 
795
                        pixel_L = output_ptr[-2];
 
796
                        pixel_UR = output_ptr[off_up_right];
 
797
                        pixel_UL = output_ptr[off_up_left];
 
798
 
 
799
                        dL = diff_encoding[0x100 + pixel_UL - pixel_L];
 
800
                        dC = diff_encoding[0x100 + pixel_U - pixel_UL];
 
801
                        dR = diff_encoding[0x100 + pixel_UR - pixel_U];
 
802
 
 
803
                        if (pixel_x < 2) {
 
804
                                pixel_L = pixel_UL = pixel_U =
 
805
                                    output_ptr[-xwidth * 2];
 
806
                                pixel_UR = output_ptr[off_up_right];
 
807
                                dL = dC = 0;
 
808
                                dR = diff_encoding[0x100 + pixel_UR -
 
809
                                                   pixel_U];
 
810
                        } else if (pixel_x > width - 3)
 
811
                                dR = 0;
 
812
 
 
813
                        multiplier = 4;
 
814
                        index = dR + dC * 8 + dL * 64;
 
815
 
 
816
                        if (pixel_L + pixel_U * 2 <= 144
 
817
                            && (pixel_y & 1) == 0
 
818
                            && (b_it & 3) == 0 && (dR < 5) && (dC < 5)
 
819
                            && (dL < 5)) {
 
820
                                multiplier = 1;
 
821
                        } else if (pixel_L <= 48
 
822
                                   && dL <= 4 && dC <= 4 && dL >= 1
 
823
                                   && dC >= 1) {
 
824
                                multiplier = 2;
 
825
                        } else if (var_7 == 1) {
 
826
                                multiplier = 2;
 
827
                        } else if (dC + dL >= 11 || var_7 == 2) {
 
828
                                multiplier = 8;
 
829
                        }
 
830
 
 
831
                        if (i_hits[index] < 7) {
 
832
                                bitfill -= nbits_A[cur_byte];
 
833
                                gkw = tab_A[cur_byte];
 
834
                                if (gkw == 0xfe)
 
835
                                        gkw = fun_A(&bitfill);
 
836
                        } else if (i_hits[index] >= accum[index]) {
 
837
                                bitfill -= nbits_B[cur_byte];
 
838
                                gkw = tab_B[cur_byte];
 
839
                                if (cur_byte == 0)
 
840
                                        gkw = fun_B(&bitfill);
 
841
                        } else if (i_hits[index] * 2 >= accum[index]) {
 
842
                                bitfill -= nbits_C[cur_byte];
 
843
                                gkw = tab_C[cur_byte];
 
844
                                if (cur_byte < 2)
 
845
                                        gkw = fun_C(&bitfill, gkw);
 
846
                        } else if (i_hits[index] * 4 >= accum[index]) {
 
847
                                bitfill -= nbits_D[cur_byte];
 
848
                                gkw = tab_D[cur_byte];
 
849
                                if (cur_byte < 4)
 
850
                                        gkw = fun_D(&bitfill, gkw);
 
851
                        } else if (i_hits[index] * 8 >= accum[index]) {
 
852
                                gkw = fun_E(cur_byte, &bitfill);
 
853
                        } else {
 
854
                                gkw = fun_F(cur_byte, &bitfill);
 
855
                        }
 
856
 
 
857
                        if (gkw == 0xff)
 
858
                                return -3;
 
859
 
 
860
                        {
 
861
                                int tmp1, tmp2;
 
862
 
 
863
                                tmp1 =
 
864
                                    (pixel_U + pixel_L) * 3 - pixel_UL * 2;
 
865
                                tmp1 += (tmp1 < 0) ? 3 : 0;
 
866
                                tmp2 = a_curve[19 + gkw] * multiplier;
 
867
                                tmp2 += (tmp2 < 0) ? 1 : 0;
 
868
 
 
869
                                *(output_ptr++) =
 
870
                                    clamp0_255[0x100 + (tmp1 >> 2) -
 
871
                                               (tmp2 >> 1)];
 
872
                        }
 
873
                        pixel_U = saved_pixel_UR;
 
874
                        saved_pixel_UR = pixel_UR;
 
875
 
 
876
                        if (++pixel_x == width) {
 
877
                                output_ptr += 6;
 
878
                                pixel_x = 0;
 
879
                                pixel_y++;
 
880
                        }
 
881
 
 
882
                        accum[index] += abs_clamp15[19 + gkw];
 
883
 
 
884
                        if (i_hits[index]++ == 15) {
 
885
                                i_hits[index] = 8;
 
886
                                accum[index] /= 2;
 
887
                        }
 
888
                }
 
889
        }
 
890
        return 0;
 
891
}
 
892
 
 
893
/* FIXME, change internal_spca561_decode not to need the extra border
 
894
   around its dest buffer */
 
895
void v4lconvert_decode_spca561(const unsigned char *inbuf,
 
896
  unsigned char *outbuf, int width, int height)
 
897
{
 
898
        int i;
 
899
        static unsigned char tmpbuf[650 * 490];
 
900
        if (internal_spca561_decode(width, height, inbuf, tmpbuf) != 0)
 
901
                return;
 
902
        for (i = 0; i < height; i++)
 
903
                memcpy(outbuf + i * width,
 
904
                       tmpbuf + (i + 2) * (width + 6) + 3, width);
 
905
}
 
906
 
 
907
/*************** License Change Permission Notice ***************
 
908
 
 
909
Return-Path: <qq@kuku.eu.org>
 
910
Received: from koko.hhs.nl ([145.52.2.16] verified)
 
911
  by hhs.nl (CommuniGate Pro SMTP 4.3.6)
 
912
  with ESMTP id 88574071 for j.w.r.degoede@hhs.nl; Mon, 16 Jun 2008 16:36:24 +0200
 
913
Received: from exim (helo=koko)
 
914
        by koko.hhs.nl with local-smtp (Exim 4.62)
 
915
        (envelope-from <qq@kuku.eu.org>)
 
916
        id 1K8Fom-0002iJ-3K
 
917
        for j.w.r.degoede@hhs.nl; Mon, 16 Jun 2008 16:36:24 +0200
 
918
Received: from [192.87.102.74] (port=41377 helo=filter6-ams.mf.surf.net)
 
919
        by koko.hhs.nl with esmtp (Exim 4.62)
 
920
        (envelope-from <qq@kuku.eu.org>)
 
921
        id 1K8Fol-0002iC-Qo
 
922
        for j.w.r.degoede@hhs.nl; Mon, 16 Jun 2008 16:36:23 +0200
 
923
Received: from kuku.eu.org (pa90.wielkopole.sdi.tpnet.pl [217.99.123.90])
 
924
        by filter6-ams.mf.surf.net (8.13.8/8.13.8/Debian-3) with ESMTP id m5GEa55r001787
 
925
        for <j.w.r.degoede@hhs.nl>; Mon, 16 Jun 2008 16:36:06 +0200
 
926
Received: (qmail 2243 invoked by uid 500); 16 Jun 2008 14:29:37 -0000
 
927
Date: Mon, 16 Jun 2008 16:29:37 +0200 (CEST)
 
928
From: Andrzej Szombierski <qq@kuku.eu.org>
 
929
To: Hans de Goede <j.w.r.degoede@hhs.nl>
 
930
Subject: Re: spca561 decoder license question
 
931
In-Reply-To: <485673B6.4050003@hhs.nl>
 
932
Message-ID: <Pine.LNX.4.44L.0806161614560.7665-100000@kuku.eu.org>
 
933
References: <485673B6.4050003@hhs.nl>
 
934
MIME-Version: 1.0
 
935
Content-Type: TEXT/PLAIN; charset=iso-8859-2
 
936
Content-Transfer-Encoding: QUOTED-PRINTABLE
 
937
X-Canit-CHI2: 0.00
 
938
X-Bayes-Prob: 0.0001 (Score 0, tokens from: @@RPTN)
 
939
X-Spam-Score: 2.00 (**) [Tag at 6.00] RBL(uceprotect-blacklist.surfnet.nl,2.0)
 
940
X-CanItPRO-Stream: hhs:j.w.r.degoede@hhs.nl (inherits from hhs:default,base:default)
 
941
X-Canit-Stats-ID: 85673281 - 37e52c8b07bc
 
942
X-Scanned-By: CanIt (www . roaringpenguin . com) on 192.87.102.74
 
943
X-Anti-Virus: Kaspersky Anti-Virus for MailServers 5.5.2/RELEASE, bases: 16062008 #776409, status: clean
 
944
 
 
945
On Mon, 16 Jun 2008, Hans de Goede wrote:
 
946
 
 
947
> Hi,
 
948
>=20
 
949
> I don't know if you're still subscribed to the spca devel mailing list, s=
 
950
o let=20
 
951
> me start with a short intro.
 
952
>
 
953
> I'm a Linux enthusiast / developer currently helping Jean-Fran=E7ois Moin=
 
954
e with=20
 
955
> porting gspca to video4linux2 and cleaning up the code to get it ready fo=
 
956
r=20
 
957
> mainline kernel inclusion.
 
958
>=20
 
959
> As part of this process the decompression code for all supported cams mus=
 
960
t be=20
 
961
> moved to userspace, as doing in kernel decompression is considered unwant=
 
962
ed by=20
 
963
> the mainline people (I agree) as it should be done in userspace.
 
964
>
 
965
 
 
966
Sounds reasonable.
 
967
=20
 
968
> As such I'm working on a library which does decompression of custom cam f=
 
969
ormats=20
 
970
> in userspace.
 
971
>
 
972
 
 
973
Nice. I hope that the library won't be limited to spca-supported webcams,=
 
974
=20
 
975
and as an application developer I would be able to just request RGB data=20
 
976
from any /dev/video*, right?
 
977
 
 
978
> I do not want to license this library as GPL (as the current spca code is=
 
979
), as=20
 
980
> it should be usable by as much software as possible. Instead I want to li=
 
981
cense=20
 
982
> it under the LGPL version 2.1 or later.
 
983
 
 
984
Also sounds reasonable.
 
985
 
 
986
>=20
 
987
> So my question us my I have your permission to relicense your spca561=20
 
988
> decompression code under the LGPL?
 
989
>=20
 
990
 
 
991
Yes, of course.=20
 
992
 
 
993
> Thanks & Regards,
 
994
>=20
 
995
> Hans
 
996
>=20
 
997
>
 
998
 
 
999
--=20
 
1000
:: Andrzej Szombierski :: qq@kuku.eu.org :: http://kuku.eu.org ::
 
1001
:: anszom@bezkitu.com  :: radio bez kitu :: http://bezkitu.com ::
 
1002
 
 
1003
*/