Merge 2.6.38-rc5 into staging-next
[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 (NULL == 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 ;  u = u + 128;
101                 v =  615*r/1000 - 515*g/1000 - 100*b/1000 ;  v = v + 128;
102
103                 uyvy[0] =  0xFF & u ;
104                 uyvy[1] =  0xFF & y ;
105                 uyvy[2] =  0xFF & v ;
106                 uyvy[3] =  0xFF & y ;
107
108                 p1 = &bfbar[0];
109                 while (p1 < &bfbar[barwidth]) {
110                         *p1++ = uyvy[0] ;
111                         *p1++ = uyvy[1] ;
112                         *p1++ = uyvy[2] ;
113                         *p1++ = uyvy[3] ;
114                         total += 4;
115                         }
116
117                 p1 = &bfbar[0];
118                 more = barwidth;
119
120                 while (more) {
121                         if ((FIELD_BUFFER_SIZE/PAGE_SIZE) <= m) {
122                                 SAM("ERROR:  bad m reached\n");
123                                 return;
124                         }
125                 if (PAGE_SIZE < n) {
126                         SAM("ERROR:  bad n reached\n"); return;
127                 }
128
129                 if (0 > more) {
130                         SAM("ERROR:  internal fault\n");
131                         return;
132                 }
133
134                 much = PAGE_SIZE - n;
135                 if (much > more)
136                         much = more;
137                 pfield_buffer = &peasycap->field_buffer[k][m];
138                 p2 = pfield_buffer->pgo + n;
139                 memcpy(p2, p1, much);
140
141                 p1 += much;
142                 n += much;
143                 more -= much;
144                 if (PAGE_SIZE == n) {
145                         m++;
146                         n = 0;
147                         }
148                 }
149         }
150 }
151 return;
152 }