1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Linux driver for Philips webcam
3 Decompression frontend.
4 (C) 1999-2003 Nemosoft Unv.
7 NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx
8 driver and thus may have bugs that are not present in the original version.
10 The decompression routines have been implemented by reverse-engineering the
11 Nemosoft binary pwcx module. Caveat emptor.
17 #include <asm/current.h>
18 #include <asm/types.h>
22 #include "pwc-dec23.h"
24 int pwc_decompress(struct pwc_device *pdev, struct pwc_frame_buf *fbuf)
29 u16 *dsty, *dstu, *dstv;
31 image = vb2_plane_vaddr(&fbuf->vb.vb2_buf, 0);
33 yuv = fbuf->data + pdev->frame_header_size; /* Skip header */
35 /* Raw format; that's easy... */
36 if (pdev->pixfmt != V4L2_PIX_FMT_YUV420)
38 struct pwc_raw_frame *raw_frame = image;
39 raw_frame->type = cpu_to_le16(pdev->type);
40 raw_frame->vbandlength = cpu_to_le16(pdev->vbandlength);
41 /* cmd_buf is always 4 bytes, but sometimes, only the
42 * first 3 bytes is filled (Nala case). We can
43 * determine this using the type of the webcam */
44 memcpy(raw_frame->cmd, pdev->cmd_buf, 4);
45 memcpy(raw_frame+1, yuv, pdev->frame_size);
46 vb2_set_plane_payload(&fbuf->vb.vb2_buf, 0,
47 pdev->frame_size + sizeof(struct pwc_raw_frame));
51 vb2_set_plane_payload(&fbuf->vb.vb2_buf, 0,
52 pdev->width * pdev->height * 3 / 2);
54 if (pdev->vbandlength == 0) {
57 * We do some byte shuffling here to go from the
58 * native format to YUV420P.
61 n = pdev->width * pdev->height;
62 dsty = (u16 *)(image);
63 dstu = (u16 *)(image + n);
64 dstv = (u16 *)(image + n + n / 4);
66 for (line = 0; line < pdev->height; line++) {
67 for (col = 0; col < pdev->width; col += 4) {
82 * the decompressor routines will write the data in planar format
85 if (DEVICE_USE_CODEC1(pdev->type)) {
88 PWC_ERROR("This chipset is not supported for now\n");
89 return -ENXIO; /* No such device or address: missing decompressor */
92 pwc_dec23_decompress(pdev, yuv, image);