[media] soc-camera: Add soc_mbus_image_size
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Wed, 21 Mar 2012 11:03:25 +0000 (08:03 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Tue, 15 May 2012 19:10:20 +0000 (16:10 -0300)
The function returns the minimum size of an image for a given number of
bytes per line (as per the V4L2 specification), width and format.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/video/soc_mediabus.c
include/media/soc_mediabus.h

index a7073142f9f1acf399173e0c06c4f34f60c217b8..89dce097a827a57d918702b0a4cd415b48ee409e 100644 (file)
@@ -397,6 +397,24 @@ s32 soc_mbus_bytes_per_line(u32 width, const struct soc_mbus_pixelfmt *mf)
 }
 EXPORT_SYMBOL(soc_mbus_bytes_per_line);
 
+s32 soc_mbus_image_size(const struct soc_mbus_pixelfmt *mf,
+                       u32 bytes_per_line, u32 height)
+{
+       if (mf->layout == SOC_MBUS_LAYOUT_PACKED)
+               return bytes_per_line * height;
+
+       switch (mf->packing) {
+       case SOC_MBUS_PACKING_2X8_PADHI:
+       case SOC_MBUS_PACKING_2X8_PADLO:
+               return bytes_per_line * height * 2;
+       case SOC_MBUS_PACKING_1_5X8:
+               return bytes_per_line * height * 3 / 2;
+       default:
+               return -EINVAL;
+       }
+}
+EXPORT_SYMBOL(soc_mbus_image_size);
+
 const struct soc_mbus_pixelfmt *soc_mbus_find_fmtdesc(
        enum v4l2_mbus_pixelcode code,
        const struct soc_mbus_lookup *lookup,
index e18eed4e5678f86b8078ec655fdcdd362e730053..0dc6f4625b920021fa573bfe06918d58c120296c 100644 (file)
@@ -99,6 +99,8 @@ const struct soc_mbus_pixelfmt *soc_mbus_find_fmtdesc(
 const struct soc_mbus_pixelfmt *soc_mbus_get_fmtdesc(
        enum v4l2_mbus_pixelcode code);
 s32 soc_mbus_bytes_per_line(u32 width, const struct soc_mbus_pixelfmt *mf);
+s32 soc_mbus_image_size(const struct soc_mbus_pixelfmt *mf,
+                       u32 bytes_per_line, u32 height);
 int soc_mbus_samples_per_pixel(const struct soc_mbus_pixelfmt *mf,
                        unsigned int *numerator, unsigned int *denominator);
 unsigned int soc_mbus_config_compatible(const struct v4l2_mbus_config *cfg,