pwc-uncompress.c 4.0 KB

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