[RFC PATCH 19/20] lib: image-formats: Add more functions
From: Maxime Ripard
Date: Tue Mar 19 2019 - 17:58:43 EST
V4L2 drivers typically need a few more helpers compared to DRM drivers, so
let's add them.
Signed-off-by: Maxime Ripard <maxime.ripard@xxxxxxxxxxx>
---
include/linux/image-formats.h | 4 +++-
lib/image-formats.c | 42 ++++++++++++++++++++++++++++++++++++-
2 files changed, 46 insertions(+)
diff --git a/include/linux/image-formats.h b/include/linux/image-formats.h
index fbc3a4501ebd..f1d4a2a03cc0 100644
--- a/include/linux/image-formats.h
+++ b/include/linux/image-formats.h
@@ -236,9 +236,13 @@ unsigned int image_format_plane_cpp(const struct image_format_info *format,
unsigned int image_format_plane_width(int width,
const struct image_format_info *format,
int plane);
+unsigned int image_format_plane_stride(const struct image_format_info *format,
+ int width, int plane);
unsigned int image_format_plane_height(int height,
const struct image_format_info *format,
int plane);
+unsigned int image_format_plane_size(const struct image_format_info *format,
+ int width, int height, int plane);
unsigned int image_format_block_width(const struct image_format_info *format,
int plane);
unsigned int image_format_block_height(const struct image_format_info *format,
diff --git a/lib/image-formats.c b/lib/image-formats.c
index 39f1d38ae861..c4e213a89edb 100644
--- a/lib/image-formats.c
+++ b/lib/image-formats.c
@@ -740,6 +740,26 @@ unsigned int image_format_plane_width(int width,
EXPORT_SYMBOL(image_format_plane_width);
/**
+ * image_format_plane_stride - determine the stride value
+ * @format: pointer to the image_format
+ * @width: plane width
+ * @plane: plane index
+ *
+ * Returns:
+ * The bytes per pixel value for the specified plane.
+ */
+unsigned int image_format_plane_stride(const struct image_format_info *format,
+ unsigned int width, int plane)
+{
+ if (!format || plane >= format->num_planes)
+ return 0;
+
+ return image_format_plane_width(width, format, plane) *
+ image_format_plane_cpp(format, plane);
+}
+EXPORT_SYMBOL(image_format_plane_stride);
+
+/**
* image_format_plane_height - height of the plane given the first plane
* @format: pointer to the image_format
* @height: height of the first plane
@@ -763,6 +783,28 @@ unsigned int image_format_plane_height(int height,
EXPORT_SYMBOL(image_format_plane_height);
/**
+ * image_format_plane_size - determine the size value
+ * @format: pointer to the image_format
+ * @width: plane width
+ * @height: plane width
+ * @plane: plane index
+ *
+ * Returns:
+ * The size of the plane buffer.
+ */
+unsigned int image_format_plane_size(const struct image_format_info *format,
+ unsigned int width, unsigned int height,
+ int plane)
+{
+ if (!format || plane >= format->num_planes)
+ return 0;
+
+ return image_format_plane_stride(format, width, plane) *
+ image_format_plane_height(format, height, plane);
+}
+EXPORT_SYMBOL(image_format_plane_size);
+
+/**
* image_format_block_width - width in pixels of block.
* @format: pointer to the image_format
* @plane: plane index
--
git-series 0.9.1