/drivers/staging/easycap/easycap_testcard.c

https://bitbucket.org/slukk/jb-tsm-kernel-4.2 · C · 155 lines · 116 code · 12 blank · 27 comment · 14 complexity · 693ddab303f0a7a059fb6a818508114b MD5 · raw file

  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. #include "easycap.h"
  28. /*****************************************************************************/
  29. #define TESTCARD_BYTESPERLINE (2 * 720)
  30. void
  31. easycap_testcard(struct easycap *peasycap, int field)
  32. {
  33. int total;
  34. int y, u, v, r, g, b;
  35. unsigned char uyvy[4];
  36. int i1, line, k, m, n, more, much, barwidth, barheight;
  37. unsigned char bfbar[TESTCARD_BYTESPERLINE / 8], *p1, *p2;
  38. struct data_buffer *pfield_buffer;
  39. if (!peasycap) {
  40. SAY("ERROR: peasycap is NULL\n");
  41. return;
  42. }
  43. JOM(8, "%i=field\n", field);
  44. switch (peasycap->width) {
  45. case 720:
  46. case 360: {
  47. barwidth = (2 * 720) / 8;
  48. break;
  49. }
  50. case 704:
  51. case 352: {
  52. barwidth = (2 * 704) / 8;
  53. break;
  54. }
  55. case 640:
  56. case 320: {
  57. barwidth = (2 * 640) / 8;
  58. break;
  59. }
  60. default: {
  61. SAM("ERROR: cannot set barwidth\n");
  62. return;
  63. }
  64. }
  65. if (TESTCARD_BYTESPERLINE < barwidth) {
  66. SAM("ERROR: barwidth is too large\n");
  67. return;
  68. }
  69. switch (peasycap->height) {
  70. case 576:
  71. case 288: {
  72. barheight = 576;
  73. break;
  74. }
  75. case 480:
  76. case 240: {
  77. barheight = 480;
  78. break;
  79. }
  80. default: {
  81. SAM("ERROR: cannot set barheight\n");
  82. return;
  83. }
  84. }
  85. total = 0;
  86. k = field;
  87. m = 0;
  88. n = 0;
  89. for (line = 0; line < (barheight / 2); line++) {
  90. for (i1 = 0; i1 < 8; i1++) {
  91. r = (i1 * 256)/8;
  92. g = (i1 * 256)/8;
  93. b = (i1 * 256)/8;
  94. y = 299*r/1000 + 587*g/1000 + 114*b/1000 ;
  95. u = -147*r/1000 - 289*g/1000 + 436*b/1000 ;
  96. u = u + 128;
  97. v = 615*r/1000 - 515*g/1000 - 100*b/1000 ;
  98. v = v + 128;
  99. uyvy[0] = 0xFF & u ;
  100. uyvy[1] = 0xFF & y ;
  101. uyvy[2] = 0xFF & v ;
  102. uyvy[3] = 0xFF & y ;
  103. p1 = &bfbar[0];
  104. while (p1 < &bfbar[barwidth]) {
  105. *p1++ = uyvy[0] ;
  106. *p1++ = uyvy[1] ;
  107. *p1++ = uyvy[2] ;
  108. *p1++ = uyvy[3] ;
  109. total += 4;
  110. }
  111. p1 = &bfbar[0];
  112. more = barwidth;
  113. while (more) {
  114. if ((FIELD_BUFFER_SIZE/PAGE_SIZE) <= m) {
  115. SAM("ERROR: bad m reached\n");
  116. return;
  117. }
  118. if (PAGE_SIZE < n) {
  119. SAM("ERROR: bad n reached\n");
  120. return;
  121. }
  122. if (0 > more) {
  123. SAM("ERROR: internal fault\n");
  124. return;
  125. }
  126. much = PAGE_SIZE - n;
  127. if (much > more)
  128. much = more;
  129. pfield_buffer = &peasycap->field_buffer[k][m];
  130. p2 = pfield_buffer->pgo + n;
  131. memcpy(p2, p1, much);
  132. p1 += much;
  133. n += much;
  134. more -= much;
  135. if (PAGE_SIZE == n) {
  136. m++;
  137. n = 0;
  138. }
  139. }
  140. }
  141. }
  142. return;
  143. }