VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / drivers / usb / media / pwc-misc.c
1 /* Linux driver for Philips webcam 
2    Various miscellaneous functions and tables.
3    (C) 1999-2003 Nemosoft Unv. (webcam@smcc.demon.nl)
4
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2 of the License, or
8    (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 */
19
20 #include <linux/slab.h>
21
22 #include "pwc.h"
23
24 struct pwc_coord pwc_image_sizes[PSZ_MAX] =
25 {
26         { 128,  96, 0 },
27         { 160, 120, 0 },
28         { 176, 144, 0 },
29         { 320, 240, 0 },
30         { 352, 288, 0 },
31         { 640, 480, 0 },
32 };
33
34 /* x,y -> PSZ_ */
35 int pwc_decode_size(struct pwc_device *pdev, int width, int height)
36 {
37         int i, find;
38
39         /* Make sure we don't go beyond our max size.
40            NB: we have different limits for RAW and normal modes. In case
41            you don't have the decompressor loaded or use RAW mode, 
42            the maximum viewable size is smaller.
43         */
44         if (pdev->vpalette == VIDEO_PALETTE_RAW)
45         {
46                 if (width > pdev->abs_max.x || height > pdev->abs_max.y)
47                 {
48                         Debug("VIDEO_PALETTE_RAW: going beyond abs_max.\n");
49                         return -1;
50                 }
51         }
52         else
53         {
54                 if (width > pdev->view_max.x || height > pdev->view_max.y)
55                 {
56                         Debug("VIDEO_PALETTE_ not RAW: going beyond view_max.\n");
57                         return -1;
58                 }
59         }
60
61         /* Find the largest size supported by the camera that fits into the
62            requested size.
63          */
64         find = -1;
65         for (i = 0; i < PSZ_MAX; i++) {
66                 if (pdev->image_mask & (1 << i)) {
67                         if (pwc_image_sizes[i].x <= width && pwc_image_sizes[i].y <= height)
68                                 find = i;
69                 }
70         }
71         return find;
72 }
73
74 /* initialize variables depending on type and decompressor*/
75 void pwc_construct(struct pwc_device *pdev)
76 {
77         switch(pdev->type) {
78         case 645:
79         case 646:
80                 pdev->view_min.x = 128;
81                 pdev->view_min.y =  96;
82                 pdev->view_max.x = 352;
83                 pdev->view_max.y = 288;
84                 pdev->abs_max.x  = 352;
85                 pdev->abs_max.y  = 288;
86                 pdev->image_mask = 1 << PSZ_SQCIF | 1 << PSZ_QCIF | 1 << PSZ_CIF;
87                 pdev->vcinterface = 2;
88                 pdev->vendpoint = 4;
89                 pdev->frame_header_size = 0;
90                 pdev->frame_trailer_size = 0;
91                 break;
92         case 675:
93         case 680:
94         case 690:
95                 pdev->view_min.x = 128;
96                 pdev->view_min.y =  96;
97                 /* Anthill bug #38: PWC always reports max size, even without PWCX */
98                 if (pdev->decompressor != NULL) {
99                         pdev->view_max.x = 640;
100                         pdev->view_max.y = 480;
101                 }
102                 else {
103                         pdev->view_max.x = 352;
104                         pdev->view_max.y = 288;
105                 }
106                 pdev->image_mask = 1 << PSZ_SQCIF | 1 << PSZ_QSIF | 1 << PSZ_QCIF | 1 << PSZ_SIF | 1 << PSZ_CIF | 1 << PSZ_VGA;
107                 pdev->abs_max.x = 640;
108                 pdev->abs_max.y = 480;
109                 pdev->vcinterface = 3;
110                 pdev->vendpoint = 4;
111                 pdev->frame_header_size = 0;
112                 pdev->frame_trailer_size = 0;
113                 break;
114         case 720:
115         case 730:
116         case 740:
117         case 750:
118                 pdev->view_min.x = 160;
119                 pdev->view_min.y = 120;
120                 /* Anthill bug #38: PWC always reports max size, even without PWCX */
121                 if (pdev->decompressor != NULL) {
122                         pdev->view_max.x = 640;
123                         pdev->view_max.y = 480;
124                 }
125                 else {
126                         /* We use CIF, not SIF since some tools really need CIF. So we cheat a bit. */
127                         pdev->view_max.x = 352;
128                         pdev->view_max.y = 288;
129                 }
130                 pdev->image_mask = 1 << PSZ_QSIF | 1 << PSZ_SIF | 1 << PSZ_VGA;
131                 pdev->abs_max.x = 640;
132                 pdev->abs_max.y = 480;
133                 pdev->vcinterface = 3;
134                 pdev->vendpoint = 5;
135                 pdev->frame_header_size = TOUCAM_HEADER_SIZE;
136                 pdev->frame_trailer_size = TOUCAM_TRAILER_SIZE;
137                 break;
138         }
139         pdev->vpalette = VIDEO_PALETTE_YUV420P; /* default */
140         pdev->view_min.size = pdev->view_min.x * pdev->view_min.y;
141         pdev->view_max.size = pdev->view_max.x * pdev->view_max.y;
142         /* length of image, in YUV format; always allocate enough memory. */
143         pdev->len_per_image = (pdev->abs_max.x * pdev->abs_max.y * 3) / 2;
144 }
145
146