[PATCH] server: fix dump_bitmap() on BE machines

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Also control the dump path though the SPICE_BMP_DUMP_PATH
environment variable

Signed-off-by: Denis Kirjanov <kda@xxxxxxxxxxx>
---
 server/spice_bitmap_utils.c |   37 ++++++++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 13 deletions(-)

diff --git a/server/spice_bitmap_utils.c b/server/spice_bitmap_utils.c
index aa7d71b..8022020 100644
--- a/server/spice_bitmap_utils.c
+++ b/server/spice_bitmap_utils.c
@@ -1,4 +1,5 @@
 #include <stdio.h>
+#include <glib.h>
 
 #include "common/log.h"
 #include "common/draw.h"
@@ -22,13 +23,15 @@ int spice_bitmap_from_surface_type(uint32_t surface_format)
     return 0;
 }
 
-#define RAM_PATH "/tmp/tmpfs"
+#define DFLT_BITMAP_DUMP_PATH "/tmp/tmpfs"
 
 static void dump_palette(FILE *f, SpicePalette* plt)
 {
     int i;
+    int val;
     for (i = 0; i < plt->num_ents; i++) {
-        fwrite(plt->ents + i, sizeof(uint32_t), 1, f);
+		val = GUINT32_TO_LE(plt->ents[i]);
+        fwrite(&val, sizeof(uint32_t), 1, f);
     }
 }
 
@@ -64,6 +67,11 @@ void dump_bitmap(SpiceBitmap *bitmap)
     uint16_t tmp_u16;
     FILE *f;
     int i, j;
+	const char *bmp_dump_path;
+
+	bmp_dump_path = getenv("SPICE_BMP_DUMP_PATH");
+	if (!bmp_dump_path)
+		bmp_dump_path = DFLT_BITMAP_DUMP_PATH;
 
     switch (bitmap->format) {
     case SPICE_BITMAP_FMT_1BIT_BE:
@@ -97,6 +105,7 @@ void dump_bitmap(SpiceBitmap *bitmap)
         spice_error("invalid bitmap format  %u", bitmap->format);
         return;
     }
+	n_pixel_bits = GUINT16_TO_LE(n_pixel_bits);
 
     if (!rgb) {
         if (!bitmap->palette) {
@@ -104,39 +113,40 @@ void dump_bitmap(SpiceBitmap *bitmap)
         }
         plt = bitmap->palette;
     }
-    row_size = (((bitmap->x * n_pixel_bits) + 31) / 32) * 4;
+    row_size = (((bitmap->x * GUINT16_FROM_LE(n_pixel_bits)) + 31) / 32) * 4;
     bitmap_data_offset = header_size;
 
     if (plt) {
         bitmap_data_offset += plt->num_ents * 4;
     }
-    file_size = bitmap_data_offset + (bitmap->y * row_size);
+    file_size = GUINT32_TO_LE(bitmap_data_offset + (bitmap->y * row_size));
 
     id = ++file_id;
-    sprintf(file_str, "%s/%u.bmp", RAM_PATH, id);
+    sprintf(file_str, "%s/%u.bmp", bmp_dump_path, id);
 
     f = fopen(file_str, "wb");
     if (!f) {
-        spice_error("Error creating bmp");
+        spice_warning("Error creating bmp: %s", file_str);
         return;
     }
 
     /* writing the bmp v3 header */
     fprintf(f, "BM");
     fwrite(&file_size, sizeof(file_size), 1, f);
-    tmp_u16 = alpha ? 1 : 0;
+    tmp_u16 = GUINT16_TO_LE(alpha ? 1 : 0);
     fwrite(&tmp_u16, sizeof(tmp_u16), 1, f); // reserved for application
     tmp_u16 = 0;
     fwrite(&tmp_u16, sizeof(tmp_u16), 1, f);
+	bitmap_data_offset = GUINT32_TO_LE(bitmap_data_offset);
     fwrite(&bitmap_data_offset, sizeof(bitmap_data_offset), 1, f);
-    tmp_u32 = header_size - 14;
+    tmp_u32 = GUINT32_TO_LE(header_size - 14);
     fwrite(&tmp_u32, sizeof(tmp_u32), 1, f); // sub header size
-    tmp_32 = bitmap->x;
+    tmp_32 = GUINT32_TO_LE(bitmap->x);
     fwrite(&tmp_32, sizeof(tmp_32), 1, f);
-    tmp_32 = bitmap->y;
+    tmp_32 = GUINT32_TO_LE(bitmap->y);
     fwrite(&tmp_32, sizeof(tmp_32), 1, f);
 
-    tmp_u16 = 1;
+    tmp_u16 = GUINT16_TO_LE(1);
     fwrite(&tmp_u16, sizeof(tmp_u16), 1, f); // color plane
     fwrite(&n_pixel_bits, sizeof(n_pixel_bits), 1, f); // pixel depth
 
@@ -148,7 +158,7 @@ void dump_bitmap(SpiceBitmap *bitmap)
     tmp_32 = 0;
     fwrite(&tmp_32, sizeof(tmp_32), 1, f);
     fwrite(&tmp_32, sizeof(tmp_32), 1, f);
-    tmp_u32 = (!plt) ? 0 : plt->num_ents; // plt entries
+    tmp_u32 = (!plt) ? 0 : GUINT32_TO_LE(plt->num_ents); // plt entries
     fwrite(&tmp_u32, sizeof(tmp_u32), 1, f);
     tmp_u32 = 0;
     fwrite(&tmp_u32, sizeof(tmp_u32), 1, f);
@@ -161,7 +171,8 @@ void dump_bitmap(SpiceBitmap *bitmap)
         SpiceChunk *chunk = &bitmap->data->chunk[i];
         int num_lines = chunk->len / bitmap->stride;
         for (j = 0; j < num_lines; j++) {
-            dump_line(f, chunk->data + (j * bitmap->stride), n_pixel_bits, bitmap->x, row_size);
+            dump_line(f, chunk->data + (j * bitmap->stride), GUINT16_FROM_LE(n_pixel_bits),
+				   	bitmap->x, row_size);
         }
     }
     fclose(f);
-- 
1.7.10.4

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]