Commit 1c657a99 authored by Trent Piepho's avatar Trent Piepho Committed by Mauro Carvalho Chehab

V4L/DVB (11908): w8968cf: Use v4l bounding/alignment function

The v4l function has a better algorithm for aligning image size.

The existing code was casting pointers to u32 and to unsigned int into
pointers to u16.  This could mess up if someone passed in an image size
greater than 65,535 and on big-endian platforms it won't work at all.

The existing bounding code would shrink an image if it was too big, but
returned ERANGE if it was too small.  The code will not shrink or expand as
necessary.
Signed-off-by: default avatarTrent Piepho <xyzzy@speakeasy.org>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 4b89945e
...@@ -460,7 +460,7 @@ static int w9968cf_set_picture(struct w9968cf_device*, struct video_picture); ...@@ -460,7 +460,7 @@ static int w9968cf_set_picture(struct w9968cf_device*, struct video_picture);
static int w9968cf_set_window(struct w9968cf_device*, struct video_window); static int w9968cf_set_window(struct w9968cf_device*, struct video_window);
static int w9968cf_postprocess_frame(struct w9968cf_device*, static int w9968cf_postprocess_frame(struct w9968cf_device*,
struct w9968cf_frame_t*); struct w9968cf_frame_t*);
static int w9968cf_adjust_window_size(struct w9968cf_device*, u16* w, u16* h); static int w9968cf_adjust_window_size(struct w9968cf_device*, u32 *w, u32 *h);
static void w9968cf_init_framelist(struct w9968cf_device*); static void w9968cf_init_framelist(struct w9968cf_device*);
static void w9968cf_push_frame(struct w9968cf_device*, u8 f_num); static void w9968cf_push_frame(struct w9968cf_device*, u8 f_num);
static void w9968cf_pop_frame(struct w9968cf_device*,struct w9968cf_frame_t**); static void w9968cf_pop_frame(struct w9968cf_device*,struct w9968cf_frame_t**);
...@@ -1763,8 +1763,7 @@ w9968cf_set_window(struct w9968cf_device* cam, struct video_window win) ...@@ -1763,8 +1763,7 @@ w9968cf_set_window(struct w9968cf_device* cam, struct video_window win)
#define UNSC(x) ((x) >> 10) #define UNSC(x) ((x) >> 10)
/* Make sure we are using a supported resolution */ /* Make sure we are using a supported resolution */
if ((err = w9968cf_adjust_window_size(cam, (u16*)&win.width, if ((err = w9968cf_adjust_window_size(cam, &win.width, &win.height)))
(u16*)&win.height)))
goto error; goto error;
/* Scaling factors */ /* Scaling factors */
...@@ -1914,12 +1913,9 @@ error: ...@@ -1914,12 +1913,9 @@ error:
Return 0 on success, -1 otherwise. Return 0 on success, -1 otherwise.
--------------------------------------------------------------------------*/ --------------------------------------------------------------------------*/
static int static int
w9968cf_adjust_window_size(struct w9968cf_device* cam, u16* width, u16* height) w9968cf_adjust_window_size(struct w9968cf_device *cam, u32 *width, u32 *height)
{ {
u16 maxw, maxh; unsigned int maxw, maxh, align;
if ((*width < cam->minwidth) || (*height < cam->minheight))
return -ERANGE;
maxw = cam->upscaling && !(cam->vpp_flag & VPP_DECOMPRESSION) && maxw = cam->upscaling && !(cam->vpp_flag & VPP_DECOMPRESSION) &&
w9968cf_vpp ? max((u16)W9968CF_MAX_WIDTH, cam->maxwidth) w9968cf_vpp ? max((u16)W9968CF_MAX_WIDTH, cam->maxwidth)
...@@ -1927,16 +1923,10 @@ w9968cf_adjust_window_size(struct w9968cf_device* cam, u16* width, u16* height) ...@@ -1927,16 +1923,10 @@ w9968cf_adjust_window_size(struct w9968cf_device* cam, u16* width, u16* height)
maxh = cam->upscaling && !(cam->vpp_flag & VPP_DECOMPRESSION) && maxh = cam->upscaling && !(cam->vpp_flag & VPP_DECOMPRESSION) &&
w9968cf_vpp ? max((u16)W9968CF_MAX_HEIGHT, cam->maxheight) w9968cf_vpp ? max((u16)W9968CF_MAX_HEIGHT, cam->maxheight)
: cam->maxheight; : cam->maxheight;
align = (cam->vpp_flag & VPP_DECOMPRESSION) ? 4 : 0;
if (*width > maxw) v4l_bound_align_image(width, cam->minwidth, maxw, align,
*width = maxw; height, cam->minheight, maxh, align, 0);
if (*height > maxh)
*height = maxh;
if (cam->vpp_flag & VPP_DECOMPRESSION) {
*width &= ~15L; /* multiple of 16 */
*height &= ~15L;
}
PDBGG("Window size adjusted w=%u, h=%u ", *width, *height) PDBGG("Window size adjusted w=%u, h=%u ", *width, *height)
...@@ -3043,8 +3033,8 @@ static long w9968cf_v4l_ioctl(struct file *filp, ...@@ -3043,8 +3033,8 @@ static long w9968cf_v4l_ioctl(struct file *filp,
if (win.clipcount != 0 || win.flags != 0) if (win.clipcount != 0 || win.flags != 0)
return -EINVAL; return -EINVAL;
if ((err = w9968cf_adjust_window_size(cam, (u16*)&win.width, if ((err = w9968cf_adjust_window_size(cam, &win.width,
(u16*)&win.height))) { &win.height))) {
DBG(4, "Resolution not supported (%ux%u). " DBG(4, "Resolution not supported (%ux%u). "
"VIDIOCSWIN failed", win.width, win.height) "VIDIOCSWIN failed", win.width, win.height)
return err; return err;
...@@ -3116,6 +3106,7 @@ static long w9968cf_v4l_ioctl(struct file *filp, ...@@ -3116,6 +3106,7 @@ static long w9968cf_v4l_ioctl(struct file *filp,
{ {
struct video_mmap mmap; struct video_mmap mmap;
struct w9968cf_frame_t* fr; struct w9968cf_frame_t* fr;
u32 w, h;
int err = 0; int err = 0;
if (copy_from_user(&mmap, arg, sizeof(mmap))) if (copy_from_user(&mmap, arg, sizeof(mmap)))
...@@ -3164,8 +3155,10 @@ static long w9968cf_v4l_ioctl(struct file *filp, ...@@ -3164,8 +3155,10 @@ static long w9968cf_v4l_ioctl(struct file *filp,
} }
} }
if ((err = w9968cf_adjust_window_size(cam, (u16*)&mmap.width, w = mmap.width; h = mmap.height;
(u16*)&mmap.height))) { err = w9968cf_adjust_window_size(cam, &w, &h);
mmap.width = w; mmap.height = h;
if (err) {
DBG(4, "Resolution not supported (%dx%d). " DBG(4, "Resolution not supported (%dx%d). "
"VIDIOCMCAPTURE failed", "VIDIOCMCAPTURE failed",
mmap.width, mmap.height) mmap.width, mmap.height)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment