]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
V4L/DVB (10711): zoran: fix TRY_FMT support
authorHans Verkuil <hverkuil@xs4all.nl>
Wed, 18 Feb 2009 20:11:17 +0000 (17:11 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Mon, 30 Mar 2009 15:42:56 +0000 (12:42 -0300)
Actually try to turn the format into something usable rather than just
rejecting it if it isn't perfect.

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/video/zoran/zoran_card.c
drivers/media/video/zoran/zoran_card.h
drivers/media/video/zoran/zoran_driver.c

index 18834b18435b307d51f7a8270f0c7b702df3c3fc..774717bf43cce26cce80a4b6280c246a59cab192 100644 (file)
@@ -835,7 +835,8 @@ zoran_unregister_i2c (struct zoran *zr)
 
 int
 zoran_check_jpg_settings (struct zoran              *zr,
-                         struct zoran_jpg_settings *settings)
+                         struct zoran_jpg_settings *settings,
+                         int try)
 {
        int err = 0, err0 = 0;
 
@@ -900,35 +901,61 @@ zoran_check_jpg_settings (struct zoran              *zr,
                /* We have to check the data the user has set */
 
                if (settings->HorDcm != 1 && settings->HorDcm != 2 &&
-                   (zr->card.type == DC10_new || settings->HorDcm != 4))
+                   (zr->card.type == DC10_new || settings->HorDcm != 4)) {
+                       settings->HorDcm = clamp(settings->HorDcm, 1, 2);
                        err0++;
-               if (settings->VerDcm != 1 && settings->VerDcm != 2)
+               }
+               if (settings->VerDcm != 1 && settings->VerDcm != 2) {
+                       settings->VerDcm = clamp(settings->VerDcm, 1, 2);
                        err0++;
-               if (settings->TmpDcm != 1 && settings->TmpDcm != 2)
+               }
+               if (settings->TmpDcm != 1 && settings->TmpDcm != 2) {
+                       settings->TmpDcm = clamp(settings->TmpDcm, 1, 2);
                        err0++;
+               }
                if (settings->field_per_buff != 1 &&
-                   settings->field_per_buff != 2)
+                   settings->field_per_buff != 2) {
+                       settings->field_per_buff = clamp(settings->field_per_buff, 1, 2);
                        err0++;
-               if (settings->img_x < 0)
+               }
+               if (settings->img_x < 0) {
+                       settings->img_x = 0;
                        err0++;
-               if (settings->img_y < 0)
+               }
+               if (settings->img_y < 0) {
+                       settings->img_y = 0;
                        err0++;
-               if (settings->img_width < 0)
+               }
+               if (settings->img_width < 0 || settings->img_width > BUZ_MAX_WIDTH) {
+                       settings->img_width = clamp(settings->img_width, 0, (int)BUZ_MAX_WIDTH);
                        err0++;
-               if (settings->img_height < 0)
+               }
+               if (settings->img_height < 0 || settings->img_height > BUZ_MAX_HEIGHT / 2) {
+                       settings->img_height = clamp(settings->img_height, 0, BUZ_MAX_HEIGHT / 2);
                        err0++;
-               if (settings->img_x + settings->img_width > BUZ_MAX_WIDTH)
+               }
+               if (settings->img_x + settings->img_width > BUZ_MAX_WIDTH) {
+                       settings->img_x = BUZ_MAX_WIDTH - settings->img_width;
+                       err0++;
+               }
+               if (settings->img_y + settings->img_height > BUZ_MAX_HEIGHT / 2) {
+                       settings->img_y = BUZ_MAX_HEIGHT / 2 - settings->img_height;
                        err0++;
-               if (settings->img_y + settings->img_height > BUZ_MAX_HEIGHT / 2)
+               }
+               if (settings->img_width % (16 * settings->HorDcm) != 0) {
+                       settings->img_width -= settings->img_width % (16 * settings->HorDcm);
+                       if (settings->img_width == 0)
+                               settings->img_width = 16 * settings->HorDcm;
+                       err0++;
+               }
+               if (settings->img_height % (8 * settings->VerDcm) != 0) {
+                       settings->img_height -= settings->img_height % (8 * settings->VerDcm);
+                       if (settings->img_height == 0)
+                               settings->img_height = 8 * settings->VerDcm;
                        err0++;
-               if (settings->HorDcm && settings->VerDcm) {
-                       if (settings->img_width % (16 * settings->HorDcm) != 0)
-                               err0++;
-                       if (settings->img_height % (8 * settings->VerDcm) != 0)
-                               err0++;
                }
 
-               if (err0) {
+               if (!try && err0) {
                        dprintk(1,
                                KERN_ERR
                                "%s: check_jpg_settings() - error in params for decimation = 0\n",
@@ -1018,7 +1045,7 @@ zoran_open_init_params (struct zoran *zr)
               sizeof(zr->jpg_settings.jpg_comp.COM_data));
        zr->jpg_settings.jpg_comp.jpeg_markers =
            JPEG_MARKER_DHT | JPEG_MARKER_DQT;
-       i = zoran_check_jpg_settings(zr, &zr->jpg_settings);
+       i = zoran_check_jpg_settings(zr, &zr->jpg_settings, 0);
        if (i)
                dprintk(1,
                        KERN_ERR
index 4507bdc5e3385d27be3ef23652390c66c28b8056..4936fead73e8693cfab4a2ad7ebb9111be92a1e7 100644 (file)
@@ -44,7 +44,8 @@ extern int zr36067_debug;
 extern struct video_device zoran_template;
 
 extern int zoran_check_jpg_settings(struct zoran *zr,
-                                   struct zoran_jpg_settings *settings);
+                                   struct zoran_jpg_settings *settings,
+                                   int try);
 extern void zoran_open_init_params(struct zoran *zr);
 extern void zoran_vdev_release(struct video_device *vdev);
 
index 0cce652011ff0bc351c1d332416fc99435e6cc69..cdfd3cc05151e7a2b786c4ed3cbe23018ebecb4f 100644 (file)
@@ -1797,7 +1797,7 @@ static long zoran_default(struct file *file, void *__fh, int cmd, void *arg)
 
                /* Check the params first before overwriting our
                 * nternal values */
-               if (zoran_check_jpg_settings(zr, &settings)) {
+               if (zoran_check_jpg_settings(zr, &settings, 0)) {
                        res = -EINVAL;
                        goto sparams_unlock_and_return;
                }
@@ -2205,7 +2205,7 @@ static int zoran_try_fmt_vid_out(struct file *file, void *__fh,
                settings.field_per_buff = 1;
 
        /* check */
-       res = zoran_check_jpg_settings(zr, &settings);
+       res = zoran_check_jpg_settings(zr, &settings, 1);
        if (res)
                goto tryfmt_unlock_and_return;
 
@@ -2231,6 +2231,7 @@ static int zoran_try_fmt_vid_cap(struct file *file, void *__fh,
 {
        struct zoran_fh *fh = __fh;
        struct zoran *zr = fh->zr;
+       int bpp;
        int i;
 
        if (fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_MJPEG)
@@ -2247,6 +2248,8 @@ static int zoran_try_fmt_vid_cap(struct file *file, void *__fh,
                return -EINVAL;
        }
 
+       bpp = (zoran_formats[i].depth + 7) / 8;
+       fmt->fmt.pix.width &= ~((bpp == 2) ? 1 : 3);
        if (fmt->fmt.pix.width > BUZ_MAX_WIDTH)
                fmt->fmt.pix.width = BUZ_MAX_WIDTH;
        if (fmt->fmt.pix.width < BUZ_MIN_WIDTH)
@@ -2334,8 +2337,16 @@ static int zoran_s_fmt_vid_out(struct file *file, void *__fh,
        else
                settings.field_per_buff = 1;
 
+       if (settings.HorDcm > 1) {
+               settings.img_x = (BUZ_MAX_WIDTH == 720) ? 8 : 0;
+               settings.img_width = (BUZ_MAX_WIDTH == 720) ? 704 : BUZ_MAX_WIDTH;
+       } else {
+               settings.img_x = 0;
+               settings.img_width = BUZ_MAX_WIDTH;
+       }
+
        /* check */
-       res = zoran_check_jpg_settings(zr, &settings);
+       res = zoran_check_jpg_settings(zr, &settings, 0);
        if (res)
                goto sfmtjpg_unlock_and_return;
 
@@ -3216,7 +3227,7 @@ static int zoran_s_crop(struct file *file, void *__fh, struct v4l2_crop *crop)
        settings.img_height = crop->c.height;
 
        /* check validity */
-       res = zoran_check_jpg_settings(zr, &settings);
+       res = zoran_check_jpg_settings(zr, &settings, 0);
        if (res)
                goto scrop_unlock_and_return;
 
@@ -3278,7 +3289,7 @@ static int zoran_s_jpegcomp(struct file *file, void *__fh,
                goto sjpegc_unlock_and_return;
        }
 
-       res = zoran_check_jpg_settings(zr, &settings);
+       res = zoran_check_jpg_settings(zr, &settings, 0);
        if (res)
                goto sjpegc_unlock_and_return;
        if (!fh->jpg_buffers.allocated)