pwc-misc.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* Linux driver for Philips webcam
  2. Various miscellaneous functions and tables.
  3. (C) 1999-2003 Nemosoft Unv.
  4. (C) 2004-2006 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 "pwc.h"
  23. const struct pwc_coord pwc_image_sizes[PSZ_MAX] =
  24. {
  25. { 128, 96, 0 }, /* sqcif */
  26. { 160, 120, 0 }, /* qsif */
  27. { 176, 144, 0 }, /* qcif */
  28. { 320, 240, 0 }, /* sif */
  29. { 352, 288, 0 }, /* cif */
  30. { 640, 480, 0 }, /* vga */
  31. };
  32. /* x,y -> PSZ_ */
  33. int pwc_decode_size(struct pwc_device *pdev, int width, int height)
  34. {
  35. int i, find;
  36. /* Make sure we don't go beyond our max size.
  37. NB: we have different limits for RAW and normal modes. In case
  38. you don't have the decompressor loaded or use RAW mode,
  39. the maximum viewable size is smaller.
  40. */
  41. if (pdev->vpalette == VIDEO_PALETTE_RAW)
  42. {
  43. if (width > pdev->abs_max.x || height > pdev->abs_max.y)
  44. {
  45. PWC_DEBUG_SIZE("VIDEO_PALETTE_RAW: going beyond abs_max.\n");
  46. return -1;
  47. }
  48. }
  49. else
  50. {
  51. if (width > pdev->view_max.x || height > pdev->view_max.y)
  52. {
  53. PWC_DEBUG_SIZE("VIDEO_PALETTE_not RAW: going beyond view_max.\n");
  54. return -1;
  55. }
  56. }
  57. /* Find the largest size supported by the camera that fits into the
  58. requested size.
  59. */
  60. find = -1;
  61. for (i = 0; i < PSZ_MAX; i++) {
  62. if (pdev->image_mask & (1 << i)) {
  63. if (pwc_image_sizes[i].x <= width && pwc_image_sizes[i].y <= height)
  64. find = i;
  65. }
  66. }
  67. return find;
  68. }
  69. /* initialize variables depending on type and decompressor*/
  70. void pwc_construct(struct pwc_device *pdev)
  71. {
  72. if (DEVICE_USE_CODEC1(pdev->type)) {
  73. pdev->view_min.x = 128;
  74. pdev->view_min.y = 96;
  75. pdev->view_max.x = 352;
  76. pdev->view_max.y = 288;
  77. pdev->abs_max.x = 352;
  78. pdev->abs_max.y = 288;
  79. pdev->image_mask = 1 << PSZ_SQCIF | 1 << PSZ_QCIF | 1 << PSZ_CIF;
  80. pdev->vcinterface = 2;
  81. pdev->vendpoint = 4;
  82. pdev->frame_header_size = 0;
  83. pdev->frame_trailer_size = 0;
  84. } else if (DEVICE_USE_CODEC3(pdev->type)) {
  85. pdev->view_min.x = 160;
  86. pdev->view_min.y = 120;
  87. pdev->view_max.x = 640;
  88. pdev->view_max.y = 480;
  89. pdev->image_mask = 1 << PSZ_QSIF | 1 << PSZ_SIF | 1 << PSZ_VGA;
  90. pdev->abs_max.x = 640;
  91. pdev->abs_max.y = 480;
  92. pdev->vcinterface = 3;
  93. pdev->vendpoint = 5;
  94. pdev->frame_header_size = TOUCAM_HEADER_SIZE;
  95. pdev->frame_trailer_size = TOUCAM_TRAILER_SIZE;
  96. } else /* if (DEVICE_USE_CODEC2(pdev->type)) */ {
  97. pdev->view_min.x = 128;
  98. pdev->view_min.y = 96;
  99. /* Anthill bug #38: PWC always reports max size, even without PWCX */
  100. pdev->view_max.x = 640;
  101. pdev->view_max.y = 480;
  102. pdev->image_mask = 1 << PSZ_SQCIF | 1 << PSZ_QSIF | 1 << PSZ_QCIF | 1 << PSZ_SIF | 1 << PSZ_CIF | 1 << PSZ_VGA;
  103. pdev->abs_max.x = 640;
  104. pdev->abs_max.y = 480;
  105. pdev->vcinterface = 3;
  106. pdev->vendpoint = 4;
  107. pdev->frame_header_size = 0;
  108. pdev->frame_trailer_size = 0;
  109. }
  110. pdev->vpalette = VIDEO_PALETTE_YUV420P; /* default */
  111. pdev->view_min.size = pdev->view_min.x * pdev->view_min.y;
  112. pdev->view_max.size = pdev->view_max.x * pdev->view_max.y;
  113. /* length of image, in YUV format; always allocate enough memory. */
  114. pdev->len_per_image = PAGE_ALIGN((pdev->abs_max.x * pdev->abs_max.y * 3) / 2);
  115. }