Skip to contentSkip to conversation

ui/vnc: fix some endian problems

PATCH Superseded Daniel P. Berrangé 3 participants 11 messages May 13, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#1 lore raw

PATCH 1/3 ui/vnc.c: replace big endian flag with byte order value

In reply to Daniel P. Berrangé

From: Daniel P. Berrangé <[email protected]>

It will make it easier to do certain comparisons in future if we store G_BIG_ENDIAN/G_LITTLE_ENDIAN directly, instead of a boolean flag.

---
 ui/vnc-enc-tight.c | 2 +-
 ui/vnc-enc-zrle.c  | 2 +-
 ui/vnc-jobs.c      | 2 +-
 ui/vnc.c           | 6 +++---
 ui/vnc.h           | 2 +-
 5 files changed, 7 insertions(+), 7 deletions(-)
ui/vnc-enc-tight.c +1 -1
index 41f559eb83..f51f618e46 100644
@@ -150,7 +150,7 @@ tight_detect_smooth_image24(VncState *vs, int w, int h)
      * If client is big-endian, color samples begin from the second
      * byte (offset 1) of a 32-bit pixel value.
      */
-    off = vs->client_be;
+    off = vs->client_bo == G_BIG_ENDIAN ? 1 : 0;
 
     memset(stats, 0, sizeof (stats));
 
