media: ov5670: Use v4l2_find_nearest_size
Use v4l2_find_nearest_size instead of a driver specific function to find nearest matching size. Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
This commit is contained in:
parent
227b183dcb
commit
894de53b49
|
@ -2180,36 +2180,6 @@ static int ov5670_enum_frame_size(struct v4l2_subdev *sd,
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* Calculate resolution distance */
|
||||
static int ov5670_get_reso_dist(const struct ov5670_mode *mode,
|
||||
struct v4l2_mbus_framefmt *framefmt)
|
||||
{
|
||||
return abs(mode->width - framefmt->width) +
|
||||
abs(mode->height - framefmt->height);
|
||||
}
|
||||
|
||||
/* Find the closest supported resolution to the requested resolution */
|
||||
static const struct ov5670_mode *ov5670_find_best_fit(
|
||||
struct ov5670 *ov5670,
|
||||
struct v4l2_subdev_format *fmt)
|
||||
{
|
||||
struct v4l2_mbus_framefmt *framefmt = &fmt->format;
|
||||
int dist;
|
||||
int cur_best_fit = 0;
|
||||
int cur_best_fit_dist = -1;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(supported_modes); i++) {
|
||||
dist = ov5670_get_reso_dist(&supported_modes[i], framefmt);
|
||||
if (cur_best_fit_dist == -1 || dist < cur_best_fit_dist) {
|
||||
cur_best_fit_dist = dist;
|
||||
cur_best_fit = i;
|
||||
}
|
||||
}
|
||||
|
||||
return &supported_modes[cur_best_fit];
|
||||
}
|
||||
|
||||
static void ov5670_update_pad_format(const struct ov5670_mode *mode,
|
||||
struct v4l2_subdev_format *fmt)
|
||||
{
|
||||
|
@ -2259,7 +2229,8 @@ static int ov5670_set_pad_format(struct v4l2_subdev *sd,
|
|||
|
||||
fmt->format.code = MEDIA_BUS_FMT_SGRBG10_1X10;
|
||||
|
||||
mode = ov5670_find_best_fit(ov5670, fmt);
|
||||
mode = v4l2_find_nearest_size(supported_modes, width, height,
|
||||
fmt->format.width, fmt->format.height);
|
||||
ov5670_update_pad_format(mode, fmt);
|
||||
if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
|
||||
*v4l2_subdev_get_try_format(sd, cfg, fmt->pad) = fmt->format;
|
||||
|
|
Loading…
Reference in New Issue