[Spice-devel] [PATCH spice-gtk] mjpeg: fix blue-tinted video stream with old server

Marc-André Lureau marcandre.lureau at gmail.com
Fri Mar 30 14:47:45 PDT 2012


The major == 1 uses RGB colorspace for mjpeg streams.
---
 gtk/channel-display-mjpeg.c |   25 +++++++++++++++++++------
 1 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/gtk/channel-display-mjpeg.c b/gtk/channel-display-mjpeg.c
index cb1bc87..aed3adf 100644
--- a/gtk/channel-display-mjpeg.c
+++ b/gtk/channel-display-mjpeg.c
@@ -65,6 +65,7 @@ G_GNUC_INTERNAL
 void stream_mjpeg_data(display_stream *st)
 {
     SpiceMsgDisplayStreamCreate *info = spice_msg_in_parsed(st->msg_create);
+    gboolean back_compat = st->channel->priv->peer_hdr.major_version == 1;
     int width = info->stream_width;
     int height = info->stream_height;
     uint8_t *dest;
@@ -80,7 +81,10 @@ void stream_mjpeg_data(display_stream *st)
     jpeg_read_header(&st->mjpeg_cinfo, 1);
 #ifdef JCS_EXTENSIONS
     // requires jpeg-turbo
-    st->mjpeg_cinfo.out_color_space = JCS_EXT_BGRX;
+    if (back_compat)
+        st->mjpeg_cinfo.out_color_space = JCS_EXT_RGBX;
+    else
+        st->mjpeg_cinfo.out_color_space = JCS_EXT_BGRX;
 #else
 #warning "You should consider building with libjpeg-turbo"
     st->mjpeg_cinfo.out_color_space = JCS_RGB;
@@ -121,11 +125,20 @@ void stream_mjpeg_data(display_stream *st)
             uint8_t *s = lines[0];
             uint32_t *d = (uint32_t *)s;
 
-            for (unsigned int j = lines_read * width; j > 0; ) {
-                j -= 1; // reverse order, bad for cache?
-                d[j] = s[j * 3 + 0] << 16 |
-                    s[j * 3 + 1] << 8 |
-                    s[j * 3 + 2];
+            if (back_compat) {
+                for (unsigned int j = lines_read * width; j > 0; ) {
+                    j -= 1; // reverse order, bad for cache?
+                    d[j] = s[j * 3 + 0] |
+                        s[j * 3 + 1] << 8 |
+                        s[j * 3 + 2] << 16;
+                }
+            } else {
+                for (unsigned int j = lines_read * width; j > 0; ) {
+                    j -= 1; // reverse order, bad for cache?
+                    d[j] = s[j * 3 + 0] << 16 |
+                        s[j * 3 + 1] << 8 |
+                        s[j * 3 + 2];
+                }
             }
         }
 #endif
-- 
1.7.7.6



More information about the Spice-devel mailing list