summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrediano Ziglio <fziglio@redhat.com>2017-08-22 12:51:45 +0100
committerFrediano Ziglio <fziglio@redhat.com>2017-08-22 17:41:36 +0100
commitaaeecf129424752b13373a9242bcede58337e047 (patch)
tree43d7e6bfb477c33f439118d3ab73242294202551
parent0630d749fa00cd46c89b693e0a5a8c90a236d524 (diff)
Make BitmapCoder::from_bitmap return a BMP file format
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@redhat.com> Acked-by: Uri Lublin <uril@redhat.com>
-rw-r--r--vdagent/image.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/vdagent/image.cpp b/vdagent/image.cpp
index 82cfb0e..15bd4fa 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;
}