Skip to contentSkip to conversation

Arithmetic error in EDID generation fixed

PATCH In review Anton V. Boyarshinov 3 participants 3 messages Feb 26, 2020 – Mar 2, 2020

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Arithmetic error in EDID generation fixed

To calculate screen size in centimeters we should calculate:
pixels/dpi*2.54
but not
pixels*dpi/2540

Using wrong formula we actually get 65 DPI and very small fonts.

---
Changes from v1: get rid of casts

 hw/display/edid-generate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/display/edid-generate.c +2 -2
index 75c945a948..e58472fde5 100644
@@ -360,8 +360,8 @@ void qemu_edid_generate(uint8_t *edid, size_t size,
     edid[20] = 0xa5;
 
     /* screen size: undefined */
-    edid[21] = info->prefx * info->dpi / 2540;
-    edid[22] = info->prefy * info->dpi / 2540;
+    edid[21] = info->prefx * 254 / 100 / info->dpi;
+    edid[22] = info->prefy * 254 / 100 / info->dpi;
 
     /* display gamma: 2.2 */
     edid[23] = 220 - 100;
Signature · 1 line
2.21.0
#1 lore raw
Quoted 6 lines · Anton V. Boyarshinov

To calculate screen size in centimeters we should calculate:
pixels/dpi*2.54
but not
pixels*dpi/2540

Using wrong formula we actually get 65 DPI and very small fonts.

Added to vga patch queu.

thanks,
Gerd

#2 lore raw
In reply to Anton V. Boyarshinov

Am 26.02.20 um 13:20 schrieb Anton V. Boyarshinov:

Quoted 19 lines

To calculate screen size in centimeters we should calculate:
pixels/dpi*2.54
but not
pixels*dpi/2540

Using wrong formula we actually get 65 DPI and very small fonts.

---
Changes from v1: get rid of casts

 hw/display/edid-generate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/display/edid-generate.c +0 -0
index 75c945a948..e58472fde5 100644

hw/display/edid-generate.c void qemu_edid_generate(uint8_t *edid, size_t size, · line 362

Quoted 3 lines
hw/display/edid-generate.c +0 -0
@@ -360,8 +360,8 @@ void qemu_edid_generate(uint8_t *edid, size_t size,
     edid[20] = 0xa5;
 
     /* screen size: undefined */

Gerd, is this comment still correct?

hw/display/edid-generate.c void qemu_edid_generate(uint8_t *edid, size_t size, · line 364

Quoted 4 lines
hw/display/edid-generate.c +2 -2
-    edid[21] = info->prefx * info->dpi / 2540;
-    edid[22] = info->prefy * info->dpi / 2540;
+    edid[21] = info->prefx * 254 / 100 / info->dpi;
+    edid[22] = info->prefy * 254 / 100 / info->dpi;

The fix is good, but can be improved:

According to the standard, the values are "rounded to the nearest centimeter". Currently they are not rounded, but truncated. So this would be a better approximation:

edid[21] = (info->prefx * 254 / info->dpi + 50) / 100;

...

Regards,

Stefan