ui/vnc-enc-zrle.c +1 -1
index bd33b89063..9032e82ee5 100644
@@ -255,7 +255,7 @@ static void zrle_write_u8(VncState *vs, uint8_t value)
 static int zrle_send_framebuffer_update(VncState *vs, int x, int y,
                                         int w, int h)
 {
-    bool be = vs->client_be;
+    bool be = vs->client_bo == G_BIG_ENDIAN;
     size_t bytes;
     int zywrle_level;
 
ui/vnc-jobs.c +1 -1
index fcca7ec632..fd019e0a35 100644
@@ -188,7 +188,7 @@ static void vnc_async_encoding_start(VncState *orig, VncState *local)
     local->lossy_rect = orig->lossy_rect;
     local->write_pixels = orig->write_pixels;
     local->client_pf = orig->client_pf;
-    local->client_be = orig->client_be;
+    local->client_bo = orig->client_bo;
     local->tight = orig->tight;
     local->zlib = orig->zlib;
     local->hextile = orig->hextile;
ui/vnc.c +3 -3
index 9e097dc4b4..2c640d8be4 100644
@@ -891,7 +891,7 @@ void vnc_convert_pixel(VncState *vs, uint8_t *buf, uint32_t v)
         buf[0] = v;
         break;
     case 2:
-        if (vs->client_be) {
+        if (vs->client_bo == G_BIG_ENDIAN) {
             buf[0] = v >> 8;
             buf[1] = v;
         } else {
@@ -901,7 +901,7 @@ void vnc_convert_pixel(VncState *vs, uint8_t *buf, uint32_t v)
         break;
     default:
     case 4:
-        if (vs->client_be) {
+        if (vs->client_bo == G_BIG_ENDIAN) {
             buf[0] = v >> 24;
             buf[1] = v >> 16;
             buf[2] = v >> 8;
@@ -2312,7 +2312,7 @@ static void set_pixel_format(VncState *vs, int bits_per_pixel,
     vs->client_pf.bits_per_pixel = bits_per_pixel;
     vs->client_pf.bytes_per_pixel = bits_per_pixel / 8;
     vs->client_pf.depth = bits_per_pixel == 32 ? 24 : bits_per_pixel;
-    vs->client_be = big_endian_flag;
+    vs->client_bo = big_endian_flag ? G_BIG_ENDIAN : G_LITTLE_ENDIAN;
 
     if (!true_color_flag) {
         send_color_map(vs);
ui/vnc.h +1 -1
index acc53a2cc1..f2a627dcdf 100644
@@ -323,7 +323,7 @@ struct VncState
     VncWritePixels *write_pixels;
     PixelFormat client_pf;
     pixman_format_code_t client_format;
-    bool client_be;
+    int client_bo; /* G_LITTLE_ENDIAN or G_BIG_ENDIAN */
 
     CaptureVoiceOut *audio_cap;
     struct audsettings as;
Signature · 1 line
2.49.0
#7 lore raw

PATCH 2/3 ui/vnc: take account of client byte order in pixman format

In reply to Daniel P. Berrangé

From: Daniel P. Berrangé <[email protected]>

The set_pixel_conversion() method is responsible for determining whether the VNC client pixel format matches the server format, and thus whether we can use the fast path "copy" impl for sending pixels, or must use the generic impl with bit swizzling.

The VNC server format is set at build time to VNC_SERVER_FB_FORMAT, which corresponds to PIXMAN_x8r8g8b8.

The qemu_pixman_get_format() method is then responsible for converting the VNC pixel format into a pixman format.

The VNC client pixel shifts are relative to the associated endianness.

The pixman formats are always relative to the host native endianness.

The qemu_pixman_get_format() method does not take into account the VNC client endianness, and is thus returning a pixman format that is only valid with the host endianness matches that of the VNC client.

This has been broken since pixman was introduced to the VNC server:

commit 9f64916da20eea67121d544698676295bbb105a7
Author: Gerd Hoffmann <[email protected]>
Date: Wed Oct 10 13:29:43 2012 +0200

pixman/vnc: use pixman images in vnc.

The flaw can be demonstrated using the Tigervnc client by using

vncviewer -AutoSelect=0 -PreferredEncoding=raw server:display

connecting from a LE client to a QEMU on a BE server, or the reverse.

The bug was masked, however, because almost all VNC clients will advertize support for the "tight" encoding and the QEMU VNC server will prefer "tight" if advertized.

The tight_pack24 method is responsible for taking a set of pixels which have already been converted into client endianness and then repacking them into the TPIXEL format which the RFB spec defines as

"TPIXEL is only 3 bytes long, where the first byte is the
red component, the second byte is the green component, and the third byte is the blue component of the pixel color value"

IOW, the TPIXEL format is fixed on the wire, regardless of what the VNC client declare as its endianness.

Since the VNC pixel encoding code was failing to honour the endian flag of the client, the tight_pack24 method was always operating on data in native endianness. Its impl cancelled out the VNC pixel encoding bug.

With the VNC pixel encoding code now fixed, the tight_pack24 method needs to take into account that it is operating on data in client endianness, not native endianness. It thus may need to invert the pixel shifts.

---
 include/ui/qemu-pixman.h |  4 ++--
 ui/qemu-pixman.c         | 15 ++++++++-------
 ui/vnc-enc-tight.c       |  2 +-
 ui/vnc.c                 |  3 ++-
 4 files changed, 13 insertions(+), 11 deletions(-)
include/ui/qemu-pixman.h +2 -2
index 193bc046d1..2ca0ed7029 100644
@@ -75,12 +75,12 @@ PixelFormat qemu_pixelformat_from_pixman(pixman_format_code_t format);
 pixman_format_code_t qemu_default_pixman_format(int bpp, bool native_endian);
 pixman_format_code_t qemu_drm_format_to_pixman(uint32_t drm_format);
 uint32_t qemu_pixman_to_drm_format(pixman_format_code_t pixman);
-int qemu_pixman_get_type(int rshift, int gshift, int bshift);
+int qemu_pixman_get_type(int rshift, int gshift, int bshift, int endian);
 bool qemu_pixman_check_format(DisplayChangeListener *dcl,
                               pixman_format_code_t format);
 
 #ifdef CONFIG_PIXMAN
-pixman_format_code_t qemu_pixman_get_format(PixelFormat *pf);
+pixman_format_code_t qemu_pixman_get_format(PixelFormat *pf, int endian);
 pixman_image_t *qemu_pixman_linebuf_create(pixman_format_code_t format,
                                            int width);
 void qemu_pixman_linebuf_fill(pixman_image_t *linebuf, pixman_image_t *fb,
ui/qemu-pixman.c +8 -7
index 6ef4376f4e..9ca420ff78 100644
@@ -126,33 +126,34 @@ uint32_t qemu_pixman_to_drm_format(pixman_format_code_t pixman_format)
     return 0;
 }
 
-int qemu_pixman_get_type(int rshift, int gshift, int bshift)
+int qemu_pixman_get_type(int rshift, int gshift, int bshift, int endian)
 {
     int type = PIXMAN_TYPE_OTHER;
+    bool native = (endian == G_BYTE_ORDER);
 
     if (rshift > gshift && gshift > bshift) {
         if (bshift == 0) {
-            type = PIXMAN_TYPE_ARGB;
+            type = native ? PIXMAN_TYPE_ARGB : PIXMAN_TYPE_BGRA;
         } else {
-            type = PIXMAN_TYPE_RGBA;
+            type = native ? PIXMAN_TYPE_RGBA : PIXMAN_TYPE_ABGR;
         }
     } else if (rshift < gshift && gshift < bshift) {
         if (rshift == 0) {
-            type = PIXMAN_TYPE_ABGR;
+            type = native ? PIXMAN_TYPE_ABGR : PIXMAN_TYPE_RGBA;
         } else {
-            type = PIXMAN_TYPE_BGRA;
+            type = native ? PIXMAN_TYPE_BGRA : PIXMAN_TYPE_ARGB;
         }
     }
     return type;
 }
 
 #ifdef CONFIG_PIXMAN
-pixman_format_code_t qemu_pixman_get_format(PixelFormat *pf)
+pixman_format_code_t qemu_pixman_get_format(PixelFormat *pf, int endian)
 {
     pixman_format_code_t format;
     int type;
 
-    type = qemu_pixman_get_type(pf->rshift, pf->gshift, pf->bshift);
+    type = qemu_pixman_get_type(pf->rshift, pf->gshift, pf->bshift, endian);
     format = PIXMAN_FORMAT(pf->bits_per_pixel, type,
                            pf->abits, pf->rbits, pf->gbits, pf->bbits);
     if (!pixman_format_supported_source(format)) {
ui/vnc-enc-tight.c +1 -1
index f51f618e46..c6e8d71d4f 100644
@@ -891,7 +891,7 @@ static void tight_pack24(VncState *vs, uint8_t *buf, size_t count, size_t *ret)
 
     buf8 = buf;
 
-    if (1 /* FIXME */) {
+    if (vs->client_bo == G_BYTE_ORDER) {
         rshift = vs->client_pf.rshift;
         gshift = vs->client_pf.gshift;
         bshift = vs->client_pf.bshift;
ui/vnc.c +2 -1
index 2c640d8be4..c0b8ad9cc1 100644
@@ -2240,7 +2240,8 @@ static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings)
 
 static void set_pixel_conversion(VncState *vs)
 {
-    pixman_format_code_t fmt = qemu_pixman_get_format(&vs->client_pf);
+    pixman_format_code_t fmt = qemu_pixman_get_format(&vs->client_pf,
+                                                      vs->client_bo);
 
     if (fmt == VNC_SERVER_FB_FORMAT) {
         vs->write_pixels = vnc_write_pixels_copy;
Signature · 1 line
2.49.0
#0 lore raw

cover ui/vnc: fix some endian problems

This fixes some edge cases in endian handling in the VNC server. These bugs are rarely going to be visible by default, since most servers will negotiate encoding formats / framebuffer formats that avoid hitting the problem scenarios.

Daniel P. Berrangé (3):
ui/vnc.c: replace big endian flag with byte order value ui/vnc: take account of client byte order in pixman format ui/vnc: fix tight palette pixel encoding for 8/16-bpp formats

 include/ui/qemu-pixman.h |  4 ++--
 ui/qemu-pixman.c         | 15 ++++++++-------
 ui/vnc-enc-tight.c       | 16 ++++++++++------
 ui/vnc-enc-zrle.c        |  2 +-
 ui/vnc-jobs.c            |  2 +-
 ui/vnc.c                 |  9 +++++----
 ui/vnc.h                 |  2 +-
 7 files changed, 28 insertions(+), 22 deletions(-)
Signature · 1 line
2.49.0
#9 lore raw

PATCH 3/3 ui/vnc: fix tight palette pixel encoding for 8/16-bpp formats

From: Daniel P. Berrangé <[email protected]>

When sending a tight rectangle with the palette filter, if the client format was 8/16bpp, the colours on big endian hosts are not set as we're sending the wrong bytes. We must first cast the 32-bit colour to a 16/8-bit value, and then send the result.

---
 ui/vnc-enc-tight.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
ui/vnc-enc-tight.c +8 -4
index c6e8d71d4f..f6d4411e14 100644
@@ -1001,13 +1001,17 @@ static int send_mono_rect(VncState *vs, int x, int y,
         break;
     }
     case 2:
-        vnc_write(vs, &bg, 2);
-        vnc_write(vs, &fg, 2);
+        uint16_t bg16 = bg;
+        uint16_t fg16 = fg;
+        vnc_write(vs, &bg16, 2);
+        vnc_write(vs, &fg16, 2);
         tight_encode_mono_rect16(vs->tight->tight.buffer, w, h, bg, fg);
         break;
     default:
-        vnc_write_u8(vs, bg);
-        vnc_write_u8(vs, fg);
+        uint8_t bg8 = bg;
+        uint8_t fg8 = fg;
+        vnc_write_u8(vs, bg8);
+        vnc_write_u8(vs, fg8);
         tight_encode_mono_rect8(vs->tight->tight.buffer, w, h, bg, fg);
         break;
     }
Signature · 1 line
2.49.0
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] ui/vnc.c: replace big endian flag with byte order value

In reply to Daniel P. Berrangé
Quoted 21 lines · Daniel P. Berrangé

From: Daniel P. Berrangé <[email protected]>

It will make it easier to do certain comparisons in future if we store G_BIG_ENDIAN/G_LITTLE_ENDIAN directly, instead of a boolean flag.

---
  ui/vnc-enc-tight.c | 2 +-
  ui/vnc-enc-zrle.c  | 2 +-
  ui/vnc-jobs.c      | 2 +-
  ui/vnc.c           | 6 +++---
  ui/vnc.h           | 2 +-
  5 files changed, 7 insertions(+), 7 deletions(-)
ui/vnc.h +0 -0
index acc53a2cc1..f2a627dcdf 100644

ui/vnc.h struct VncState · line 326

Quoted 5 lines
ui/vnc.h +1 -1
@@ -323,7 +323,7 @@ struct VncState
      VncWritePixels *write_pixels;
      PixelFormat client_pf;
      pixman_format_code_t client_format;
-    bool client_be;
+    int client_bo; /* G_LITTLE_ENDIAN or G_BIG_ENDIAN */

At least we don't care about G_PDP_ENDIAN ;)

#3 lore raw

Re: [PATCH 1/3] ui/vnc.c: replace big endian flag with byte order value

Quoted 17 lines · Philippe Mathieu-Daudé
Quoted 14 lines · Daniel P. Berrangé

From: Daniel P. Berrangé <[email protected]>

It will make it easier to do certain comparisons in future if we store G_BIG_ENDIAN/G_LITTLE_ENDIAN directly, instead of a boolean flag.

---
  ui/vnc-enc-tight.c | 2 +-
  ui/vnc-enc-zrle.c  | 2 +-
  ui/vnc-jobs.c      | 2 +-
  ui/vnc.c           | 6 +++---
  ui/vnc.h           | 2 +-

  5 files changed, 7 insertions(+), 7 deletions(-)
Quoted 10 lines

ui/vnc.h struct VncState · line 326

Quoted 10 lines
ui/vnc.h +1 -1
index acc53a2cc1..f2a627dcdf 100644
@@ -323,7 +323,7 @@ struct VncState
       VncWritePixels *write_pixels;
       PixelFormat client_pf;
       pixman_format_code_t client_format;
-    bool client_be;
+    int client_bo; /* G_LITTLE_ENDIAN or G_BIG_ENDIAN */

'bo' = 'big order'?

Maybe 'client_endian' or even 'client_endianness'?

Quoted 5 lines

At least we don't care about G_PDP_ENDIAN ;)

#4 lore raw

Re: [PATCH 1/3] ui/vnc.c: replace big endian flag with byte order value

Quoted 18 lines · Philippe Mathieu-Daudé
Quoted 17 lines · Philippe Mathieu-Daudé
Quoted 14 lines · Daniel P. Berrangé

From: Daniel P. Berrangé <[email protected]>

It will make it easier to do certain comparisons in future if we store G_BIG_ENDIAN/G_LITTLE_ENDIAN directly, instead of a boolean flag.

---
  ui/vnc-enc-tight.c | 2 +-
  ui/vnc-enc-zrle.c  | 2 +-
  ui/vnc-jobs.c      | 2 +-
  ui/vnc.c           | 6 +++---
  ui/vnc.h           | 2 +-

  5 files changed, 7 insertions(+), 7 deletions(-)
Quoted 12 lines
Quoted 10 lines

ui/vnc.h struct VncState · line 326

Quoted 10 lines
ui/vnc.h +1 -1
index acc53a2cc1..f2a627dcdf 100644
@@ -323,7 +323,7 @@ struct VncState
       VncWritePixels *write_pixels;
       PixelFormat client_pf;
       pixman_format_code_t client_format;
-    bool client_be;
+    int client_bo; /* G_LITTLE_ENDIAN or G_BIG_ENDIAN */

'bo' = 'big order'?

bo == byte order.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
Reviewed-by on v1 2/3
#8 lore raw

Re: [PATCH 2/3] ui/vnc: take account of client byte order in pixman format

In reply to Daniel P. Berrangé
Quoted 76 lines · Daniel P. Berrangé

From: Daniel P. Berrangé <[email protected]>

The set_pixel_conversion() method is responsible for determining whether the VNC client pixel format matches the server format, and thus whether we can use the fast path "copy" impl for sending pixels, or must use the generic impl with bit swizzling.

The VNC server format is set at build time to VNC_SERVER_FB_FORMAT, which corresponds to PIXMAN_x8r8g8b8.

The qemu_pixman_get_format() method is then responsible for converting the VNC pixel format into a pixman format.

The VNC client pixel shifts are relative to the associated endianness.

The pixman formats are always relative to the host native endianness.

The qemu_pixman_get_format() method does not take into account the VNC client endianness, and is thus returning a pixman format that is only valid with the host endianness matches that of the VNC client.

This has been broken since pixman was introduced to the VNC server:

commit 9f64916da20eea67121d544698676295bbb105a7
Author: Gerd Hoffmann <[email protected]>
Date: Wed Oct 10 13:29:43 2012 +0200

pixman/vnc: use pixman images in vnc.

The flaw can be demonstrated using the Tigervnc client by using

vncviewer -AutoSelect=0 -PreferredEncoding=raw server:display

connecting from a LE client to a QEMU on a BE server, or the reverse.

The bug was masked, however, because almost all VNC clients will advertize support for the "tight" encoding and the QEMU VNC server will prefer "tight" if advertized.

The tight_pack24 method is responsible for taking a set of pixels which have already been converted into client endianness and then repacking them into the TPIXEL format which the RFB spec defines as

"TPIXEL is only 3 bytes long, where the first byte is the
red component, the second byte is the green component, and the third byte is the blue component of the pixel color value"

IOW, the TPIXEL format is fixed on the wire, regardless of what the VNC client declare as its endianness.

Since the VNC pixel encoding code was failing to honour the endian flag of the client, the tight_pack24 method was always operating on data in native endianness. Its impl cancelled out the VNC pixel encoding bug.

With the VNC pixel encoding code now fixed, the tight_pack24 method needs to take into account that it is operating on data in client endianness, not native endianness. It thus may need to invert the pixel shifts.

---
  include/ui/qemu-pixman.h |  4 ++--
  ui/qemu-pixman.c         | 15 ++++++++-------
  ui/vnc-enc-tight.c       |  2 +-
  ui/vnc.c                 |  3 ++-
  4 files changed, 13 insertions(+), 11 deletions(-)
include/ui/qemu-pixman.h +0 -0
index 193bc046d1..2ca0ed7029 100644

include/ui/qemu-pixman.h PixelFormat qemu_pixelformat_from_pixman(pixman_format_code_t format); · line 78

Quoted 5 lines
include/ui/qemu-pixman.h +1 -1
@@ -75,12 +75,12 @@ PixelFormat qemu_pixelformat_from_pixman(pixman_format_code_t format);
  pixman_format_code_t qemu_default_pixman_format(int bpp, bool native_endian);
  pixman_format_code_t qemu_drm_format_to_pixman(uint32_t drm_format);
  uint32_t qemu_pixman_to_drm_format(pixman_format_code_t pixman);
-int qemu_pixman_get_type(int rshift, int gshift, int bshift);
+int qemu_pixman_get_type(int rshift, int gshift, int bshift, int endian);

Too bad there is no GLib enum. Maybe name 'g_endian'?

include/ui/qemu-pixman.h PixelFormat qemu_pixelformat_from_pixman(pixman_format_code_t format); · line 83

Quoted 6 lines
include/ui/qemu-pixman.h +1 -1
  bool qemu_pixman_check_format(DisplayChangeListener *dcl,
                                pixman_format_code_t format);
 
  #ifdef CONFIG_PIXMAN
-pixman_format_code_t qemu_pixman_get_format(PixelFormat *pf);
+pixman_format_code_t qemu_pixman_get_format(PixelFormat *pf, int endian);

(Ditto)

Quoted 8 lines
include/ui/qemu-pixman.h +0 -0
  pixman_image_t *qemu_pixman_linebuf_create(pixman_format_code_t format,
                                             int width);
  void qemu_pixman_linebuf_fill(pixman_image_t *linebuf, pixman_image_t *fb,
ui/qemu-pixman.c +0 -0
index 6ef4376f4e..9ca420ff78 100644

ui/qemu-pixman.c uint32_t qemu_pixman_to_drm_format(pixman_format_code_t pixman_format) · line 132

Quoted 8 lines
ui/qemu-pixman.c +2 -1
@@ -126,33 +126,34 @@ uint32_t qemu_pixman_to_drm_format(pixman_format_code_t pixman_format)
      return 0;
  }
 
-int qemu_pixman_get_type(int rshift, int gshift, int bshift)
+int qemu_pixman_get_type(int rshift, int gshift, int bshift, int endian)
  {
      int type = PIXMAN_TYPE_OTHER;
+    bool native = (endian == G_BYTE_ORDER);

Preferably "native_endian" like in qemu_default_pixman_format().

Quoted 38 lines
ui/qemu-pixman.c +6 -6
      if (rshift > gshift && gshift > bshift) {
          if (bshift == 0) {
-            type = PIXMAN_TYPE_ARGB;
+            type = native ? PIXMAN_TYPE_ARGB : PIXMAN_TYPE_BGRA;
          } else {
-            type = PIXMAN_TYPE_RGBA;
+            type = native ? PIXMAN_TYPE_RGBA : PIXMAN_TYPE_ABGR;
          }
      } else if (rshift < gshift && gshift < bshift) {
          if (rshift == 0) {
-            type = PIXMAN_TYPE_ABGR;
+            type = native ? PIXMAN_TYPE_ABGR : PIXMAN_TYPE_RGBA;
          } else {
-            type = PIXMAN_TYPE_BGRA;
+            type = native ? PIXMAN_TYPE_BGRA : PIXMAN_TYPE_ARGB;
          }
      }
      return type;
  }
 
  #ifdef CONFIG_PIXMAN
-pixman_format_code_t qemu_pixman_get_format(PixelFormat *pf)
+pixman_format_code_t qemu_pixman_get_format(PixelFormat *pf, int endian)
  {
      pixman_format_code_t format;
      int type;
 
-    type = qemu_pixman_get_type(pf->rshift, pf->gshift, pf->bshift);
+    type = qemu_pixman_get_type(pf->rshift, pf->gshift, pf->bshift, endian);
      format = PIXMAN_FORMAT(pf->bits_per_pixel, type,
                             pf->abits, pf->rbits, pf->gbits, pf->bbits);
      if (!pixman_format_supported_source(format)) {
ui/vnc-enc-tight.c +0 -0
index f51f618e46..c6e8d71d4f 100644

ui/vnc-enc-tight.c static void tight_pack24(VncState *vs, uint8_t *buf, size_t count, size_t *ret) · line 894

Quoted 5 lines
ui/vnc-enc-tight.c +1 -1
@@ -891,7 +891,7 @@ static void tight_pack24(VncState *vs, uint8_t *buf, size_t count, size_t *ret)
 
      buf8 = buf;
 
-    if (1 /* FIXME */) {
+    if (vs->client_bo == G_BYTE_ORDER) {

More explicit as:

  bool native_endian = (vs->client_endian == G_BYTE_ORDER);
  if (native_endian) {
Quoted 8 lines
ui/vnc-enc-tight.c +0 -0
          rshift = vs->client_pf.rshift;
          gshift = vs->client_pf.gshift;
          bshift = vs->client_pf.bshift;
ui/vnc.c +0 -0
index 2c640d8be4..c0b8ad9cc1 100644

ui/vnc.c static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings) · line 2247

Quoted 9 lines
ui/vnc.c +2 -1
@@ -2240,7 +2240,8 @@ static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings)
 
  static void set_pixel_conversion(VncState *vs)
  {
-    pixman_format_code_t fmt = qemu_pixman_get_format(&vs->client_pf);
+    pixman_format_code_t fmt = qemu_pixman_get_format(&vs->client_pf,
+                                                      vs->client_bo);
 
      if (fmt == VNC_SERVER_FB_FORMAT) {
          vs->write_pixels = vnc_write_pixels_copy;
#5 lore raw

Re: [PATCH 1/3] ui/vnc.c: replace big endian flag with byte order value

In reply to Daniel P. Berrangé
Quoted 32 lines · Daniel P. Berrangé
Quoted 18 lines · Philippe Mathieu-Daudé
Quoted 17 lines · Philippe Mathieu-Daudé
Quoted 14 lines · Daniel P. Berrangé

From: Daniel P. Berrangé <[email protected]>

It will make it easier to do certain comparisons in future if we store G_BIG_ENDIAN/G_LITTLE_ENDIAN directly, instead of a boolean flag.

---
   ui/vnc-enc-tight.c | 2 +-
   ui/vnc-enc-zrle.c  | 2 +-
   ui/vnc-jobs.c      | 2 +-
   ui/vnc.c           | 6 +++---
   ui/vnc.h           | 2 +-
   5 files changed, 7 insertions(+), 7 deletions(-)
Quoted 12 lines
Quoted 10 lines

ui/vnc.h struct VncState · line 326

Quoted 10 lines
ui/vnc.h +1 -1
index acc53a2cc1..f2a627dcdf 100644
@@ -323,7 +323,7 @@ struct VncState
       VncWritePixels *write_pixels;
       PixelFormat client_pf;
       pixman_format_code_t client_format;
-    bool client_be;
+    int client_bo; /* G_LITTLE_ENDIAN or G_BIG_ENDIAN */

'bo' = 'big order'?

Quoted 1 line

bo == byte order.

Oh of course. Since no GLib endian enum, preferably:

int client_bo; /* byte order: G_LITTLE_ENDIAN or G_BIG_ENDIAN */

Reviewed-by on v1 3/3
#10 lore raw

Re: [PATCH 3/3] ui/vnc: fix tight palette pixel encoding for 8/16-bpp formats

In reply to Daniel P. Berrangé
Quoted 11 lines · Daniel P. Berrangé

From: Daniel P. Berrangé <[email protected]>

When sending a tight rectangle with the palette filter, if the client format was 8/16bpp, the colours on big endian hosts are not set as we're sending the wrong bytes. We must first cast the 32-bit colour to a 16/8-bit value, and then send the result.

---
  ui/vnc-enc-tight.c | 12 ++++++++----
  1 file changed, 8 insertions(+), 4 deletions(-)
#6 lore raw

Re: [PATCH 1/3] ui/vnc.c: replace big endian flag with byte order value

In reply to Philippe Mathieu-Daudé
Quoted 31 lines · Philippe Mathieu-Daudé
Quoted 17 lines · Philippe Mathieu-Daudé
Quoted 14 lines · Daniel P. Berrangé

From: Daniel P. Berrangé <[email protected]>

It will make it easier to do certain comparisons in future if we store G_BIG_ENDIAN/G_LITTLE_ENDIAN directly, instead of a boolean flag.

---
  ui/vnc-enc-tight.c | 2 +-
  ui/vnc-enc-zrle.c  | 2 +-
  ui/vnc-jobs.c      | 2 +-
  ui/vnc.c           | 6 +++---
  ui/vnc.h           | 2 +-

  5 files changed, 7 insertions(+), 7 deletions(-)
Quoted 10 lines

ui/vnc.h struct VncState · line 326

Quoted 10 lines
ui/vnc.h +1 -1
index acc53a2cc1..f2a627dcdf 100644
@@ -323,7 +323,7 @@ struct VncState
       VncWritePixels *write_pixels;
       PixelFormat client_pf;
       pixman_format_code_t client_format;
-    bool client_be;
+    int client_bo; /* G_LITTLE_ENDIAN or G_BIG_ENDIAN */

'bo' = 'big order'?

Quoted 1 line

Maybe 'client_endian' or even 'client_endianness'?

I also thought bo makes no sense. What's the problem with be which was more obvious as it is? If you need to change it client_endian would still be more descriptive, I can't guess what client_bo stands for without the comment and even with that it's not obvious.

Regards,
BALATON Zoltan