~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux/drivers/usb/ibmcam.h

Version: ~ [ 2.4.0 ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * Header file for USB IBM C-It Video Camera driver.
  3  *
  4  * Supports IBM C-It Video Camera.
  5  *
  6  * This driver is based on earlier work of:
  7  *
  8  * (C) Copyright 1999 Johannes Erdfelt
  9  * (C) Copyright 1999 Randy Dunlap
 10  */
 11 
 12 #ifndef __LINUX_IBMCAM_H
 13 #define __LINUX_IBMCAM_H
 14 
 15 #include <linux/list.h>
 16 
 17 #define USES_IBMCAM_PUTPIXEL    0       /* 0=Fast/oops 1=Slow/secure */
 18 
 19 /* Video Size 384 x 288 x 3 bytes for RGB */
 20 /* 384 because xawtv tries to grab 384 even though we tell it 352 is our max */
 21 #define V4L_FRAME_WIDTH         384
 22 #define V4L_FRAME_WIDTH_USED    352
 23 #define V4L_FRAME_HEIGHT        288
 24 #define V4L_BYTES_PER_PIXEL     3
 25 #define MAX_FRAME_SIZE          (V4L_FRAME_WIDTH * V4L_FRAME_HEIGHT * V4L_BYTES_PER_PIXEL)
 26 
 27 /* Camera capabilities (maximum) */
 28 #define CAMERA_IMAGE_WIDTH      352
 29 #define CAMERA_IMAGE_HEIGHT     288
 30 #define CAMERA_IMAGE_LINE_SZ    ((CAMERA_IMAGE_WIDTH * 3) / 2) /* Bytes */
 31 #define CAMERA_URB_FRAMES       32
 32 #define CAMERA_MAX_ISO_PACKET   1023 /* 1022 actually sent by camera */
 33 
 34 #define IBMCAM_NUMFRAMES        2
 35 #define IBMCAM_NUMSBUF          2
 36 
 37 #define FRAMES_PER_DESC         (CAMERA_URB_FRAMES)
 38 #define FRAME_SIZE_PER_DESC     (CAMERA_MAX_ISO_PACKET)
 39 
 40 /* This macro restricts an int variable to an inclusive range */
 41 #define RESTRICT_TO_RANGE(v,mi,ma) { if ((v) < (mi)) (v) = (mi); else if ((v) > (ma)) (v) = (ma); }
 42 
 43 /*
 44  * This macro performs bounds checking - use it when working with
 45  * new formats, or else you may get oopses all over the place.
 46  * If pixel falls out of bounds then it gets shoved back (as close
 47  * to place of offence as possible) and is painted bright red.
 48  */
 49 #define IBMCAM_PUTPIXEL(fr, ix, iy, vr, vg, vb) { \
 50         register unsigned char *pf; \
 51         int limiter = 0, mx, my; \
 52         mx = ix; \
 53         my = iy; \
 54         if (mx < 0) { \
 55                 mx=0; \
 56                 limiter++; \
 57         } else if (mx >= 352) { \
 58                 mx=351; \
 59                 limiter++; \
 60         } \
 61         if (my < 0) { \
 62                 my = 0; \
 63                 limiter++; \
 64         } else if (my >= V4L_FRAME_HEIGHT) { \
 65                 my = V4L_FRAME_HEIGHT - 1; \
 66                 limiter++; \
 67         } \
 68         pf = (fr)->data + V4L_BYTES_PER_PIXEL*((iy)*352 + (ix)); \
 69         if (limiter) { \
 70                 *pf++ = 0; \
 71                 *pf++ = 0; \
 72                 *pf++ = 0xFF; \
 73         } else { \
 74                 *pf++ = (vb); \
 75                 *pf++ = (vg); \
 76                 *pf++ = (vr); \
 77         } \
 78 }
 79 
 80 /*
 81  * We use macros to do YUV -> RGB conversion because this is
 82  * very important for speed and totally unimportant for size.
 83  *
 84  * YUV -> RGB Conversion
 85  * ---------------------
 86  *
 87  * B = 1.164*(Y-16)                 + 2.018*(V-128)
 88  * G = 1.164*(Y-16) - 0.813*(U-128) - 0.391*(V-128)
 89  * R = 1.164*(Y-16) + 1.596*(U-128)
 90  *
 91  * If you fancy integer arithmetics (as you should), hear this:
 92  *
 93  * 65536*B = 76284*(Y-16)                 + 132252*(V-128)
 94  * 65536*G = 76284*(Y-16) -  53281*(U-128) -  25625*(V-128)
 95  * 65536*R = 76284*(Y-16) + 104595*(U-128)
 96  *
 97  * Make sure the output values are within [0..255] range.
 98  */
 99 #define LIMIT_RGB(x) (((x) < 0) ? 0 : (((x) > 255) ? 255 : (x)))
