Merge git://git.kernel.org/pub/scm/linux/kernel/git/wim/linux-2.6-watchdog
[linux-block.git] / drivers / staging / easycap / easycap_testcard.c
1 /******************************************************************************
2 *                                                                             *
3 *  easycap_testcard.c                                                         *
4 *                                                                             *
5 ******************************************************************************/
6 /*
7  *
8  *  Copyright (C) 2010 R.M. Thomas  <rmthomas@sciolus.org>
9  *
10  *
11  *  This is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  The software is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this software; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24  *
25 */
26 /*****************************************************************************/
27
28 #include "easycap.h"
29
30 /*****************************************************************************/
31 #define TESTCARD_BYTESPERLINE (2 * 720)
32 void
33 easycap_testcard(struct easycap *peasycap, int field)
34 {
35         int total;
36         int y, u, v, r, g, b;
37         unsigned char uyvy[4];
38         int i1, line, k, m, n, more, much, barwidth, barheight;
39         unsigned char bfbar[TESTCARD_BYTESPERLINE / 8], *p1, *p2;
40         struct data_buffer *pfield_buffer;
41
42         if (!peasycap) {
43                 SAY("ERROR: peasycap is NULL\n");
44                 return;
45         }
46         JOM(8, "%i=field\n", field);
47         switch (peasycap->width) {
48         case 720:
49         case 360: {
50                 barwidth = (2 * 720) / 8;
51                 break;
52         }
53         case 704:
54         case 352: {
55                 barwidth = (2 * 704) / 8;
56                 break;
57         }
58         case 640:
59         case 320: {
60                 barwidth = (2 * 640) / 8;
61                 break;
62         }
63         default: {
64                 SAM("ERROR:  cannot set barwidth\n");
65                 return;
66         }
67         }
68         if (TESTCARD_BYTESPERLINE < barwidth) {
69                 SAM("ERROR: barwidth is too large\n");
70                 return;
71         }
72         switch (peasycap->height) {
73         case 576:
74         case 288: {
75                 barheight = 576;
76                 break;
77         }
78         case 480:
79         case 240: {
80                 barheight = 480;
81                 break;
82         }
83         default: {
84                 SAM("ERROR: cannot set barheight\n");
85                 return;
86         }
87         }
88         total = 0;
89         k = field;
90         m = 0;
91         n = 0;
92
93         for (line = 0;  line < (barheight / 2);  line++) {
94                 for (i1 = 0;  i1 < 8;  i1++) {
95                         r = (i1 * 256)/8;
96                         g = (i1 * 256)/8;
97                         b = (i1 * 256)/8;
98
99                         y =  299*r/1000 + 587*g/1000 + 114*b/1000 ;
100                         u = -147*r/1000 - 289*g/1000 + 436*b/1000 ;
101                         u = u + 128;
102                         v =  615*r/1000 - 515*g/1000 - 100*b/1000 ;
103                         v = v + 128;
104
105                         uyvy[0] =  0xFF & u ;
106                         uyvy[1] =  0xFF & y ;
107                         uyvy[2] =  0xFF & v ;
108                         uyvy[3] =  0xFF & y ;
109
110                         p1 = &bfbar[0];
111                         while (p1 < &bfbar[barwidth]) {
112                                 *p1++ = uyvy[0] ;
113                                 *p1++ = uyvy[1] ;
114                                 *p1++ = uyvy[2] ;
115                                 *p1++ = uyvy[3] ;
116                                 total += 4;
117                         }
118
119                         p1 = &bfbar[0];
120                         more = barwidth;
121
122                         while (more) {
123                                 if ((FIELD_BUFFER_SIZE/PAGE_SIZE) <= m) {
124                                         SAM("ERROR:  bad m reached\n");
125                                         return;
126                                 }
127                                 if (PAGE_SIZE < n) {
128                                         SAM("ERROR:  bad n reached\n");
129                                         return;
130                                 }
131
132                                 if (0 > more) {
133                                         SAM("ERROR:  internal fault\n");
134                                         return;
135                                 }
136
137                                 much = PAGE_SIZE - n;
138                                 if (much > more)
139                                         much = more;
140                                 pfield_buffer = &peasycap->field_buffer[k][m];
141                                 p2 = pfield_buffer->pgo + n;
142                                 memcpy(p2, p1, much);
143
144                                 p1 += much;
145                                 n += much;
146                                 more -= much;
147                                 if (PAGE_SIZE == n) {
148                                         m++;
149                                         n = 0;
150                                 }
151                         }
152                 }
153         }
154         return;
155 }