summaryrefslogtreecommitdiffstats
path: root/drivers/media/v4l2-core
diff options
context:
space:
mode:
authorSakari Ailus <sakari.ailus@linux.intel.com>2018-02-23 10:50:14 +0100
committerMauro Carvalho Chehab <mchehab@s-opensource.com>2018-03-21 16:18:52 +0100
commit95ce9c28601afc5da0c11792601ad32dd14cdd44 (patch)
tree8e30f3685fe841a55833a753453c92f6b98ce3d9 /drivers/media/v4l2-core
parentmedia: imon: rename protocol from other to imon (diff)
downloadlinux-95ce9c28601afc5da0c11792601ad32dd14cdd44.tar.xz
linux-95ce9c28601afc5da0c11792601ad32dd14cdd44.zip
media: v4l: common: Add a function to obtain best size from a list
Add a function (as well as a helper macro) to obtain the best size in a list of device specific sizes. This helps writing drivers as well as aligns interface behaviour across drivers. The struct in which this information is contained in is typically specific to the driver, therefore the existing function v4l2_find_nearest_format() does not address the need. Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Acked-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Diffstat (limited to 'drivers/media/v4l2-core')
-rw-r--r--drivers/media/v4l2-core/v4l2-common.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c
index 96c1b31de9e3..9b65529dfaf6 100644
--- a/drivers/media/v4l2-core/v4l2-common.c
+++ b/drivers/media/v4l2-core/v4l2-common.c
@@ -383,6 +383,36 @@ v4l2_find_nearest_format(const struct v4l2_frmsize_discrete *sizes,
}
EXPORT_SYMBOL_GPL(v4l2_find_nearest_format);
+const void *
+__v4l2_find_nearest_size(const void *array, size_t array_size,
+ size_t entry_size, size_t width_offset,
+ size_t height_offset, s32 width, s32 height)
+{
+ u32 error, min_error = U32_MAX;
+ const void *best = NULL;
+ unsigned int i;
+
+ if (!array)
+ return NULL;
+
+ for (i = 0; i < array_size; i++, array += entry_size) {
+ const u32 *entry_width = array + width_offset;
+ const u32 *entry_height = array + height_offset;
+
+ error = abs(*entry_width - width) + abs(*entry_height - height);
+ if (error > min_error)
+ continue;
+
+ min_error = error;
+ best = array;
+ if (!error)
+ break;
+ }
+
+ return best;
+}
+EXPORT_SYMBOL_GPL(__v4l2_find_nearest_size);
+
void v4l2_get_timestamp(struct timeval *tv)
{
struct timespec ts;