pwc-uncompress.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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;
  31. void *yuv, *image;
  32. u16 *src;
  33. u16 *dsty, *dstu, *dstv;
  34. image = vb2_plane_vaddr(&fbuf->vb.vb2_buf, 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.vb2_buf, 0,
  48. pdev->frame_size + sizeof(struct pwc_raw_frame));
  49. return 0;
  50. }
  51. vb2_set_plane_payload(&fbuf->vb.vb2_buf, 0,
  52. pdev->width * pdev->height * 3 / 2);
  53. if (pdev->vbandlength == 0) {
  54. /* Uncompressed mode.
  55. *
  56. * We do some byte shuffling here to go from the
  57. * native format to YUV420P.
  58. */
  59. src = (u16 *)yuv;
  60. n = pdev->width * pdev->height;
  61. dsty = (u16 *)(image);
  62. dstu = (u16 *)(image + n);
  63. dstv = (u16 *)(image + n + n / 4);
  64. for (line = 0; line < pdev->height; line++) {
  65. for (col = 0; col < pdev->width; col += 4) {
  66. *dsty++ = *src++;
  67. *dsty++ = *src++;
  68. if (line & 1)
  69. *dstv++ = *src++;
  70. else
  71. *dstu++ = *src++;
  72. }
  73. }
  74. return 0;
  75. }
  76. /*
  77. * Compressed;
  78. * the decompressor routines will write the data in planar format
  79. * immediately.
  80. */
  81. if (DEVICE_USE_CODEC1(pdev->type)) {
  82. /* TODO & FIXME */
  83. PWC_ERROR("This chipset is not supported for now\n");
  84. return -ENXIO; /* No such device or address: missing decompressor */
  85. } else {
  86. pwc_dec23_decompress(pdev, yuv, image);
  87. }
  88. return 0;
  89. }