pwc-uncompress.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* Linux driver for Philips webcam
  2. Decompression frontend.
  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. vim: set ts=8:
  22. */
  23. #include <asm/current.h>
  24. #include <asm/types.h>
  25. #include "pwc.h"
  26. #include "pwc-uncompress.h"
  27. #include "pwc-dec1.h"
  28. #include "pwc-dec23.h"
  29. int pwc_decompress(struct pwc_device *pdev)
  30. {
  31. struct pwc_frame_buf *fbuf;
  32. int n, line, col, stride;
  33. void *yuv, *image;
  34. u16 *src;
  35. u16 *dsty, *dstu, *dstv;
  36. if (pdev == NULL)
  37. return -EFAULT;
  38. fbuf = pdev->read_frame;
  39. if (fbuf == NULL)
  40. return -EFAULT;
  41. image = pdev->image_data;
  42. image += pdev->images[pdev->fill_image].offset;
  43. yuv = fbuf->data + pdev->frame_header_size; /* Skip header */
  44. /* Raw format; that's easy... */
  45. if (pdev->vpalette == VIDEO_PALETTE_RAW)
  46. {
  47. struct pwc_raw_frame *raw_frame = image;
  48. raw_frame->type = cpu_to_le16(pdev->type);
  49. raw_frame->vbandlength = cpu_to_le16(pdev->vbandlength);
  50. /* cmd_buf is always 4 bytes, but sometimes, only the
  51. * first 3 bytes is filled (Nala case). We can
  52. * determine this using the type of the webcam */
  53. memcpy(raw_frame->cmd, pdev->cmd_buf, 4);
  54. memcpy(raw_frame+1, yuv, pdev->frame_size);
  55. return 0;
  56. }
  57. if (pdev->vbandlength == 0) {
  58. /* Uncompressed mode.
  59. * We copy the data into the output buffer, using the viewport
  60. * size (which may be larger than the image size).
  61. * Unfortunately we have to do a bit of byte stuffing to get
  62. * the desired output format/size.
  63. *
  64. * We do some byte shuffling here to go from the
  65. * native format to YUV420P.
  66. */
  67. src = (u16 *)yuv;
  68. n = pdev->view.x * pdev->view.y;
  69. /* offset in Y plane */
  70. stride = pdev->view.x * pdev->offset.y + pdev->offset.x;
  71. dsty = (u16 *)(image + stride);
  72. /* offsets in U/V planes */
  73. stride = pdev->view.x * pdev->offset.y / 4 + pdev->offset.x / 2;
  74. dstu = (u16 *)(image + n + stride);
  75. dstv = (u16 *)(image + n + n / 4 + stride);
  76. /* increment after each line */
  77. stride = (pdev->view.x - pdev->image.x) / 2; /* u16 is 2 bytes */
  78. for (line = 0; line < pdev->image.y; line++) {
  79. for (col = 0; col < pdev->image.x; col += 4) {
  80. *dsty++ = *src++;
  81. *dsty++ = *src++;
  82. if (line & 1)
  83. *dstv++ = *src++;
  84. else
  85. *dstu++ = *src++;
  86. }
  87. dsty += stride;
  88. if (line & 1)
  89. dstv += (stride >> 1);
  90. else
  91. dstu += (stride >> 1);
  92. }
  93. return 0;
  94. }
  95. /*
  96. * Compressed;
  97. * the decompressor routines will write the data in planar format
  98. * immediately.
  99. */
  100. if (pdev->vsize == PSZ_VGA && pdev->vframes == 5 && pdev->vsnapshot) {
  101. PWC_ERROR("Mode Bayer is not supported for now\n");
  102. /* flags |= PWCX_FLAG_BAYER; */
  103. return -ENXIO; /* No such device or address: missing decompressor */
  104. }
  105. if (DEVICE_USE_CODEC1(pdev->type)) {
  106. /* TODO & FIXME */
  107. PWC_ERROR("This chipset is not supported for now\n");
  108. return -ENXIO; /* No such device or address: missing decompressor */
  109. } else {
  110. pwc_dec23_decompress(pdev, yuv, image, PWCX_FLAG_PLANAR);
  111. }
  112. return 0;
  113. }
  114. /* vim: set cino= formatoptions=croql cindent shiftwidth=8 tabstop=8: */