aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/pwc/pwc-uncompress.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/pwc/pwc-uncompress.c')
-rw-r--r--drivers/media/video/pwc/pwc-uncompress.c146
1 files changed, 146 insertions, 0 deletions
diff --git a/drivers/media/video/pwc/pwc-uncompress.c b/drivers/media/video/pwc/pwc-uncompress.c
new file mode 100644
index 000000000000..ef4204eab6c4
--- /dev/null
+++ b/drivers/media/video/pwc/pwc-uncompress.c
@@ -0,0 +1,146 @@
1/* Linux driver for Philips webcam
2 Decompression frontend.
3 (C) 1999-2003 Nemosoft Unv.
4 (C) 2004 Luc Saillard (luc@saillard.org)
5
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.
11
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.
16
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.
21
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
25*/
26
27#include <asm/current.h>
28#include <asm/types.h>
29
30#include "pwc.h"
31#include "pwc-uncompress.h"
32
33int pwc_decompress(struct pwc_device *pdev)
34{
35 struct pwc_frame_buf *fbuf;
36 int n, line, col, stride;
37 void *yuv, *image;
38 u16 *src;
39 u16 *dsty, *dstu, *dstv;
40
41 if (pdev == NULL)
42 return -EFAULT;
43#if defined(__KERNEL__) && defined(PWC_MAGIC)
44 if (pdev->magic != PWC_MAGIC) {
45 Err("pwc_decompress(): magic failed.\n");
46 return -EFAULT;
47 }
48#endif
49
50 fbuf = pdev->read_frame;
51 if (fbuf == NULL)
52 return -EFAULT;
53 image = pdev->image_ptr[pdev->fill_image];
54 if (!image)
55 return -EFAULT;
56
57 yuv = fbuf->data + pdev->frame_header_size; /* Skip header */
58
59 /* Raw format; that's easy... */
60 if (pdev->vpalette == VIDEO_PALETTE_RAW)
61 {
62 memcpy(image, yuv, pdev->frame_size);
63 return 0;
64 }
65
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.
71 */
72 /*
73 * We do some byte shuffling here to go from the
74 * native format to YUV420P.
75 */
76 src = (u16 *)yuv;
77 n = pdev->view.x * pdev->view.y;
78
79 /* offset in Y plane */
80 stride = pdev->view.x * pdev->offset.y + pdev->offset.x;
81 dsty = (u16 *)(image + stride);
82
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);
87
88 /* increment after each line */
89 stride = (pdev->view.x - pdev->image.x) / 2; /* u16 is 2 bytes */
90
91 for (line = 0; line < pdev->image.y; line++) {
92 for (col = 0; col < pdev->image.x; col += 4) {
93 *dsty++ = *src++;
94 *dsty++ = *src++;
95 if (line & 1)
96 *dstv++ = *src++;
97 else
98 *dstu++ = *src++;
99 }
100 dsty += stride;
101 if (line & 1)
102 dstv += (stride >> 1);
103 else
104 dstu += (stride >> 1);
105 }
106 }
107 else {
108 /* Compressed; the decompressor routines will write the data
109 in planar format immediately.
110 */
111 int flags;
112
113 flags = PWCX_FLAG_PLANAR;
114 if (pdev->vsize == PSZ_VGA && pdev->vframes == 5 && pdev->vsnapshot)
115 {
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 */
119 }
120
121#if 0
122 switch (pdev->type)
123 {
124 case 675:
125 case 680:
126 case 690:
127 case 720:
128 case 730:
129 case 740:
130 case 750:
131 pwc_dec23_decompress(&pdev->image, &pdev->view,
132 &pdev->offset, yuv, image, flags,
133 pdev->decompress_data, pdev->vbandlength);
134 break;
135 case 645:
136 case 646:
137 /* TODO & FIXME */
138 return -ENXIO; /* Missing decompressor */
139 break;
140 }
141#endif
142 }
143 return 0;
144}
145
146