pwc-misc.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 int pwc_image_sizes[PSZ_MAX][2] =
  24. {
  25. { 128, 96 }, /* sqcif */
  26. { 160, 120 }, /* qsif */
  27. { 176, 144 }, /* qcif */
  28. { 320, 240 }, /* sif */
  29. { 352, 288 }, /* cif */
  30. { 640, 480 }, /* vga */
  31. };
  32. /* x,y -> PSZ_ */
  33. int pwc_get_size(struct pwc_device *pdev, int width, int height)
  34. {
  35. int i;
  36. /* Find the largest size supported by the camera that fits into the
  37. requested size. */
  38. for (i = PSZ_MAX - 1; i >= 0; i--) {
  39. if (!(pdev->image_mask & (1 << i)))
  40. continue;
  41. if (pwc_image_sizes[i][0] <= width &&
  42. pwc_image_sizes[i][1] <= height)
  43. return i;
  44. }
  45. /* No mode found, return the smallest mode we have */
  46. for (i = 0; i < PSZ_MAX; i++) {
  47. if (pdev->image_mask & (1 << i))
  48. return i;
  49. }
  50. /* Never reached there always is atleast one supported mode */
  51. return 0;
  52. }
  53. /* initialize variables depending on type and decompressor */
  54. void pwc_construct(struct pwc_device *pdev)
  55. {
  56. if (DEVICE_USE_CODEC1(pdev->type)) {
  57. pdev->image_mask = 1 << PSZ_SQCIF | 1 << PSZ_QCIF | 1 << PSZ_CIF;
  58. pdev->vcinterface = 2;
  59. pdev->vendpoint = 4;
  60. pdev->frame_header_size = 0;
  61. pdev->frame_trailer_size = 0;
  62. } else if (DEVICE_USE_CODEC3(pdev->type)) {
  63. pdev->image_mask = 1 << PSZ_QSIF | 1 << PSZ_SIF | 1 << PSZ_VGA;
  64. pdev->vcinterface = 3;
  65. pdev->vendpoint = 5;
  66. pdev->frame_header_size = TOUCAM_HEADER_SIZE;
  67. pdev->frame_trailer_size = TOUCAM_TRAILER_SIZE;
  68. } else /* if (DEVICE_USE_CODEC2(pdev->type)) */ {
  69. pdev->image_mask = 1 << PSZ_SQCIF | 1 << PSZ_QSIF | 1 << PSZ_QCIF | 1 << PSZ_SIF | 1 << PSZ_CIF | 1 << PSZ_VGA;
  70. pdev->vcinterface = 3;
  71. pdev->vendpoint = 4;
  72. pdev->frame_header_size = 0;
  73. pdev->frame_trailer_size = 0;
  74. }
  75. }