1 From 79f3433a85bb8128dca78bd05588a2a4b7a389ae Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.org>
3 Date: Fri, 30 Nov 2018 16:00:54 +0000
4 Subject: [PATCH 281/773] staging: bcm2835-camera: Fix stride on RGB3/BGR3
7 RGB3/BGR3 end up being 3 bytes per pixel, which meant that
8 the alignment code ended up trying to align using bitmasking
10 That doesn't work, so switch to an arithmetic alignment for
13 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
15 .../bcm2835-camera/bcm2835-camera.c | 26 ++++++++++++++-----
16 1 file changed, 20 insertions(+), 6 deletions(-)
18 --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
19 +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
20 @@ -1008,13 +1008,27 @@ static int vidioc_try_fmt_vid_cap(struct
22 f->fmt.pix.bytesperline = f->fmt.pix.width * mfmt->ybbp;
23 if (!mfmt->remove_padding) {
24 - int align_mask = ((32 * mfmt->depth) >> 3) - 1;
25 - /* GPU isn't removing padding, so stride is aligned to 32 */
26 - f->fmt.pix.bytesperline =
27 - (f->fmt.pix.bytesperline + align_mask) & ~align_mask;
28 + if (mfmt->depth == 24) {
30 + * 24bpp is a pain as we can't use simple masking.
31 + * Min stride is width aligned to 16, times 24bpp.
33 + f->fmt.pix.bytesperline =
34 + ((f->fmt.pix.width + 15) & ~15) * 3;
37 + * GPU isn't removing padding, so stride is aligned to
40 + int align_mask = ((32 * mfmt->depth) >> 3) - 1;
42 + f->fmt.pix.bytesperline =
43 + (f->fmt.pix.bytesperline + align_mask) &
46 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
47 - "Not removing padding, so bytes/line = %d, (align_mask %d)\n",
48 - f->fmt.pix.bytesperline, align_mask);
49 + "Not removing padding, so bytes/line = %d\n",
50 + f->fmt.pix.bytesperline);
53 /* Image buffer has to be padded to allow for alignment, even though