100 #define YUV_TO_RGB_BY_THE_BOOK(my,mu,mv,mr,mg,mb) { \
101     int mm_y, mm_yc, mm_u, mm_v, mm_r, mm_g, mm_b; \
102     mm_y = (my) - 16;  \
103     mm_u = (mu) - 128; \
104     mm_v = (mv) - 128; \
105     mm_yc= mm_y * 76284; \
106     mm_b = (mm_yc               + 132252*mm_v   ) >> 16; \
107     mm_g = (mm_yc -  53281*mm_u -  25625*mm_v   ) >> 16; \
108     mm_r = (mm_yc + 104595*mm_u                 ) >> 16; \
109     mb = LIMIT_RGB(mm_b); \
110     mg = LIMIT_RGB(mm_g); \
111     mr = LIMIT_RGB(mm_r); \
112 }
113 
114 /* Debugging aid */
115 #define IBMCAM_SAY_AND_WAIT(what) { \
116         wait_queue_head_t wq; \
117         init_waitqueue_head(&wq); \
118         printk(KERN_INFO "Say: %s\n", what); \
119         interruptible_sleep_on_timeout (&wq, HZ*3); \
120 }
121 
122 /*
123  * This macro checks if ibmcam is still operational. The 'ibmcam'
124  * pointer must be valid, ibmcam->dev must be valid, we are not
125  * removing the device and the device has not erred on us.
126  */
127 #define IBMCAM_IS_OPERATIONAL(ibm_cam) (\
128         (ibm_cam != NULL) && \
129         ((ibm_cam)->dev != NULL) && \
130         ((ibm_cam)->last_error == 0) && \
131         (!(ibm_cam)->remove_pending))
132 
133 enum {
134         STATE_SCANNING,         /* Scanning for header */
135         STATE_LINES,            /* Parsing lines */
136 };
137 
138 enum {
139         FRAME_UNUSED,           /* Unused (no MCAPTURE) */
140         FRAME_READY,            /* Ready to start grabbing */
141         FRAME_GRABBING,         /* In the process of being grabbed into */
142         FRAME_DONE,             /* Finished grabbing, but not been synced yet */
143         FRAME_ERROR,            /* Something bad happened while processing */
144 };
145 
146 struct usb_device;
147 
148 struct ibmcam_sbuf {
149         char *data;
150         urb_t *urb;
151 };
152 
153 struct ibmcam_frame {
154         char *data;             /* Frame buffer */
155         int order_uv;           /* True=UV False=VU */
156         int order_yc;           /* True=Yc False=cY ('c'=either U or V) */
157         unsigned char hdr_sig;  /* "00 FF 00 ??" where 'hdr_sig' is '??' */
158 
159         int width;              /* Width application is expecting */
160         int height;             /* Height */
161 
162         int frmwidth;           /* Width the frame actually is */
163         int frmheight;          /* Height */
164 
165         volatile int grabstate; /* State of grabbing */
166         int scanstate;          /* State of scanning */
167 
168         int curline;            /* Line of frame we're working on */
169 
170         long scanlength;        /* uncompressed, raw data length of frame */
171         long bytes_read;        /* amount of scanlength that has been read from *data */
172 
173         wait_queue_head_t wq;   /* Processes waiting */
174 };
175 
176 #define IBMCAM_MODEL_1  1       /* XVP-501, 3 interfaces, rev. 0.02 */
177 #define IBMCAM_MODEL_2  2       /* KSX-X9903, 2 interfaces, rev. 3.0a */
178 
179 struct usb_ibmcam {
180         struct video_device vdev;
181 
182         /* Device structure */
183         struct usb_device *dev;
184 
185         unsigned char iface;                            /* Video interface number */
186         unsigned char ifaceAltActive, ifaceAltInactive; /* Alt settings */
187 
188         struct semaphore lock;
189         int user;               /* user count for exclusive use */
190 
191         int ibmcam_used;        /* Is this structure in use? */
192         int initialized;        /* Had we already sent init sequence? */
193         int camera_model;       /* What type of IBM camera we got? */
194         int streaming;          /* Are we streaming Isochronous? */
195         int grabbing;           /* Are we grabbing? */
196         int last_error;         /* What calamity struck us? */
197 
198         int compress;           /* Should the next frame be compressed? */
199 
200         char *fbuf;             /* Videodev buffer area */
201         int fbuf_size;          /* Videodev buffer size */
202 
203         int curframe;
204         struct ibmcam_frame frame[IBMCAM_NUMFRAMES];    /* Double buffering */
205 
206         int cursbuf;            /* Current receiving sbuf */
207         struct ibmcam_sbuf sbuf[IBMCAM_NUMSBUF];        /* Double buffering */
208         volatile int remove_pending;    /* If set then about to exit */
209 
210         /*
211          * Scratch space from the Isochronous pipe.
212          * Scratch buffer should contain at least one pair of lines
213          * (CAMERA_IMAGE_LINE_SZ). We set it to two pairs here.
214          * This will be approximately 2 KB. HOWEVER in reality this
215          * buffer must be as large as hundred of KB because otherwise
216          * you'll get lots of overflows because V4L client may request
217          * frames not as uniformly as USB sources them.
218          */
219         unsigned char *scratch;
220         int scratchlen;
221 
222         struct video_picture vpic, vpic_old;    /* Picture settings */
223         struct video_capability vcap;           /* Video capabilities */
224         struct video_channel vchan;     /* May be used for tuner support */
225         unsigned char video_endp;       /* 0x82 for IBM camera */
226         int has_hdr;
227         int frame_num;
228         int iso_packet_len;             /* Videomode-dependent, saves bus bandwidth */
229 
230         /* Statistics that can be overlayed on screen */
231         unsigned long urb_count;        /* How many URBs we received so far */
232         unsigned long urb_length;       /* Length of last URB */
233         unsigned long data_count;       /* How many bytes we received */
234         unsigned long header_count;     /* How many frame headers we found */
235         unsigned long scratch_ovf_count;/* How many times we overflowed scratch */
236         unsigned long iso_skip_count;   /* How many empty ISO packets received */
237         unsigned long iso_err_count;    /* How many bad ISO packets received */
238 };
239 
240 #endif /* __LINUX_IBMCAM_H */
241 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.