Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
| 33 | int 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 | switch (pdev->type) |
| 122 | { |
Alan Cox | 88c1834 | 2005-05-27 13:40:53 +0100 | [diff] [blame] | 123 | #if 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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, &pdev->offset, |
| 132 | yuv, image, |
| 133 | flags, |
| 134 | pdev->decompress_data, pdev->vbandlength); |
| 135 | break; |
| 136 | case 645: |
| 137 | case 646: |
| 138 | /* TODO & FIXME */ |
Alan Cox | 88c1834 | 2005-05-27 13:40:53 +0100 | [diff] [blame] | 139 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | return -ENXIO; /* No such device or address: missing decompressor */ |
| 141 | break; |
| 142 | } |
| 143 | } |
| 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | |