1 /* Linux driver for Philips webcam
2 Decompression frontend.
3 (C) 1999-2003 Nemosoft Unv. (webcam@smcc.demon.nl)
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 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 General Public License for more details.
15 You should have received a copy of the GNU 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
20 This is where the decompression routines register and unregister
21 themselves. It also has a decompressor wrapper function.
24 #include <asm/types.h>
27 #include "pwc-uncompress.h"
30 /* This contains a list of all registered decompressors */
31 static LIST_HEAD(pwc_decompressor_list);
33 /* Should the pwc_decompress structure ever change, we increase the
34 version number so that we don't get nasty surprises, or can
35 dynamically adjust our structure.
37 const int pwc_decompressor_version = PWC_MAJOR;
39 /* Add decompressor to list, ignoring duplicates */
40 void pwc_register_decompressor(struct pwc_decompressor *pwcd)
42 if (pwc_find_decompressor(pwcd->type) == NULL) {
43 Trace(TRACE_PWCX, "Adding decompressor for model %d.\n", pwcd->type);
44 list_add_tail(&pwcd->pwcd_list, &pwc_decompressor_list);
48 /* Remove decompressor from list */
49 void pwc_unregister_decompressor(int type)
51 struct pwc_decompressor *find;
53 find = pwc_find_decompressor(type);
55 Trace(TRACE_PWCX, "Removing decompressor for model %d.\n", type);
56 list_del(&find->pwcd_list);
60 /* Find decompressor in list */
61 struct pwc_decompressor *pwc_find_decompressor(int type)
63 struct list_head *tmp;
64 struct pwc_decompressor *pwcd;
66 list_for_each(tmp, &pwc_decompressor_list) {
67 pwcd = list_entry(tmp, struct pwc_decompressor, pwcd_list);
68 if (pwcd->type == type)
76 int pwc_decompress(struct pwc_device *pdev)
78 struct pwc_frame_buf *fbuf;
79 int n, line, col, stride;
82 u16 *dsty, *dstu, *dstv;
87 #if defined(__KERNEL__) && defined(PWC_MAGIC)
88 if (pdev->magic != PWC_MAGIC) {
89 Err("pwc_decompress(): magic failed.\n");
94 fbuf = pdev->read_frame;
97 image = pdev->image_ptr[pdev->fill_image];
101 yuv = fbuf->data + pdev->frame_header_size; /* Skip header */
102 if (pdev->vbandlength == 0) {
103 /* Uncompressed mode. We copy the data into the output buffer,
104 using the viewport size (which may be larger than the image
105 size). Unfortunately we have to do a bit of byte stuffing
106 to get the desired output format/size.
109 * We do some byte shuffling here to go from the
110 * native format to YUV420P.
113 n = pdev->view.x * pdev->view.y;
115 /* offset in Y plane */
116 stride = pdev->view.x * pdev->offset.y + pdev->offset.x;
117 dsty = (u16 *)(image + stride);
119 /* offsets in U/V planes */
120 stride = pdev->view.x * pdev->offset.y / 4 + pdev->offset.x / 2;
121 dstu = (u16 *)(image + n + stride);
122 dstv = (u16 *)(image + n + n / 4 + stride);
124 /* increment after each line */
125 stride = (pdev->view.x - pdev->image.x) / 2; /* u16 is 2 bytes */
127 for (line = 0; line < pdev->image.y; line++) {
128 for (col = 0; col < pdev->image.x; col += 4) {
138 dstv += (stride >> 1);
140 dstu += (stride >> 1);
144 /* Compressed; the decompressor routines will write the data
145 in planar format immediately.
147 if (pdev->decompressor)
148 pdev->decompressor->decompress(
149 &pdev->image, &pdev->view, &pdev->offset,
152 pdev->decompress_data, pdev->vbandlength);
154 return -ENXIO; /* No such device or address: missing decompressor */
159 /* Make sure these functions are available for the decompressor plugin
160 both when this code is compiled into the kernel or as as module.
163 EXPORT_SYMBOL_NOVERS(pwc_decompressor_version);
164 EXPORT_SYMBOL(pwc_register_decompressor);
165 EXPORT_SYMBOL(pwc_unregister_decompressor);