[vdagent-win PATCH 3/3] imagetest: Save BMP file using BitmapCoder

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

 



This allows to test BitmapCoder::from_bitmap.

Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx>
---
 vdagent/image.cpp     |  2 --
 vdagent/image.h       |  2 ++
 vdagent/imagetest.cpp | 20 ++++++--------------
 3 files changed, 8 insertions(+), 16 deletions(-)

diff --git a/vdagent/image.cpp b/vdagent/image.cpp
index 727f295..7bb25ac 100644
--- a/vdagent/image.cpp
+++ b/vdagent/image.cpp
@@ -23,8 +23,6 @@
 #include "image.h"
 #include "imagepng.h"
 
-ImageCoder *create_bitmap_coder();
-
 static ImageCoder *get_coder(uint32_t vdagent_type)
 {
     switch (vdagent_type) {
diff --git a/vdagent/image.h b/vdagent/image.h
index da549d3..326d7f9 100644
--- a/vdagent/image.h
+++ b/vdagent/image.h
@@ -39,6 +39,8 @@ static inline size_t compute_dib_stride(unsigned int width, unsigned int bit_cou
     return ((width * bit_count + 31u) & ~31u) / 8u;
 }
 
+ImageCoder *create_bitmap_coder();
+
 /**
  * Returns image to put in the clipboard.
  *
diff --git a/vdagent/imagetest.cpp b/vdagent/imagetest.cpp
index 3a553a9..36b8f6c 100644
--- a/vdagent/imagetest.cpp
+++ b/vdagent/imagetest.cpp
@@ -18,6 +18,7 @@
 #undef NDEBUG
 #include <assert.h>
 #include <vector>
+#include <memory>
 
 #include "vdcommon.h"
 #include "image.h"
@@ -42,7 +43,7 @@ save_dib_to_file(ImageCoder& coder, const uint8_t *raw_dib, const char *filename
 
 int main(int argc, char **argv)
 {
-    ImageCoder *coder = create_png_coder();
+    std::unique_ptr<ImageCoder> coder(create_png_coder());
 
     assert(coder);
     if (argc < 2) {
@@ -68,19 +69,10 @@ int main(int argc, char **argv)
     memset(&out[0], 0xcc, dib_size);
     coder->get_dib_data(&out[0], &data[0], len);
 
-    // looks like many tools wants this header so craft it
-    BITMAPFILEHEADER head;
-    memset(&head, 0, sizeof(head));
-    head.bfType = 'B'+'M'*256u;
-    head.bfSize = sizeof(head) + dib_size;
-    BITMAPINFOHEADER& info(*(BITMAPINFOHEADER*)&out[0]);
-    head.bfOffBits = sizeof(head) + sizeof(BITMAPINFOHEADER) + 4 * info.biClrUsed;
-
-    f = fopen(argc > 2 ? argv[2] : "out.bmp", "wb");
-    assert(f);
-    assert(fwrite(&head, 1, sizeof(head), f) == sizeof(head));
-    assert(fwrite(&out[0], 1, dib_size, f) == dib_size);
-    fclose(f);
+    // write BMP file
+    std::unique_ptr<ImageCoder> bmp_coder(create_bitmap_coder());
+    assert(bmp_coder);
+    save_dib_to_file(*bmp_coder, &out[0], argc > 2 ? argv[2] : "out.bmp");
 
     // convert back to PNG
     save_dib_to_file(*coder, &out[0], argc > 3 ? argv[3] : "out.png");
-- 
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]