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. |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 4 | (C) 2004-2006 Luc Saillard (luc@saillard.org) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 25 | |
| 26 | vim: set ts=8: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | */ |
| 28 | |
| 29 | #include <asm/current.h> |
| 30 | #include <asm/types.h> |
| 31 | |
| 32 | #include "pwc.h" |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 33 | #include "pwc-dec1.h" |
| 34 | #include "pwc-dec23.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Hans de Goede | 885fe18 | 2011-06-06 15:33:44 -0300 | [diff] [blame] | 36 | int pwc_decompress(struct pwc_device *pdev, struct pwc_frame_buf *fbuf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | { |
Hans de Goede | 795e6eb | 2012-01-04 16:58:44 -0300 | [diff] [blame] | 38 | int n, line, col; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | void *yuv, *image; |
| 40 | u16 *src; |
| 41 | u16 *dsty, *dstu, *dstv; |
| 42 | |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 43 | image = vb2_plane_vaddr(&fbuf->vb.vb2_buf, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
| 45 | yuv = fbuf->data + pdev->frame_header_size; /* Skip header */ |
| 46 | |
| 47 | /* Raw format; that's easy... */ |
Hans Verkuil | 479567c | 2010-09-12 17:05:11 -0300 | [diff] [blame] | 48 | if (pdev->pixfmt != V4L2_PIX_FMT_YUV420) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 50 | struct pwc_raw_frame *raw_frame = image; |
| 51 | raw_frame->type = cpu_to_le16(pdev->type); |
| 52 | raw_frame->vbandlength = cpu_to_le16(pdev->vbandlength); |
| 53 | /* cmd_buf is always 4 bytes, but sometimes, only the |
| 54 | * first 3 bytes is filled (Nala case). We can |
| 55 | * determine this using the type of the webcam */ |
| 56 | memcpy(raw_frame->cmd, pdev->cmd_buf, 4); |
| 57 | memcpy(raw_frame+1, yuv, pdev->frame_size); |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 58 | vb2_set_plane_payload(&fbuf->vb.vb2_buf, 0, |
Hans de Goede | 885fe18 | 2011-06-06 15:33:44 -0300 | [diff] [blame] | 59 | pdev->frame_size + sizeof(struct pwc_raw_frame)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | return 0; |
| 61 | } |
| 62 | |
Junghak Sung | 2d70071 | 2015-09-22 10:30:30 -0300 | [diff] [blame] | 63 | vb2_set_plane_payload(&fbuf->vb.vb2_buf, 0, |
Hans de Goede | 795e6eb | 2012-01-04 16:58:44 -0300 | [diff] [blame] | 64 | pdev->width * pdev->height * 3 / 2); |
Hans de Goede | 885fe18 | 2011-06-06 15:33:44 -0300 | [diff] [blame] | 65 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | if (pdev->vbandlength == 0) { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 67 | /* Uncompressed mode. |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 68 | * |
| 69 | * We do some byte shuffling here to go from the |
| 70 | * native format to YUV420P. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | */ |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 72 | src = (u16 *)yuv; |
Hans de Goede | 795e6eb | 2012-01-04 16:58:44 -0300 | [diff] [blame] | 73 | n = pdev->width * pdev->height; |
| 74 | dsty = (u16 *)(image); |
| 75 | dstu = (u16 *)(image + n); |
| 76 | dstv = (u16 *)(image + n + n / 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
Hans de Goede | 795e6eb | 2012-01-04 16:58:44 -0300 | [diff] [blame] | 78 | for (line = 0; line < pdev->height; line++) { |
| 79 | for (col = 0; col < pdev->width; col += 4) { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 80 | *dsty++ = *src++; |
| 81 | *dsty++ = *src++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | if (line & 1) |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 83 | *dstv++ = *src++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | else |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 85 | *dstu++ = *src++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | } |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | } |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 91 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 92 | /* |
| 93 | * Compressed; |
| 94 | * the decompressor routines will write the data in planar format |
| 95 | * immediately. |
| 96 | */ |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 97 | if (DEVICE_USE_CODEC1(pdev->type)) { |
| 98 | |
| 99 | /* TODO & FIXME */ |
| 100 | PWC_ERROR("This chipset is not supported for now\n"); |
| 101 | return -ENXIO; /* No such device or address: missing decompressor */ |
| 102 | |
| 103 | } else { |
Hans de Goede | dc8a7e8 | 2011-12-31 10:52:02 -0300 | [diff] [blame] | 104 | pwc_dec23_decompress(pdev, yuv, image); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | } |
| 106 | return 0; |
| 107 | } |