Patchwork Correct computation of bytes per pixel from bits per pixel

login
register
mail settings
Submitter BALATON Zoltan
Date Aug. 21, 2012, 9:32 p.m.
Message ID <Pine.GSO.4.64.1208212331340.11653@mono>
Download mbox | patch
Permalink /patch/179195/
State New
Headers show

Comments

BALATON Zoltan - Aug. 21, 2012, 9:32 p.m.
Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
---
  console.c |    4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
Jan Kiszka - Aug. 22, 2012, 8:02 a.m.
Can you use this free space to provide a scenario where the missing
round-up caused a problem?

On 2012-08-21 23:32, BALATON Zoltan wrote:
> 
> Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
> ---
>  console.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/console.c b/console.c
> index 4525cc7..f698b77 100644
> --- a/console.c
> +++ b/console.c
> @@ -1612,7 +1612,7 @@ PixelFormat
> qemu_different_endianness_pixelformat(int bpp)
>      memset(&pf, 0x00, sizeof(PixelFormat));
> 
>      pf.bits_per_pixel = bpp;
> -    pf.bytes_per_pixel = bpp / 8;
> +    pf.bytes_per_pixel = (bpp + 7) >> 3;

Compilers are smart enough to substitute such divisions by shift
operations but for humans the explicit form is easier to read. So please
keep it.

>      pf.depth = bpp == 32 ? 24 : bpp;
> 
>      switch (bpp) {
> @@ -1661,7 +1661,7 @@ PixelFormat qemu_default_pixelformat(int bpp)
>      memset(&pf, 0x00, sizeof(PixelFormat));
> 
>      pf.bits_per_pixel = bpp;
> -    pf.bytes_per_pixel = bpp / 8;
> +    pf.bytes_per_pixel = (bpp + 7) >> 3;
>      pf.depth = bpp == 32 ? 24 : bpp;
> 
>      switch (bpp) {

Jan
Peter Maydell - Aug. 22, 2012, 8:30 a.m.
On 21 August 2012 22:32, BALATON Zoltan <balaton@eik.bme.hu> wrote:

If you make the Subject "console: Correct computation of bytes per pixel
from bits per pixel" it's easier to tell what bit of qemu the patch
is dealing with.

> Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
> ---
>  console.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/console.c b/console.c
> index 4525cc7..f698b77 100644
> --- a/console.c
> +++ b/console.c
> @@ -1612,7 +1612,7 @@ PixelFormat qemu_different_endianness_pixelformat(int
> bpp)
>      memset(&pf, 0x00, sizeof(PixelFormat));
>
>      pf.bits_per_pixel = bpp;
> -    pf.bytes_per_pixel = bpp / 8;
> +    pf.bytes_per_pixel = (bpp + 7) >> 3;

You could write this as
       pf.bytes_per_pixel = DIV_ROUND_UP(bpp, 8);

-- PMM

Patch

diff --git a/console.c b/console.c
index 4525cc7..f698b77 100644
--- a/console.c
+++ b/console.c
@@ -1612,7 +1612,7 @@  PixelFormat qemu_different_endianness_pixelformat(int bpp)
      memset(&pf, 0x00, sizeof(PixelFormat));

      pf.bits_per_pixel = bpp;
-    pf.bytes_per_pixel = bpp / 8;
+    pf.bytes_per_pixel = (bpp + 7) >> 3;
      pf.depth = bpp == 32 ? 24 : bpp;

      switch (bpp) {
@@ -1661,7 +1661,7 @@  PixelFormat qemu_default_pixelformat(int bpp)
      memset(&pf, 0x00, sizeof(PixelFormat));

      pf.bits_per_pixel = bpp;
-    pf.bytes_per_pixel = bpp / 8;
+    pf.bytes_per_pixel = (bpp + 7) >> 3;
      pf.depth = bpp == 32 ? 24 : bpp;

      switch (bpp) {