1 /* Linux driver for Philips webcam
2 Decompression frontend.
3 (C) 1999-2003 Nemosoft Unv.
4 (C) 2004 Luc Saillard (luc@saillard.org)
6 NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx
7 driver and thus may have bugs that are not present in the original version.
8 Please send bug reports and support requests to <luc@saillard.org>.
9 The decompression routines have been implemented by reverse-engineering the
10 Nemosoft binary pwcx module. Caveat emptor.
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include <asm/current.h>
28 #include <asm/types.h>
31 #include "pwc-uncompress.h"
33 int pwc_decompress(struct pwc_device
*pdev
)
35 struct pwc_frame_buf
*fbuf
;
36 int n
, line
, col
, stride
;
39 u16
*dsty
, *dstu
, *dstv
;
43 #if defined(__KERNEL__) && defined(PWC_MAGIC)
44 if (pdev
->magic
!= PWC_MAGIC
) {
45 Err("pwc_decompress(): magic failed.\n");
50 fbuf
= pdev
->read_frame
;
53 image
= pdev
->image_ptr
[pdev
->fill_image
];
57 yuv
= fbuf
->data
+ pdev
->frame_header_size
; /* Skip header */
59 /* Raw format; that's easy... */
60 if (pdev
->vpalette
== VIDEO_PALETTE_RAW
)
62 memcpy(image
, yuv
, pdev
->frame_size
);
66 if (pdev
->vbandlength
== 0) {
67 /* Uncompressed mode. We copy the data into the output buffer,
68 using the viewport size (which may be larger than the image
69 size). Unfortunately we have to do a bit of byte stuffing
70 to get the desired output format/size.
73 * We do some byte shuffling here to go from the
74 * native format to YUV420P.
77 n
= pdev
->view
.x
* pdev
->view
.y
;
79 /* offset in Y plane */
80 stride
= pdev
->view
.x
* pdev
->offset
.y
+ pdev
->offset
.x
;
81 dsty
= (u16
*)(image
+ stride
);
83 /* offsets in U/V planes */
84 stride
= pdev
->view
.x
* pdev
->offset
.y
/ 4 + pdev
->offset
.x
/ 2;
85 dstu
= (u16
*)(image
+ n
+ stride
);
86 dstv
= (u16
*)(image
+ n
+ n
/ 4 + stride
);
88 /* increment after each line */
89 stride
= (pdev
->view
.x
- pdev
->image
.x
) / 2; /* u16 is 2 bytes */
91 for (line
= 0; line
< pdev
->image
.y
; line
++) {
92 for (col
= 0; col
< pdev
->image
.x
; col
+= 4) {
102 dstv
+= (stride
>> 1);
104 dstu
+= (stride
>> 1);
108 /* Compressed; the decompressor routines will write the data
109 in planar format immediately.
113 flags
= PWCX_FLAG_PLANAR
;
114 if (pdev
->vsize
== PSZ_VGA
&& pdev
->vframes
== 5 && pdev
->vsnapshot
)
116 printk(KERN_ERR
"pwc: Mode Bayer is not supported for now\n");
117 flags
|= PWCX_FLAG_BAYER
;
118 return -ENXIO
; /* No such device or address: missing decompressor */
131 pwc_dec23_decompress(&pdev
->image
, &pdev
->view
,
132 &pdev
->offset
, yuv
, image
, flags
,
133 pdev
->decompress_data
, pdev
->vbandlength
);
138 return -ENXIO
; /* Missing decompressor */