1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Linux driver for Philips webcam
3 Decompression frontend.
4 (C) 1999-2003 Nemosoft Unv.
5 (C) 2004-2006 Luc Saillard (luc@saillard.org)
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.
9 Please send bug reports and support requests to <luc@saillard.org>.
10 The decompression routines have been implemented by reverse-engineering the
11 Nemosoft binary pwcx module. Caveat emptor.
14 #include <asm/current.h>
15 #include <asm/types.h>
19 #include "pwc-dec23.h"
21 int pwc_decompress(struct pwc_device
*pdev
, struct pwc_frame_buf
*fbuf
)
26 u16
*dsty
, *dstu
, *dstv
;
28 image
= vb2_plane_vaddr(&fbuf
->vb
.vb2_buf
, 0);
30 yuv
= fbuf
->data
+ pdev
->frame_header_size
; /* Skip header */
32 /* Raw format; that's easy... */
33 if (pdev
->pixfmt
!= V4L2_PIX_FMT_YUV420
)
35 struct pwc_raw_frame
*raw_frame
= image
;
36 raw_frame
->type
= cpu_to_le16(pdev
->type
);
37 raw_frame
->vbandlength
= cpu_to_le16(pdev
->vbandlength
);
38 /* cmd_buf is always 4 bytes, but sometimes, only the
39 * first 3 bytes is filled (Nala case). We can
40 * determine this using the type of the webcam */
41 memcpy(raw_frame
->cmd
, pdev
->cmd_buf
, 4);
42 memcpy(raw_frame
->rawframe
, yuv
, pdev
->frame_size
);
43 vb2_set_plane_payload(&fbuf
->vb
.vb2_buf
, 0,
44 struct_size(raw_frame
, rawframe
, pdev
->frame_size
));
48 vb2_set_plane_payload(&fbuf
->vb
.vb2_buf
, 0,
49 pdev
->width
* pdev
->height
* 3 / 2);
51 if (pdev
->vbandlength
== 0) {
54 * We do some byte shuffling here to go from the
55 * native format to YUV420P.
58 n
= pdev
->width
* pdev
->height
;
59 dsty
= (u16
*)(image
);
60 dstu
= (u16
*)(image
+ n
);
61 dstv
= (u16
*)(image
+ n
+ n
/ 4);
63 for (line
= 0; line
< pdev
->height
; line
++) {
64 for (col
= 0; col
< pdev
->width
; col
+= 4) {
79 * the decompressor routines will write the data in planar format
82 if (DEVICE_USE_CODEC1(pdev
->type
)) {
85 PWC_ERROR("This chipset is not supported for now\n");
86 return -ENXIO
; /* No such device or address: missing decompressor */
89 pwc_dec23_decompress(pdev
, yuv
, image
);