Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /* Linux driver for Philips webcam
0003    Decompression frontend.
0004    (C) 1999-2003 Nemosoft Unv.
0005    (C) 2004-2006 Luc Saillard (luc@saillard.org)
0006 
0007    NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx
0008    driver and thus may have bugs that are not present in the original version.
0009    Please send bug reports and support requests to <luc@saillard.org>.
0010    The decompression routines have been implemented by reverse-engineering the
0011    Nemosoft binary pwcx module. Caveat emptor.
0012 */
0013 
0014 #include <asm/current.h>
0015 #include <asm/types.h>
0016 
0017 #include "pwc.h"
0018 #include "pwc-dec1.h"
0019 #include "pwc-dec23.h"
0020 
0021 int pwc_decompress(struct pwc_device *pdev, struct pwc_frame_buf *fbuf)
0022 {
0023     int n, line, col;
0024     void *yuv, *image;
0025     u16 *src;
0026     u16 *dsty, *dstu, *dstv;
0027 
0028     image = vb2_plane_vaddr(&fbuf->vb.vb2_buf, 0);
0029 
0030     yuv = fbuf->data + pdev->frame_header_size;  /* Skip header */
0031 
0032     /* Raw format; that's easy... */
0033     if (pdev->pixfmt != V4L2_PIX_FMT_YUV420)
0034     {
0035         struct pwc_raw_frame *raw_frame = image;
0036         raw_frame->type = cpu_to_le16(pdev->type);
0037         raw_frame->vbandlength = cpu_to_le16(pdev->vbandlength);
0038             /* cmd_buf is always 4 bytes, but sometimes, only the
0039              * first 3 bytes is filled (Nala case). We can
0040              * determine this using the type of the webcam */
0041         memcpy(raw_frame->cmd, pdev->cmd_buf, 4);
0042         memcpy(raw_frame+1, yuv, pdev->frame_size);
0043         vb2_set_plane_payload(&fbuf->vb.vb2_buf, 0,
0044             struct_size(raw_frame, rawframe, pdev->frame_size));
0045         return 0;
0046     }
0047 
0048     vb2_set_plane_payload(&fbuf->vb.vb2_buf, 0,
0049                   pdev->width * pdev->height * 3 / 2);
0050 
0051     if (pdev->vbandlength == 0) {
0052         /* Uncompressed mode.
0053          *
0054          * We do some byte shuffling here to go from the
0055          * native format to YUV420P.
0056          */
0057         src = (u16 *)yuv;
0058         n = pdev->width * pdev->height;
0059         dsty = (u16 *)(image);
0060         dstu = (u16 *)(image + n);
0061         dstv = (u16 *)(image + n + n / 4);
0062 
0063         for (line = 0; line < pdev->height; line++) {
0064             for (col = 0; col < pdev->width; col += 4) {
0065                 *dsty++ = *src++;
0066                 *dsty++ = *src++;
0067                 if (line & 1)
0068                     *dstv++ = *src++;
0069                 else
0070                     *dstu++ = *src++;
0071             }
0072         }
0073 
0074         return 0;
0075     }
0076 
0077     /*
0078      * Compressed;
0079      * the decompressor routines will write the data in planar format
0080      * immediately.
0081      */
0082     if (DEVICE_USE_CODEC1(pdev->type)) {
0083 
0084         /* TODO & FIXME */
0085         PWC_ERROR("This chipset is not supported for now\n");
0086         return -ENXIO; /* No such device or address: missing decompressor */
0087 
0088     } else {
0089         pwc_dec23_decompress(pdev, yuv, image);
0090     }
0091     return 0;
0092 }