console: Correct computation of bytes per pixel from bits per pixel
PATCH v2 1/1 console: Correct computation of bytes per pixel from bits per pixel
Division with round up is the correct way to compute this even if the only case where division with round down gives incorrect result is probably 15 bpp. This case was explicitely patched up in one of these functions but was unhandled in the other. (I'm not sure about setting 16 bpp for the 15bpp case either but I left that there for now.)
--- console.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
v2: Use DIV_ROUND_UP and extended commit message
console.c +2 -3
@@ -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 =DIV_ROUND_UP (bpp,8 ); pf.depth = bpp ==32 ?24 : bpp;switch (bpp) {
@@ -1661,13 +1661,12 @@ 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 =DIV_ROUND_UP (bpp,8 ); pf.depth = bpp ==32 ?24 : bpp;switch (bpp) {case 15 : pf.bits_per_pixel =16 ; - pf.bytes_per_pixel =2 ; pf.rmask =0x00007c00 ; pf.gmask =0x000003E0 ; pf.bmask =0x0000001F ;
Signature · 1 line
1.7.10
Quoted 29 lines · BALATON Zoltan
Division with round up is the correct way to compute this even if the only case where division with round down gives incorrect result is probably 15 bpp. This case was explicitely patched up in one of these functions but was unhandled in the other. (I'm not sure about setting 16 bpp for the 15bpp case either but I left that there for now.)
Signed-off-by BALATON Zoltan <[email protected]>--- console.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)v2: Use
DIV_ROUND_UPand extended commit messageconsole.c +1
-1@@ -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 =DIV_ROUND_UP (bpp,8 ); pf.depth = bpp ==32 ?24 : bpp;switch (bpp) {console.c +0
-0@@ -1661,13 +1661,12 @@ PixelFormat qemu_default_pixelformat(int bpp)memset (&pf,0x00 ,sizeof (PixelFormat));
console.c PixelFormat qemu_default_pixelformat(int bpp) · line 1670
Quoted 10 lines
console.c +1
-2pf.bits_per_pixel = bpp; - pf.bytes_per_pixel = bpp /8 ; + pf.bytes_per_pixel =DIV_ROUND_UP (bpp,8 ); pf.depth = bpp ==32 ?24 : bpp;switch (bpp) {case 15 : pf.bits_per_pixel =16 ; - pf.bytes_per_pixel =2 ;
Removed unintentionally?
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE Corporate Competence Center Embedded Linux
Am 22.08.2012 17:32, schrieb Jan Kiszka:
Quoted 36 lines · BALATON Zoltan
Quoted 35 lines
Division with round up is the correct way to compute this even if the only case where division with round down gives incorrect result is probably 15 bpp. This case was explicitely patched up in one of these functions but was unhandled in the other. (I'm not sure about setting 16 bpp for the 15bpp case either but I left that there for now.)
Signed-off-by BALATON Zoltan <[email protected]>--- console.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)v2: Use
DIV_ROUND_UPand extended commit messageconsole.c +1
-1@@ -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 =DIV_ROUND_UP (bpp,8 ); pf.depth = bpp ==32 ?24 : bpp;switch (bpp) {console.c +1
-1@@ -1661,13 +1661,12 @@ 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 =DIV_ROUND_UP (bpp,8 ); pf.depth = bpp ==32 ?24 : bpp;
Quoted 7 lines
console.c PixelFormat qemu_default_pixelformat(int bpp) · line 1670
Quoted 4 lines
console.c +0
-1switch (bpp) {case 15 : pf.bits_per_pixel =16 ; - pf.bytes_per_pixel =2 ;Removed unintentionally?
Jan
15 bpp no longer needs special handling because
the computation above is fixed by the same patch,
so the removal is correct.
Stefan
Quoted 43 lines · Stefan Weil
Am 22.08.2012 17:32, schrieb Jan Kiszka:
Quoted 42 lines · BALATON Zoltan
Quoted 29 lines
Division with round up is the correct way to compute this even if the only case where division with round down gives incorrect result is probably 15 bpp. This case was explicitely patched up in one of these functions but was unhandled in the other. (I'm not sure about setting 16 bpp for the 15bpp case either but I left that there for now.)
Signed-off-by BALATON Zoltan <[email protected]>--- console.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)v2: Use
DIV_ROUND_UPand extended commit messageconsole.c +1
-1@@ -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 =DIV_ROUND_UP (bpp,8 ); pf.depth = bpp ==32 ?24 : bpp;switch (bpp) {console.c +0
-0@@ -1661,13 +1661,12 @@ PixelFormat qemu_default_pixelformat(int bpp)memset (&pf,0x00 ,sizeof (PixelFormat));console.c PixelFormat qemu_default_pixelformat(int bpp) · line 1670
Quoted 10 lines
console.c +1
-2pf.bits_per_pixel = bpp; - pf.bytes_per_pixel = bpp /8 ; + pf.bytes_per_pixel =DIV_ROUND_UP (bpp,8 ); pf.depth = bpp ==32 ?24 : bpp;switch (bpp) {case 15 : pf.bits_per_pixel =16 ; - pf.bytes_per_pixel =2 ;Removed unintentionally?
Quoted 5 lines
Quoted 1 line
Jan
15 bpp no longer needs special handling because
the computation above is fixed by the same patch,
so the removal is correct.
Ok, actually starting to look at this code: This is apparently a code cleanup, not a bug fix like the subject suggests. No valid input for could have actually triggered the round-up issue. Please declare it as such. Bonus for abort() on the invalid default cases.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE Corporate Competence Center Embedded Linux
Quoted 46 lines · Jan Kiszka
Quoted 45 lines · Stefan Weil
Am 22.08.2012 17:32, schrieb Jan Kiszka:
Quoted 43 lines · BALATON Zoltan
Quoted 29 lines
Division with round up is the correct way to compute this even if the only case where division with round down gives incorrect result is probably 15 bpp. This case was explicitely patched up in one of these functions but was unhandled in the other. (I'm not sure about setting 16 bpp for the 15bpp case either but I left that there for now.)
Signed-off-by BALATON Zoltan <[email protected]>--- console.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)v2: Use
DIV_ROUND_UPand extended commit messageconsole.c +1
-1@@ -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 =DIV_ROUND_UP (bpp,8 ); pf.depth = bpp ==32 ?24 : bpp;switch (bpp) {console.c +0
-0@@ -1661,13 +1661,12 @@ PixelFormat qemu_default_pixelformat(int bpp)memset (&pf,0x00 ,sizeof (PixelFormat));console.c PixelFormat qemu_default_pixelformat(int bpp) · line 1670
Quoted 10 lines
console.c +1
-2pf.bits_per_pixel = bpp; - pf.bytes_per_pixel = bpp /8 ; + pf.bytes_per_pixel =DIV_ROUND_UP (bpp,8 ); pf.depth = bpp ==32 ?24 : bpp;switch (bpp) {case 15 : pf.bits_per_pixel =16 ; - pf.bytes_per_pixel =2 ;Removed unintentionally?
Jan
Quoted 8 lines
Quoted 3 lines
15 bpp no longer needs special handling because
the computation above is fixed by the same patch,
so the removal is correct.Ok, actually starting to look at this code: This is apparently a code cleanup, not a bug fix like the subject suggests. No valid input for could have actually triggered the round-up issue. Please declare it as such. Bonus for
abort()on the invalid default cases.
Well, do not abort on bpp == 0, the curses case.
Also, qemu_different_endianness_pixelformat is currently only called with 16 or 32 bpp (see vga.c), but only handles 24 and 32. Fishy...
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE Corporate Competence Center Embedded Linux
Quoted 46 lines · Jan Kiszka
Quoted 45 lines · Stefan Weil
Am 22.08.2012 17:32, schrieb Jan Kiszka:
Quoted 43 lines · BALATON Zoltan
Quoted 29 lines
Division with round up is the correct way to compute this even if the only case where division with round down gives incorrect result is probably 15 bpp. This case was explicitely patched up in one of these functions but was unhandled in the other. (I'm not sure about setting 16 bpp for the 15bpp case either but I left that there for now.)
Signed-off-by BALATON Zoltan <[email protected]>--- console.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)v2: Use
DIV_ROUND_UPand extended commit messageconsole.c +1
-1@@ -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 =DIV_ROUND_UP (bpp,8 ); pf.depth = bpp ==32 ?24 : bpp;switch (bpp) {console.c +0
-0@@ -1661,13 +1661,12 @@ PixelFormat qemu_default_pixelformat(int bpp)memset (&pf,0x00 ,sizeof (PixelFormat));console.c PixelFormat qemu_default_pixelformat(int bpp) · line 1670
Quoted 10 lines
console.c +1
-2pf.bits_per_pixel = bpp; - pf.bytes_per_pixel = bpp /8 ; + pf.bytes_per_pixel =DIV_ROUND_UP (bpp,8 ); pf.depth = bpp ==32 ?24 : bpp;switch (bpp) {case 15 : pf.bits_per_pixel =16 ; - pf.bytes_per_pixel =2 ;Removed unintentionally?
Jan
Quoted 8 lines
Quoted 3 lines
15 bpp no longer needs special handling because
the computation above is fixed by the same patch,
so the removal is correct.Ok, actually starting to look at this code: This is apparently a code cleanup, not a bug fix like the subject suggests. No valid input for could have actually triggered the round-up issue. Please declare it as such. Bonus for
abort()on the invalid default cases.
I have updated the commit message to "console: Clean up bytes per pixel calculation".
Stefan
Quoted 51 lines · Stefan Hajnoczi
Quoted 50 lines · Jan Kiszka
Quoted 48 lines · Stefan Weil
Am 22.08.2012 17:32, schrieb Jan Kiszka:
Quoted 36 lines · BALATON Zoltan
Quoted 35 lines
Division with round up is the correct way to compute this even if the only case where division with round down gives incorrect result is probably 15 bpp. This case was explicitely patched up in one of these functions but was unhandled in the other. (I'm not sure about setting 16 bpp for the 15bpp case either but I left that there for now.)
Signed-off-by BALATON Zoltan <[email protected]>--- console.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)v2: Use
DIV_ROUND_UPand extended commit messageconsole.c +1
-1@@ -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 =DIV_ROUND_UP (bpp,8 ); pf.depth = bpp ==32 ?24 : bpp;switch (bpp) {console.c +1
-1@@ -1661,13 +1661,12 @@ 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 =DIV_ROUND_UP (bpp,8 ); pf.depth = bpp ==32 ?24 : bpp;Quoted 7 lines
console.c PixelFormat qemu_default_pixelformat(int bpp) · line 1670
Quoted 4 lines
console.c +0
-1switch (bpp) {case 15 : pf.bits_per_pixel =16 ; - pf.bytes_per_pixel =2 ;Removed unintentionally?
Jan
15 bpp no longer needs special handling because
the computation above is fixed by the same patch,
so the removal is correct.
Quoted 7 lines
Quoted 4 lines
Ok, actually starting to look at this code: This is apparently a code cleanup, not a bug fix like the subject suggests. No valid input for could have actually triggered the round-up issue. Please declare it as such. Bonus for
abort()on the invalid default cases.I have updated the commit message to "console: Clean up bytes per pixel calculation".
I think there was a v3 on the list, didn't check the details yet, though.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE Corporate Competence Center Embedded Linux
Quoted 57 lines · Jan Kiszka
Quoted 56 lines · Stefan Hajnoczi
Quoted 54 lines · Jan Kiszka
Quoted 43 lines · Stefan Weil
Am 22.08.2012 17:32, schrieb Jan Kiszka:
Quoted 42 lines · BALATON Zoltan
Quoted 29 lines
Division with round up is the correct way to compute this even if the only case where division with round down gives incorrect result is probably 15 bpp. This case was explicitely patched up in one of these functions but was unhandled in the other. (I'm not sure about setting 16 bpp for the 15bpp case either but I left that there for now.)
Signed-off-by BALATON Zoltan <[email protected]>--- console.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)v2: Use
DIV_ROUND_UPand extended commit messageconsole.c +1
-1@@ -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 =DIV_ROUND_UP (bpp,8 ); pf.depth = bpp ==32 ?24 : bpp;switch (bpp) {console.c +0
-0@@ -1661,13 +1661,12 @@ PixelFormat qemu_default_pixelformat(int bpp)memset (&pf,0x00 ,sizeof (PixelFormat));console.c PixelFormat qemu_default_pixelformat(int bpp) · line 1670
Quoted 10 lines
console.c +1
-2pf.bits_per_pixel = bpp; - pf.bytes_per_pixel = bpp /8 ; + pf.bytes_per_pixel =DIV_ROUND_UP (bpp,8 ); pf.depth = bpp ==32 ?24 : bpp;switch (bpp) {case 15 : pf.bits_per_pixel =16 ; - pf.bytes_per_pixel =2 ;Removed unintentionally?
Quoted 5 lines
Quoted 1 line
Jan
15 bpp no longer needs special handling because
the computation above is fixed by the same patch,
so the removal is correct.Ok, actually starting to look at this code: This is apparently a code cleanup, not a bug fix like the subject suggests. No valid input for could have actually triggered the round-up issue. Please declare it as such. Bonus for
abort()on the invalid default cases.
Quoted 4 lines
Quoted 2 lines
I have updated the commit message to "console: Clean up bytes per pixel calculation".
I think there was a v3 on the list, didn't check the details yet, though.
Yes but it just adds more stuff that should be in separate patches. Let's take v2 and additional changes can be done separately.
Stefan
Stefan Hajnoczi
AppliedQuoted 6 lines · BALATON Zoltan
Division with round up is the correct way to compute this even if the only case where division with round down gives incorrect result is probably 15 bpp. This case was explicitely patched up in one of these functions but was unhandled in the other. (I'm not sure about setting 16 bpp for the 15bpp case either but I left that there for now.)
Quoted 6 lines
Signed-off-by BALATON Zoltan <[email protected]>--- console.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)v2: Use
DIV_ROUND_UPand extended commit message
Thanks, applied to the trivial patches tree:
https://github.com/stefanha/qemu/commits/trivial-patches
Stefan