[Spice-devel] [PATCH spice-server 3/3] jpeg: Support big endian machines

Frediano Ziglio fziglio at redhat.com
Mon Jun 3 11:22:14 UTC 2019


Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 server/jpeg-encoder.c  |  7 +++++++
 server/mjpeg-encoder.c | 21 +++++++++++++++++++--
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/server/jpeg-encoder.c b/server/jpeg-encoder.c
index 269ed8aa7..1ff7e2506 100644
--- a/server/jpeg-encoder.c
+++ b/server/jpeg-encoder.c
@@ -118,6 +118,7 @@ static void convert_RGB16_to_RGB24(void *line, int width, uint8_t **out_line)
 
     for (x = 0; x < width; x++) {
        uint16_t pixel = *src_line++;
+       pixel = GUINT16_FROM_LE(pixel);
        *out_pix++ = ((pixel >> 7) & 0xf8) | ((pixel >> 12) & 0x7);
        *out_pix++ = ((pixel >> 2) & 0xf8) | ((pixel >> 7) & 0x7);
        *out_pix++ = ((pixel << 3) & 0xf8) | ((pixel >> 2) & 0x7);
@@ -153,9 +154,15 @@ static void convert_BGRX32_to_RGB24(void *line, int width, uint8_t **out_line)
 
     for (x = 0; x < width; x++) {
         uint32_t pixel = *src_line++;
+#ifndef WORDS_BIGENDIAN
         *out_pix++ = (pixel >> 16) & 0xff;
         *out_pix++ = (pixel >> 8) & 0xff;
         *out_pix++ = pixel & 0xff;
+#else
+        *out_pix++ = (pixel >>  8) & 0xff;
+        *out_pix++ = (pixel >> 16) & 0xff;
+        *out_pix++ = (pixel >> 24) & 0xff;
+#endif
     }
 }
 
diff --git a/server/mjpeg-encoder.c b/server/mjpeg-encoder.c
index e629adae4..e293b1b6e 100644
--- a/server/mjpeg-encoder.c
+++ b/server/mjpeg-encoder.c
@@ -70,6 +70,16 @@ static const int mjpeg_quality_samples[MJPEG_QUALITY_SAMPLE_NUM] = {20, 30, 40,
 /* The compressed buffer initial size. */
 #define MJPEG_INITIAL_BUFFER_SIZE (32 * 1024)
 
+#ifdef JCS_EXTENSIONS
+#  ifndef WORDS_BIGENDIAN
+#    define JCS_EXT_LE_BGRX JCS_EXT_BGRX
+#    define JCS_EXT_LE_BGR JCS_EXT_BGR
+#  else
+#    define JCS_EXT_LE_BGRX JCS_EXT_XRGB
+#    define JCS_EXT_LE_BGR JCS_EXT_RGB
+#  endif
+#endif
+
 enum {
     MJPEG_QUALITY_EVAL_TYPE_SET,
     MJPEG_QUALITY_EVAL_TYPE_UPGRADE,
@@ -232,15 +242,22 @@ static void pixel_rgb24bpp_to_24(void *src_ptr, uint8_t *dest)
 static void pixel_rgb32bpp_to_24(void *src, uint8_t *dest)
 {
     uint32_t pixel = *(uint32_t *)src;
+#ifndef WORDS_BIGENDIAN
     *dest++ = (pixel >> 16) & 0xff;
     *dest++ = (pixel >>  8) & 0xff;
     *dest++ = (pixel >>  0) & 0xff;
+#else
+    *dest++ = (pixel >>  8) & 0xff;
+    *dest++ = (pixel >> 16) & 0xff;
+    *dest++ = (pixel >> 24) & 0xff;
+#endif
 }
 #endif
 
 static void pixel_rgb16bpp_to_24(void *src, uint8_t *dest)
 {
     uint16_t pixel = *(uint16_t *)src;
+    pixel = GUINT16_FROM_LE(pixel);
     *dest++ = ((pixel >> 7) & 0xf8) | ((pixel >> 12) & 0x7);
     *dest++ = ((pixel >> 2) & 0xf8) | ((pixel >> 7) & 0x7);
     *dest++ = ((pixel << 3) & 0xf8) | ((pixel >> 2) & 0x7);
@@ -753,7 +770,7 @@ static int mjpeg_encoder_start_frame(MJpegEncoder *encoder,
     case SPICE_BITMAP_FMT_RGBA:
         encoder->bytes_per_pixel = 4;
 #ifdef JCS_EXTENSIONS
-        encoder->cinfo.in_color_space   = JCS_EXT_BGRX;
+        encoder->cinfo.in_color_space   = JCS_EXT_LE_BGRX;
         encoder->cinfo.input_components = 4;
 #else
         encoder->pixel_converter = pixel_rgb32bpp_to_24;
@@ -766,7 +783,7 @@ static int mjpeg_encoder_start_frame(MJpegEncoder *encoder,
     case SPICE_BITMAP_FMT_24BIT:
         encoder->bytes_per_pixel = 3;
 #ifdef JCS_EXTENSIONS
-        encoder->cinfo.in_color_space = JCS_EXT_BGR;
+        encoder->cinfo.in_color_space = JCS_EXT_LE_BGR;
 #else
         encoder->pixel_converter = pixel_rgb24bpp_to_24;
 #endif
-- 
2.20.1



More information about the Spice-devel mailing list