Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1 | /* Linux driver for Philips webcam |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | Various miscellaneous functions and tables. |
| 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 |
| 25 | */ |
| 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
| 28 | #include "pwc.h" |
| 29 | |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 30 | const struct pwc_coord pwc_image_sizes[PSZ_MAX] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 32 | { 128, 96, 0 }, /* sqcif */ |
| 33 | { 160, 120, 0 }, /* qsif */ |
| 34 | { 176, 144, 0 }, /* qcif */ |
| 35 | { 320, 240, 0 }, /* sif */ |
| 36 | { 352, 288, 0 }, /* cif */ |
| 37 | { 640, 480, 0 }, /* vga */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | /* x,y -> PSZ_ */ |
| 41 | int pwc_decode_size(struct pwc_device *pdev, int width, int height) |
| 42 | { |
| 43 | int i, find; |
| 44 | |
| 45 | /* Make sure we don't go beyond our max size. |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 46 | NB: we have different limits for RAW and normal modes. In case |
| 47 | you don't have the decompressor loaded or use RAW mode, |
| 48 | the maximum viewable size is smaller. |
| 49 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | if (pdev->vpalette == VIDEO_PALETTE_RAW) |
| 51 | { |
| 52 | if (width > pdev->abs_max.x || height > pdev->abs_max.y) |
| 53 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 54 | PWC_DEBUG_SIZE("VIDEO_PALETTE_RAW: going beyond abs_max.\n"); |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 55 | return -1; |
| 56 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | } |
| 58 | else |
| 59 | { |
| 60 | if (width > pdev->view_max.x || height > pdev->view_max.y) |
| 61 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 62 | PWC_DEBUG_SIZE("VIDEO_PALETTE_not RAW: going beyond view_max.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | return -1; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | /* Find the largest size supported by the camera that fits into the |
| 68 | requested size. |
| 69 | */ |
| 70 | find = -1; |
| 71 | for (i = 0; i < PSZ_MAX; i++) { |
| 72 | if (pdev->image_mask & (1 << i)) { |
| 73 | if (pwc_image_sizes[i].x <= width && pwc_image_sizes[i].y <= height) |
| 74 | find = i; |
| 75 | } |
| 76 | } |
| 77 | return find; |
| 78 | } |
| 79 | |
| 80 | /* initialize variables depending on type and decompressor*/ |
| 81 | void pwc_construct(struct pwc_device *pdev) |
| 82 | { |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 83 | if (DEVICE_USE_CODEC1(pdev->type)) { |
| 84 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | pdev->view_min.x = 128; |
| 86 | pdev->view_min.y = 96; |
| 87 | pdev->view_max.x = 352; |
| 88 | pdev->view_max.y = 288; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 89 | pdev->abs_max.x = 352; |
| 90 | pdev->abs_max.y = 288; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | pdev->image_mask = 1 << PSZ_SQCIF | 1 << PSZ_QCIF | 1 << PSZ_CIF; |
| 92 | pdev->vcinterface = 2; |
| 93 | pdev->vendpoint = 4; |
| 94 | pdev->frame_header_size = 0; |
| 95 | pdev->frame_trailer_size = 0; |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 96 | |
| 97 | } else if (DEVICE_USE_CODEC3(pdev->type)) { |
| 98 | |
| 99 | pdev->view_min.x = 160; |
| 100 | pdev->view_min.y = 120; |
| 101 | pdev->view_max.x = 640; |
| 102 | pdev->view_max.y = 480; |
| 103 | pdev->image_mask = 1 << PSZ_QSIF | 1 << PSZ_SIF | 1 << PSZ_VGA; |
| 104 | pdev->abs_max.x = 640; |
| 105 | pdev->abs_max.y = 480; |
| 106 | pdev->vcinterface = 3; |
| 107 | pdev->vendpoint = 5; |
| 108 | pdev->frame_header_size = TOUCAM_HEADER_SIZE; |
| 109 | pdev->frame_trailer_size = TOUCAM_TRAILER_SIZE; |
| 110 | |
| 111 | } else /* if (DEVICE_USE_CODEC2(pdev->type)) */ { |
| 112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | pdev->view_min.x = 128; |
| 114 | pdev->view_min.y = 96; |
| 115 | /* Anthill bug #38: PWC always reports max size, even without PWCX */ |
| 116 | pdev->view_max.x = 640; |
| 117 | pdev->view_max.y = 480; |
| 118 | pdev->image_mask = 1 << PSZ_SQCIF | 1 << PSZ_QSIF | 1 << PSZ_QCIF | 1 << PSZ_SIF | 1 << PSZ_CIF | 1 << PSZ_VGA; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 119 | pdev->abs_max.x = 640; |
| 120 | pdev->abs_max.y = 480; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | pdev->vcinterface = 3; |
| 122 | pdev->vendpoint = 4; |
| 123 | pdev->frame_header_size = 0; |
| 124 | pdev->frame_trailer_size = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | pdev->vpalette = VIDEO_PALETTE_YUV420P; /* default */ |
| 127 | pdev->view_min.size = pdev->view_min.x * pdev->view_min.y; |
| 128 | pdev->view_max.size = pdev->view_max.x * pdev->view_max.y; |
| 129 | /* length of image, in YUV format; always allocate enough memory. */ |
Luc Saillard | 2b455db | 2006-04-24 10:29:46 -0300 | [diff] [blame] | 130 | pdev->len_per_image = PAGE_ALIGN((pdev->abs_max.x * pdev->abs_max.y * 3) / 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | |