[vdagent-win PATCH 1/3] Make BitmapCoder::from_bitmap return a raw file format

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

 



The raw data are used to return raw data that are going to
the network.
The network expect the format of the data to match a file
format so prepending DIB data with BITMAPFILEHEADER change
the format from DIB to BMP file.

Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx>
---
 vdagent/image.cpp | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/vdagent/image.cpp b/vdagent/image.cpp
index 82cfb0e..727f295 100644
--- a/vdagent/image.cpp
+++ b/vdagent/image.cpp
@@ -150,6 +150,8 @@ void BitmapCoder::get_dib_data(uint8_t *dib, const uint8_t *data, size_t size)
 
 uint8_t *BitmapCoder::from_bitmap(const BITMAPINFO& info, const void *bits, long &size)
 {
+    BITMAPFILEHEADER file_hdr;
+
     const BITMAPINFOHEADER& head(info.bmiHeader);
 
     const DWORD max_palette_colors = head.biBitCount <= 8 ? 1 << head.biBitCount : 0;
@@ -157,14 +159,21 @@ uint8_t *BitmapCoder::from_bitmap(const BITMAPINFO& info, const void *bits, long
 
     const size_t stride = compute_dib_stride(head.biWidth, head.biBitCount);
     const size_t image_size = stride * head.biHeight;
-    size = sizeof(head) + palette_size + image_size;
+    size = sizeof(file_hdr) + sizeof(head) + palette_size + image_size;
+
+    file_hdr.bfType = 'B'+'M'*256u;
+    file_hdr.bfSize = size;
+    file_hdr.bfReserved1 = 0;
+    file_hdr.bfReserved2 = 0;
+    file_hdr.bfOffBits = sizeof(file_hdr) + sizeof(head) + palette_size;
 
     uint8_t *data = (uint8_t *) malloc(size);
     if (!data) {
         return NULL;
     }
-    memcpy(data, &info, sizeof(head) + palette_size);
-    memcpy(data + sizeof(head) + palette_size, bits, image_size);
+    memcpy(data, &file_hdr, sizeof(file_hdr));
+    memcpy(data + sizeof(file_hdr), &info, sizeof(head) + palette_size);
+    memcpy(data + sizeof(file_hdr) + sizeof(head) + palette_size, bits, image_size);
     return data;
 }
 
-- 
2.13.5

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://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]