Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* Linux driver for Philips webcam |
2 | Decompression frontend. | |
3 | (C) 1999-2003 Nemosoft Unv. | |
2b455db6 | 4 | (C) 2004-2006 Luc Saillard (luc@saillard.org) |
1da177e4 LT |
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 | |
2b455db6 LS |
25 | |
26 | vim: set ts=8: | |
1da177e4 LT |
27 | */ |
28 | ||
29 | #include <asm/current.h> | |
30 | #include <asm/types.h> | |
31 | ||
32 | #include "pwc.h" | |
33 | #include "pwc-uncompress.h" | |
2b455db6 LS |
34 | #include "pwc-dec1.h" |
35 | #include "pwc-dec23.h" | |
1da177e4 LT |
36 | |
37 | int pwc_decompress(struct pwc_device *pdev) | |
38 | { | |
39 | struct pwc_frame_buf *fbuf; | |
40 | int n, line, col, stride; | |
41 | void *yuv, *image; | |
42 | u16 *src; | |
43 | u16 *dsty, *dstu, *dstv; | |
44 | ||
1da177e4 | 45 | fbuf = pdev->read_frame; |
2b455db6 LS |
46 | image = pdev->image_data; |
47 | image += pdev->images[pdev->fill_image].offset; | |
1da177e4 LT |
48 | |
49 | yuv = fbuf->data + pdev->frame_header_size; /* Skip header */ | |
50 | ||
51 | /* Raw format; that's easy... */ | |
479567ce | 52 | if (pdev->pixfmt != V4L2_PIX_FMT_YUV420) |
1da177e4 | 53 | { |
2b455db6 LS |
54 | struct pwc_raw_frame *raw_frame = image; |
55 | raw_frame->type = cpu_to_le16(pdev->type); | |
56 | raw_frame->vbandlength = cpu_to_le16(pdev->vbandlength); | |
57 | /* cmd_buf is always 4 bytes, but sometimes, only the | |
58 | * first 3 bytes is filled (Nala case). We can | |
59 | * determine this using the type of the webcam */ | |
60 | memcpy(raw_frame->cmd, pdev->cmd_buf, 4); | |
61 | memcpy(raw_frame+1, yuv, pdev->frame_size); | |
1da177e4 LT |
62 | return 0; |
63 | } | |
64 | ||
65 | if (pdev->vbandlength == 0) { | |
2b455db6 LS |
66 | /* Uncompressed mode. |
67 | * We copy the data into the output buffer, using the viewport | |
68 | * size (which may be larger than the image size). | |
69 | * Unfortunately we have to do a bit of byte stuffing to get | |
70 | * the desired output format/size. | |
71 | * | |
72 | * We do some byte shuffling here to go from the | |
73 | * native format to YUV420P. | |
1da177e4 | 74 | */ |
2b455db6 LS |
75 | src = (u16 *)yuv; |
76 | n = pdev->view.x * pdev->view.y; | |
77 | ||
78 | /* offset in Y plane */ | |
79 | stride = pdev->view.x * pdev->offset.y + pdev->offset.x; | |
80 | dsty = (u16 *)(image + stride); | |
81 | ||
82 | /* offsets in U/V planes */ | |
83 | stride = pdev->view.x * pdev->offset.y / 4 + pdev->offset.x / 2; | |
84 | dstu = (u16 *)(image + n + stride); | |
85 | dstv = (u16 *)(image + n + n / 4 + stride); | |
86 | ||
87 | /* increment after each line */ | |
88 | stride = (pdev->view.x - pdev->image.x) / 2; /* u16 is 2 bytes */ | |
89 | ||
90 | for (line = 0; line < pdev->image.y; line++) { | |
91 | for (col = 0; col < pdev->image.x; col += 4) { | |
92 | *dsty++ = *src++; | |
93 | *dsty++ = *src++; | |
1da177e4 | 94 | if (line & 1) |
2b455db6 | 95 | *dstv++ = *src++; |
1da177e4 | 96 | else |
2b455db6 | 97 | *dstu++ = *src++; |
1da177e4 | 98 | } |
2b455db6 LS |
99 | dsty += stride; |
100 | if (line & 1) | |
101 | dstv += (stride >> 1); | |
102 | else | |
103 | dstu += (stride >> 1); | |
104 | } | |
105 | ||
106 | return 0; | |
1da177e4 | 107 | } |
2b455db6 LS |
108 | |
109 | /* | |
110 | * Compressed; | |
111 | * the decompressor routines will write the data in planar format | |
112 | * immediately. | |
113 | */ | |
114 | if (pdev->vsize == PSZ_VGA && pdev->vframes == 5 && pdev->vsnapshot) { | |
115 | PWC_ERROR("Mode Bayer is not supported for now\n"); | |
116 | /* flags |= PWCX_FLAG_BAYER; */ | |
117 | return -ENXIO; /* No such device or address: missing decompressor */ | |
118 | } | |
119 | ||
120 | if (DEVICE_USE_CODEC1(pdev->type)) { | |
121 | ||
122 | /* TODO & FIXME */ | |
123 | PWC_ERROR("This chipset is not supported for now\n"); | |
124 | return -ENXIO; /* No such device or address: missing decompressor */ | |
125 | ||
126 | } else { | |
127 | pwc_dec23_decompress(pdev, yuv, image, PWCX_FLAG_PLANAR); | |
1da177e4 LT |
128 | } |
129 | return 0; | |
130 | } | |
131 | ||
132 | ||
2b455db6 | 133 | /* vim: set cino= formatoptions=croql cindent shiftwidth=8 tabstop=8: */ |