pwc-misc.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* Linux driver for Philips webcam
  2. Various miscellaneous functions and tables.
  3. (C) 1999-2003 Nemosoft Unv.
  4. (C) 2004 Luc Saillard (luc@saillard.org)
  5. NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx
  6. driver and thus may have bugs that are not present in the original version.
  7. Please send bug reports and support requests to <luc@saillard.org>.
  8. The decompression routines have been implemented by reverse-engineering the
  9. Nemosoft binary pwcx module. Caveat emptor.
  10. This program is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation; either version 2 of the License, or
  13. (at your option) any later version.
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. GNU General Public License for more details.
  18. You should have received a copy of the GNU General Public License
  19. along with this program; if not, write to the Free Software
  20. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <linux/slab.h>
  23. #include "pwc.h"
  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. /* x,y -> PSZ_ */
  34. int pwc_decode_size(struct pwc_device *pdev, int width, int height)
  35. {
  36. int i, find;
  37. /* Make sure we don't go beyond our max size.
  38. NB: we have different limits for RAW and normal modes. In case
  39. you don't have the decompressor loaded or use RAW mode,
  40. the maximum viewable size is smaller.
  41. */
  42. if (pdev->vpalette == VIDEO_PALETTE_RAW)
  43. {
  44. if (width > pdev->abs_max.x || height > pdev->abs_max.y)
  45. {
  46. Debug("VIDEO_PALETTE_RAW: going beyond abs_max.\n");
  47. return -1;
  48. }
  49. }
  50. else
  51. {
  52. if (width > pdev->view_max.x || height > pdev->view_max.y)
  53. {
  54. Debug("VIDEO_PALETTE_ not RAW: going beyond view_max.\n");
  55. return -1;
  56. }
  57. }
  58. /* Find the largest size supported by the camera that fits into the
  59. requested size.
  60. */
  61. find = -1;
  62. for (i = 0; i < PSZ_MAX; i++) {
  63. if (pdev->image_mask & (1 << i)) {
  64. if (pwc_image_sizes[i].x <= width && pwc_image_sizes[i].y <= height)
  65. find = i;
  66. }
  67. }
  68. return find;
  69. }
  70. /* initialize variables depending on type and decompressor*/
  71. void pwc_construct(struct pwc_device *pdev)
  72. {
  73. switch(pdev->type) {
  74. case 645:
  75. case 646:
  76. pdev->view_min.x = 128;
  77. pdev->view_min.y = 96;
  78. pdev->view_max.x = 352;
  79. pdev->view_max.y = 288;
  80. pdev->abs_max.x = 352;
  81. pdev->abs_max.y = 288;
  82. pdev->image_mask = 1 << PSZ_SQCIF | 1 << PSZ_QCIF | 1 << PSZ_CIF;
  83. pdev->vcinterface = 2;
  84. pdev->vendpoint = 4;
  85. pdev->frame_header_size = 0;
  86. pdev->frame_trailer_size = 0;
  87. break;
  88. case 675:
  89. case 680:
  90. case 690:
  91. pdev->view_min.x = 128;
  92. pdev->view_min.y = 96;
  93. /* Anthill bug #38: PWC always reports max size, even without PWCX */
  94. pdev->view_max.x = 640;
  95. pdev->view_max.y = 480;
  96. pdev->image_mask = 1 << PSZ_SQCIF | 1 << PSZ_QSIF | 1 << PSZ_QCIF | 1 << PSZ_SIF | 1 << PSZ_CIF | 1 << PSZ_VGA;
  97. pdev->abs_max.x = 640;
  98. pdev->abs_max.y = 480;
  99. pdev->vcinterface = 3;
  100. pdev->vendpoint = 4;
  101. pdev->frame_header_size = 0;
  102. pdev->frame_trailer_size = 0;
  103. break;
  104. case 720:
  105. case 730:
  106. case 740:
  107. case 750:
  108. pdev->view_min.x = 160;
  109. pdev->view_min.y = 120;
  110. pdev->view_max.x = 640;
  111. pdev->view_max.y = 480;
  112. pdev->image_mask = 1 << PSZ_QSIF | 1 << PSZ_SIF | 1 << PSZ_VGA;
  113. pdev->abs_max.x = 640;
  114. pdev->abs_max.y = 480;
  115. pdev->vcinterface = 3;
  116. pdev->vendpoint = 5;
  117. pdev->frame_header_size = TOUCAM_HEADER_SIZE;
  118. pdev->frame_trailer_size = TOUCAM_TRAILER_SIZE;
  119. break;
  120. }
  121. Debug("type = %d\n",pdev->type);
  122. pdev->vpalette = VIDEO_PALETTE_YUV420P; /* default */
  123. pdev->view_min.size = pdev->view_min.x * pdev->view_min.y;
  124. pdev->view_max.size = pdev->view_max.x * pdev->view_max.y;
  125. /* length of image, in YUV format; always allocate enough memory. */
  126. pdev->len_per_image = (pdev->abs_max.x * pdev->abs_max.y * 3) / 2;
  127. }