diff mbox

V4L: soc-camera: regression fix: calculate .sizeimage in soc_camera.c

Message ID Pine.LNX.4.64.1104111054110.18511@axis700.grange (mailing list archive)
State RFC
Headers show

Commit Message

Guennadi Liakhovetski April 11, 2011, 8:58 a.m. UTC
A recent patch has given individual soc-camera host drivers a possibility 
to calculate .sizeimage and .bytesperline pixel format fields internally, 
however, some drivers relied on the core calculating these values for 
them, following a default algorithm. This patch restores the default 
calculation for such drivers.

Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
---
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Janusz Krzysztofik April 11, 2011, 12:58 p.m. UTC | #1
Dnia poniedzia?ek 11 kwiecie? 2011 o 10:58:26 Guennadi Liakhovetski 
napisa?(a):
> A recent patch has given individual soc-camera host drivers a
> possibility to calculate .sizeimage and .bytesperline pixel format
> fields internally, however, some drivers relied on the core
> calculating these values for them, following a default algorithm.
> This patch restores the default calculation for such drivers.
> 
> Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>

Hi Guennadi,
Works for me on my OMAP1 camera (Amstrad Delta, 2.6.39-rc2).
You can add my Tested-by: if you like.

Thanks,
Janusz
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Guennadi Liakhovetski April 11, 2011, 1:23 p.m. UTC | #2
On Mon, 11 Apr 2011, Aguirre, Sergio wrote:

> Hi Guennadi,
> 
> On Mon, Apr 11, 2011 at 3:58 AM, Guennadi Liakhovetski <
> g.liakhovetski@gmx.de> wrote:
> 
> > A recent patch has given individual soc-camera host drivers a possibility
> > to calculate .sizeimage and .bytesperline pixel format fields internally,
> > however, some drivers relied on the core calculating these values for
> > them, following a default algorithm. This patch restores the default
> > calculation for such drivers.
> >
> > Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
> > ---
> > diff --git a/drivers/media/video/soc_camera.c
> > b/drivers/media/video/soc_camera.c
> > index 4628448..0918c48 100644
> > --- a/drivers/media/video/soc_camera.c
> > +++ b/drivers/media/video/soc_camera.c
> > @@ -376,6 +376,9 @@ static int soc_camera_set_fmt(struct soc_camera_device
> > *icd,
> >        dev_dbg(&icd->dev, "S_FMT(%c%c%c%c, %ux%u)\n",
> >                pixfmtstr(pix->pixelformat), pix->width, pix->height);
> >
> > +       pix->bytesperline = 0;
> > +       pix->sizeimage = 0;
> > +
> >        /* We always call try_fmt() before set_fmt() or set_crop() */
> >        ret = ici->ops->try_fmt(icd, f);
> >        if (ret < 0)
> > @@ -391,6 +394,17 @@ static int soc_camera_set_fmt(struct soc_camera_device
> > *icd,
> >                return -EINVAL;
> >        }
> >
> > +       if (!pix->sizeimage) {
> > +               if (!pix->bytesperline) {
> > +                       ret = soc_mbus_bytes_per_line(pix->width,
> > +
> > icd->current_fmt->host_fmt);
> > +                       if (ret > 0)
> > +                               pix->bytesperline = ret;
> > +               }
> > +               if (pix->bytesperline)
> > +                       pix->sizeimage = pix->bytesperline * pix->height;
> > +       }
> > +
> >
> 
> Shouldn't all this be better done in try_fmt?

Not _better_. We might choose to additionally do it for try_fmt too. But

1. we didn't do it before, applications don't seem to care.
2. you cannot store / reuse those .sizeimage & .bytesperline values - this 
is just a "try"
3. it would be a bit difficult to realise - we need a struct 
soc_mbus_pixelfmt to call soc_mbus_bytes_per_line(), which we don't have, 
so, we'd need to obtain it using soc_camera_xlate_by_fourcc().

This all would work, but in any case it would be an enhancement, but not a 
regression fix.

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/media/video/soc_camera.c b/drivers/media/video/soc_camera.c
index 4628448..0918c48 100644
--- a/drivers/media/video/soc_camera.c
+++ b/drivers/media/video/soc_camera.c
@@ -376,6 +376,9 @@  static int soc_camera_set_fmt(struct soc_camera_device *icd,
 	dev_dbg(&icd->dev, "S_FMT(%c%c%c%c, %ux%u)\n",
 		pixfmtstr(pix->pixelformat), pix->width, pix->height);
 
+	pix->bytesperline = 0;
+	pix->sizeimage = 0;
+
 	/* We always call try_fmt() before set_fmt() or set_crop() */
 	ret = ici->ops->try_fmt(icd, f);
 	if (ret < 0)
@@ -391,6 +394,17 @@  static int soc_camera_set_fmt(struct soc_camera_device *icd,
 		return -EINVAL;
 	}
 
+	if (!pix->sizeimage) {
+		if (!pix->bytesperline) {
+			ret = soc_mbus_bytes_per_line(pix->width,
+						      icd->current_fmt->host_fmt);
+			if (ret > 0)
+				pix->bytesperline = ret;
+		}
+		if (pix->bytesperline)
+			pix->sizeimage = pix->bytesperline * pix->height;
+	}
+
 	icd->user_width		= pix->width;
 	icd->user_height	= pix->height;
 	icd->bytesperline	= pix->bytesperline;