3
# Bertrik.Sikken. (C) 2005
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.
24
#include "libv4lconvert-priv.h"
26
#define CLAMP(x) ((x)<0?0:((x)>255)?255:(x))
37
/* FIXME not thread safe !! */
38
static code_table_t table[256];
39
static int init_done = 0;
44
pre-calculates a locally stored table for efficient huffman-decoding.
46
Each entry at index x in the table represents the codeword
47
present at the MSB of byte x.
50
static void sonix_decompress_init(void)
53
int is_abs, val, len, unk;
55
for (i = 0; i < 256; i++) {
60
if ((i & 0x80) == 0) {
65
else if ((i & 0xE0) == 0x80) {
70
else if ((i & 0xE0) == 0xA0) {
75
else if ((i & 0xF0) == 0xD0) {
80
else if ((i & 0xF0) == 0xF0) {
85
else if ((i & 0xF8) == 0xC8) {
90
else if ((i & 0xFC) == 0xC0) {
95
else if ((i & 0xFC) == 0xC4) {
96
/* code 110001xx: unknown */
101
else if ((i & 0xF0) == 0xE0) {
104
val = (i & 0x0F) << 4;
107
table[i].is_abs = is_abs;
120
decompresses an image encoded by a SN9C101 camera controller chip.
124
inp pointer to compressed frame (with header already stripped)
125
OUT outp pointer to decompressed frame
127
Returns 0 if the operation was successful.
128
Returns <0 if operation failed.
131
void v4lconvert_decode_sn9c10x(const unsigned char *inp, unsigned char *outp,
132
int width, int height)
138
const unsigned char *addr;
141
sonix_decompress_init();
144
for (row = 0; row < height; row++) {
148
/* first two pixels in first two rows are stored as raw 8-bit */
150
addr = inp + (bitpos >> 3);
151
code = (addr[0] << (bitpos & 7)) | (addr[1] >> (8 - (bitpos & 7)));
155
addr = inp + (bitpos >> 3);
156
code = (addr[0] << (bitpos & 7)) | (addr[1] >> (8 - (bitpos & 7)));
163
while (col < width) {
164
/* get bitcode from bitstream */
165
addr = inp + (bitpos >> 3);
166
code = (addr[0] << (bitpos & 7)) | (addr[1] >> (8 - (bitpos & 7)));
168
/* update bit position */
169
bitpos += table[code].len;
171
/* Skip unknown codes (most likely they indicate
172
a change of the delta's the various codes encode) */
176
/* calculate pixel value */
177
val = table[code].val;
178
if (!table[code].is_abs) {
179
/* value is relative to top and left pixel */
181
/* left column: relative to top pixel */
182
val += outp[-2*width];
185
/* top row: relative to left pixel */
189
/* main area: average of left pixel and top pixel */
190
val += (outp[-2] + outp[-2*width]) / 2;
195
*outp++ = CLAMP(val);
202
Return-Path: <bertrik@sikken.nl>
203
Received: from koko.hhs.nl ([145.52.2.16] verified)
204
by hhs.nl (CommuniGate Pro SMTP 4.3.6)
205
with ESMTP id 89132066 for j.w.r.degoede@hhs.nl; Thu, 03 Jul 2008 15:19:55 +0200
206
Received: from exim (helo=koko)
207
by koko.hhs.nl with local-smtp (Exim 4.62)
208
(envelope-from <bertrik@sikken.nl>)
210
for j.w.r.degoede@hhs.nl; Thu, 03 Jul 2008 15:19:55 +0200
211
Received: from [192.87.102.69] (port=33783 helo=filter1-ams.mf.surf.net)
212
by koko.hhs.nl with esmtp (Exim 4.62)
213
(envelope-from <bertrik@sikken.nl>)
215
for j.w.r.degoede@hhs.nl; Thu, 03 Jul 2008 15:19:55 +0200
216
Received: from cardassian.kabelfoon.nl (cardassian3.kabelfoon.nl [62.45.45.105])
217
by filter1-ams.mf.surf.net (8.13.8/8.13.8/Debian-3) with ESMTP id m63DJsKW032598
218
for <j.w.r.degoede@hhs.nl>; Thu, 3 Jul 2008 15:19:54 +0200
219
Received: from [192.168.1.1] (044-013-045-062.dynamic.caiway.nl [62.45.13.44])
220
by cardassian.kabelfoon.nl (Postfix) with ESMTP id 77761341D9A
221
for <j.w.r.degoede@hhs.nl>; Thu, 3 Jul 2008 15:19:54 +0200 (CEST)
222
Message-ID: <486CD1F9.8000307@sikken.nl>
223
Date: Thu, 03 Jul 2008 15:19:53 +0200
224
From: Bertrik Sikken <bertrik@sikken.nl>
225
User-Agent: Thunderbird 2.0.0.14 (Windows/20080421)
227
To: Hans de Goede <j.w.r.degoede@hhs.nl>
228
Subject: Re: pac207 bayer decompression algorithm license question
229
References: <48633F02.3040108@hhs.nl> <4863F611.80104@sikken.nl> <486CC6AF.7050509@hhs.nl>
230
In-Reply-To: <486CC6AF.7050509@hhs.nl>
231
X-Enigmail-Version: 0.95.6
232
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
233
Content-Transfer-Encoding: 7bit
235
X-Bayes-Prob: 0.0001 (Score 0, tokens from: @@RPTN)
236
X-Spam-Score: 0.00 () [Tag at 8.00]
237
X-CanItPRO-Stream: hhs:j.w.r.degoede@hhs.nl (inherits from hhs:default,base:default)
238
X-Canit-Stats-ID: 90943081 - 6a9ff19e8165
239
X-Scanned-By: CanIt (www . roaringpenguin . com) on 192.87.102.69
240
X-Anti-Virus: Kaspersky Anti-Virus for MailServers 5.5.2/RELEASE, bases: 03072008 #811719, status: clean
242
-----BEGIN PGP SIGNED MESSAGE-----
246
| Bertrik Sikken wrote:
249
|> Hans de Goede wrote:
250
|>> I would like to also add support for decompressing the pac207's
252
|>> bayer to this lib (and remove it from the kernel driver) and I've
253
|>> heard from Thomas Kaiser that you are a co-author of the
254
|>> decompression code. In order to add support for decompressing pac207
255
|>> compressed bayer to libv4l I need
256
|>> permission to relicense the decompression code under the LGPL
257
|>> (version 2 or later).
259
|>> Can you give me permission for this?
266
| I'm currently working on adding support for the sn9c10x bayer
267
| compression to libv4l too, and I noticed this was written by you too.
269
| May I have your permission to relicense the sn9c10x bayer decompression
270
| code under the LGPL (version 2 or later)?
272
I hereby grant you permission to relicense the sn9c10x bayer
273
decompression code under the LGPL (version 2 or later).
277
-----BEGIN PGP SIGNATURE-----
278
Version: GnuPG v1.4.7 (MingW32)
279
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
281
iD8DBQFIbNH5ETD6mlrWxPURAipvAJ9sv1ZpHyb81NMFejr6x0wqHX3i7QCfRDoB
282
jZi2e5lUjEh5KvS0dqXbi9I=
284
-----END PGP SIGNATURE-----