3
# Spca561decoder (C) 2005 Andrzej Szombierski [qq@kuku.eu.org]
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.
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.
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
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.
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
31
#include "libv4lconvert-priv.h"
33
/*fixme: not reentrant */
34
static unsigned int bit_bucket;
35
static const unsigned char *input_ptr;
37
static inline void refill(int *bitfill)
40
bit_bucket = (bit_bucket << 8) | *(input_ptr++);
45
static inline int nbits(int *bitfill, int n)
47
bit_bucket = (bit_bucket << 8) | *(input_ptr++);
49
return (bit_bucket >> (*bitfill & 0xff)) & ((1 << n) - 1);
52
static inline int _nbits(int *bitfill, int n)
55
return (bit_bucket >> (*bitfill & 0xff)) & ((1 << n) - 1);
58
static int fun_A(int *bitfill)
62
12, 13, 14, 15, 16, 17, 18, 19, -12, -13, -14, -15,
63
-16, -17, -18, -19, -19
66
ret = tab[nbits(bitfill, 4)];
71
static int fun_B(int *bitfill)
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,
78
19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30
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,
87
tmp = nbits(bitfill, 7) - 68;
91
return tab[tab1[tmp]];
93
static int fun_C(int *bitfill, int gkw)
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,
100
15, 16, 17, 18, 19, 20, 21, 22
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
109
if (nbits(bitfill, 1) == 0)
118
tmp = nbits(bitfill, 7) - 72;
123
return tab[tab1[tmp]];
125
static int fun_D(int *bitfill, int gkw)
128
if (nbits(bitfill, 1) == 0)
134
if (nbits(bitfill, 1) == 0)
140
switch (nbits(bitfill, 2)) {
153
switch (nbits(bitfill, 3)) {
163
return _nbits(bitfill, 1) ? 0xed : 0x12;
173
static int fun_E(int cur_byte, int *bitfill)
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 };
181
if ((cur_byte & 0xf0) >= 0x80) {
183
return tab0[(cur_byte >> 4) & 7];
185
if ((cur_byte & 0xc0) == 0x40) {
187
return tab1[(cur_byte >> 3) & 7];
190
if ((cur_byte & 0xe0) == 0x20) {
192
return tab2[(cur_byte >> 2) & 7];
195
if ((cur_byte & 0xf0) == 0x10) {
197
return tab3[(cur_byte >> 1) & 7];
200
if ((cur_byte & 0xf8) == 8) {
202
return tab4[cur_byte & 7];
207
static int fun_F(int cur_byte, int *bitfill)
210
switch (cur_byte & 0xf8) {
246
switch (cur_byte & 0xfc) {
282
switch (cur_byte & 0xfe) {
303
static int internal_spca561_decode(int width, int height,
304
const unsigned char *inbuf,
305
unsigned char *outbuf)
308
static int accum[8 * 8 * 8];
309
static int i_hits[8 * 8 * 8];
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,
316
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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,
322
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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,
328
7, 7, 7, 7, 7, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 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,
334
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 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,
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,
344
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
350
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
353
0, 0, 0, 0, 11, -11, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,
356
-4, -5, -5, -6, -6, -7, -7, -8, -8, -9, -9, -10, -10, -1,
359
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
362
-1, -1, -1, -1, -1, -1, -1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3,
365
-2, -2, -2, -2, -2, -2, -2, -2, -3, -3, -3, -3, -3, -3, -3,
368
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
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,
379
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2,
382
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 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,
388
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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,
394
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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,
400
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
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,
407
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
410
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
413
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
416
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
419
-1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 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,
425
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
431
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
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,
442
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3,
445
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 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,
451
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 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,
457
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 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,
463
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
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,
470
2, 2, 2, 2, 2, 2, 2, 2, 2, -3, -3, -3, -3, -3, -3, -3, -3,
473
-3, -3, -3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
476
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -2, -2, -2, -2, -2, -2, -2,
479
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
482
-2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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,
488
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1,
491
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
494
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
497
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
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,
506
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4,
509
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 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,
515
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 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,
521
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 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,
527
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
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,
534
4, 4, 4, 4, -5, -5, -5, -5, -5, -5, -5, -5, 5, 5, 5, 5, 5,
537
-6, -6, -6, -6, -6, -6, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
540
-3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3,
543
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, -4, -4, -4, -4, -4, -4, -4,
546
-4, -4, -4, -4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
549
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1,
552
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
555
-1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
558
1, 1, 1, 1, 1, 1, 1, 1, 1, -2, -2, -2, -2, -2, -2, -2, -2,
561
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
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,
572
72, 80, 88, 98, 112, 128, 144, 160
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,
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,
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,
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,
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,
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,
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,
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,
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,
603
28, 29, 30, 31, 32, 33,
604
34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
606
51, 52, 53, 54, 55, 56,
607
57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
609
74, 75, 76, 77, 78, 79,
610
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
612
97, 98, 99, 100, 101,
613
102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113,
615
115, 116, 117, 118, 119,
616
120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131,
618
133, 134, 135, 136, 137,
619
138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
621
151, 152, 153, 154, 155,
622
156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167,
624
169, 170, 171, 172, 173,
625
174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185,
627
187, 188, 189, 190, 191,
628
192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203,
630
205, 206, 207, 208, 209,
631
210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221,
633
223, 224, 225, 226, 227,
634
228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
636
241, 242, 243, 244, 245,
637
246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 255, 255,
639
255, 255, 255, 255, 255,
640
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
642
255, 255, 255, 255, 255,
643
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
645
255, 255, 255, 255, 255,
646
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
648
255, 255, 255, 255, 255,
649
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
651
255, 255, 255, 255, 255,
652
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
654
255, 255, 255, 255, 255,
655
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
657
255, 255, 255, 255, 255,
658
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
660
255, 255, 255, 255, 255,
661
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
663
255, 255, 255, 255, 255,
664
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
666
255, 255, 255, 255, 255,
667
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
669
255, 255, 255, 255, 255,
670
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
672
255, 255, 255, 255, 255,
673
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
675
255, 255, 255, 255, 255,
676
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
678
255, 255, 255, 255, 255,
679
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
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,
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,
696
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 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,
702
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 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,
708
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 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,
714
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 5, 5, 5, 5, 5, 5, 5,
717
3, 3, 1, 1, 0, 2, 2, 4, 4, 4, 4, 6, 6, 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,
723
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 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,
729
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 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,
735
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 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,
741
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
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;
755
memset(i_hits, 0, sizeof(i_hits));
756
memset(accum, 0, sizeof(accum));
758
memcpy(outbuf + xwidth * 2 + 3, inbuf + 0x14, width);
759
memcpy(outbuf + xwidth * 3 + 3, inbuf + 0x14 + width, width);
761
input_ptr = inbuf + 0x14 + width * 2;
762
output_ptr = outbuf + (xwidth) * 4 + 3;
766
for (block = 0; block < ((height - 2) * width) / 32; ++block) {
772
cur_byte = (bit_bucket >> (bitfill & 7)) & 0xff;
774
if ((cur_byte & 0x80) == 0) {
777
} else if ((cur_byte & 0xC0) == 0x80) {
780
} else if ((cur_byte & 0xc0) == 0xc0) {
785
for (b_it = 0; b_it < 32; b_it++) {
787
int pixel_L, pixel_UR, pixel_UL;
790
int gkw; /* God knows what */
793
cur_byte = bit_bucket >> (bitfill & 7) & 0xff;
795
pixel_L = output_ptr[-2];
796
pixel_UR = output_ptr[off_up_right];
797
pixel_UL = output_ptr[off_up_left];
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];
804
pixel_L = pixel_UL = pixel_U =
805
output_ptr[-xwidth * 2];
806
pixel_UR = output_ptr[off_up_right];
808
dR = diff_encoding[0x100 + pixel_UR -
810
} else if (pixel_x > width - 3)
814
index = dR + dC * 8 + dL * 64;
816
if (pixel_L + pixel_U * 2 <= 144
817
&& (pixel_y & 1) == 0
818
&& (b_it & 3) == 0 && (dR < 5) && (dC < 5)
821
} else if (pixel_L <= 48
822
&& dL <= 4 && dC <= 4 && dL >= 1
825
} else if (var_7 == 1) {
827
} else if (dC + dL >= 11 || var_7 == 2) {
831
if (i_hits[index] < 7) {
832
bitfill -= nbits_A[cur_byte];
833
gkw = tab_A[cur_byte];
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];
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];
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];
850
gkw = fun_D(&bitfill, gkw);
851
} else if (i_hits[index] * 8 >= accum[index]) {
852
gkw = fun_E(cur_byte, &bitfill);
854
gkw = fun_F(cur_byte, &bitfill);
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;
870
clamp0_255[0x100 + (tmp1 >> 2) -
873
pixel_U = saved_pixel_UR;
874
saved_pixel_UR = pixel_UR;
876
if (++pixel_x == width) {
882
accum[index] += abs_clamp15[19 + gkw];
884
if (i_hits[index]++ == 15) {
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)
899
static unsigned char tmpbuf[650 * 490];
900
if (internal_spca561_decode(width, height, inbuf, tmpbuf) != 0)
902
for (i = 0; i < height; i++)
903
memcpy(outbuf + i * width,
904
tmpbuf + (i + 2) * (width + 6) + 3, width);
907
/*************** License Change Permission Notice ***************
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>)
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>)
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>
935
Content-Type: TEXT/PLAIN; charset=iso-8859-2
936
Content-Transfer-Encoding: QUOTED-PRINTABLE
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
945
On Mon, 16 Jun 2008, Hans de Goede wrote:
949
> I don't know if you're still subscribed to the spca devel mailing list, s=
951
> me start with a short intro.
953
> I'm a Linux enthusiast / developer currently helping Jean-Fran=E7ois Moin=
955
> porting gspca to video4linux2 and cleaning up the code to get it ready fo=
957
> mainline kernel inclusion.
959
> As part of this process the decompression code for all supported cams mus=
961
> moved to userspace, as doing in kernel decompression is considered unwant=
963
> the mainline people (I agree) as it should be done in userspace.
968
> As such I'm working on a library which does decompression of custom cam f=
973
Nice. I hope that the library won't be limited to spca-supported webcams,=
975
and as an application developer I would be able to just request RGB data=20
976
from any /dev/video*, right?
978
> I do not want to license this library as GPL (as the current spca code is=
980
> it should be usable by as much software as possible. Instead I want to li=
982
> it under the LGPL version 2.1 or later.
984
Also sounds reasonable.
987
> So my question us my I have your permission to relicense your spca561=20
988
> decompression code under the LGPL?
1000
:: Andrzej Szombierski :: qq@kuku.eu.org :: http://kuku.eu.org ::
1001
:: anszom@bezkitu.com :: radio bez kitu :: http://bezkitu.com ::