From 19c60c04ae6e7fe2b191e7f0b7c842e0ea202861 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= Date: Thu, 1 Sep 2011 23:00:07 -0400 Subject: [PATCH] libfreerdp-utils: added util to dump images to bitmap files --- include/freerdp/utils/bitmap.h | 27 ++++++++ libfreerdp-gdi/gdi.c | 16 +++++ libfreerdp-utils/CMakeLists.txt | 1 + libfreerdp-utils/bitmap.c | 105 ++++++++++++++++++++++++++++++++ 4 files changed, 149 insertions(+) create mode 100644 include/freerdp/utils/bitmap.h create mode 100644 libfreerdp-utils/bitmap.c diff --git a/include/freerdp/utils/bitmap.h b/include/freerdp/utils/bitmap.h new file mode 100644 index 000000000..cb09474e3 --- /dev/null +++ b/include/freerdp/utils/bitmap.h @@ -0,0 +1,27 @@ +/** + * FreeRDP: A Remote Desktop Protocol Client + * Bitmap File Format Utils + * + * Copyright 2011 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __UTILS_BITMAP_H +#define __UTILS_BITMAP_H + +#include + +FREERDP_API void freerdp_bitmap_write(char* filename, void* data, int width, int height, int bpp); + +#endif /* __UTILS_BITMAP_H */ diff --git a/libfreerdp-gdi/gdi.c b/libfreerdp-gdi/gdi.c index 81ab8e942..bd0fc4872 100644 --- a/libfreerdp-gdi/gdi.c +++ b/libfreerdp-gdi/gdi.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -754,11 +755,14 @@ void gdi_cache_brush(rdpUpdate* update, CACHE_BRUSH_ORDER* cache_brush) brush_put(gdi->cache->brush, cache_brush->index, cache_brush->data, cache_brush->bpp); } +int tilenum = 0; + void gdi_surface_bits(rdpUpdate* update, SURFACE_BITS_COMMAND* surface_bits_command) { int i, j; int tx, ty; STREAM* s; + char* tile_bitmap; RFX_MESSAGE* message; GDI* gdi = GET_GDI(update); RFX_CONTEXT* context = (RFX_CONTEXT*) gdi->rfx_context; @@ -771,6 +775,8 @@ void gdi_surface_bits(rdpUpdate* update, SURFACE_BITS_COMMAND* surface_bits_comm surface_bits_command->width, surface_bits_command->height, surface_bits_command->bitmapDataLength); + tile_bitmap = xzalloc(32); + if (surface_bits_command->codecID == CODEC_ID_REMOTEFX) { s = stream_new(0); @@ -790,6 +796,11 @@ void gdi_surface_bits(rdpUpdate* update, SURFACE_BITS_COMMAND* surface_bits_comm gdi_image_convert(message->tiles[i]->data, gdi->tile->bitmap->data, 64, 64, 32, 32, gdi->clrconv); +#ifdef DUMP_REMOTEFX_TILES + sprintf(tile_bitmap, "/tmp/rfx/tile_%d.bmp", tilenum++); + freerdp_bitmap_write(tile_bitmap, gdi->tile->bitmap->data, 64, 64, 32); +#endif + for (j = 0; j < message->num_rects; j++) { gdi_SetClipRgn(gdi->primary->hdc, @@ -824,6 +835,11 @@ void gdi_surface_bits(rdpUpdate* update, SURFACE_BITS_COMMAND* surface_bits_comm gdi_image_convert(message->tiles[i]->data, gdi->tile->bitmap->data, 64, 64, 32, 32, gdi->clrconv); +#ifdef DUMP_REMOTEFX_TILES + sprintf(tile_bitmap, "/tmp/rfx/tile_%d.bmp", tilenum++); + freerdp_bitmap_write(tile_bitmap, gdi->tile->bitmap->data, 64, 64, 32); +#endif + gdi_BitBlt(gdi->primary->hdc, tx, ty, 64, 64, gdi->tile->hdc, 0, 0, GDI_SRCCOPY); } diff --git a/libfreerdp-utils/CMakeLists.txt b/libfreerdp-utils/CMakeLists.txt index b869f5de9..2782e2755 100644 --- a/libfreerdp-utils/CMakeLists.txt +++ b/libfreerdp-utils/CMakeLists.txt @@ -25,6 +25,7 @@ set(FREERDP_UTILS_SRCS blob.c dsp.c event.c + bitmap.c hexdump.c list.c load_plugin.c diff --git a/libfreerdp-utils/bitmap.c b/libfreerdp-utils/bitmap.c new file mode 100644 index 000000000..bbcfbdb7e --- /dev/null +++ b/libfreerdp-utils/bitmap.c @@ -0,0 +1,105 @@ +/** + * FreeRDP: A Remote Desktop Protocol Client + * Bitmap File Format Utils + * + * Copyright 2011 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include + +#include + +typedef struct +{ + uint8 magic[2]; +} bmpfile_magic; + +typedef struct +{ + uint32 filesz; + uint16 creator1; + uint16 creator2; + uint32 bmp_offset; +} bmpfile_header; + +typedef struct +{ + uint32 header_sz; + sint32 width; + sint32 height; + uint16 nplanes; + uint16 bitspp; + uint32 compress_type; + uint32 bmp_bytesz; + sint32 hres; + sint32 vres; + uint32 ncolors; + uint32 nimpcolors; +} BITMAPINFOHEADER; + +void freerdp_bitmap_write(char* filename, void* data, int width, int height, int bpp) +{ + FILE* fp; + bmpfile_magic magic; + bmpfile_header header; + BITMAPINFOHEADER info_header; + + fp = fopen(filename, "w+b"); + + if (fp == NULL) + { + printf("failed to open file %s\n", filename); + return; + } + + magic.magic[0] = 'B'; + magic.magic[1] = 'M'; + + header.creator1 = 0; + header.creator2 = 0; + + header.bmp_offset = + sizeof(bmpfile_magic) + + sizeof(bmpfile_header) + + sizeof(BITMAPINFOHEADER); + + info_header.bmp_bytesz = width * height * (bpp / 8); + + header.filesz = + header.bmp_offset + + info_header.bmp_bytesz; + + info_header.width = width; + info_header.height = (-1) * height; + info_header.nplanes = 1; + info_header.bitspp = bpp; + info_header.compress_type = 0; + info_header.hres = width; + info_header.vres = height; + info_header.ncolors = 0; + info_header.nimpcolors = 0; + info_header.header_sz = sizeof(BITMAPINFOHEADER); + + fwrite((void*) &magic, sizeof(bmpfile_magic), 1, fp); + fwrite((void*) &header, sizeof(bmpfile_header), 1, fp); + fwrite((void*) &info_header, sizeof(BITMAPINFOHEADER), 1, fp); + fwrite((void*) data, info_header.bmp_bytesz, 1, fp); + + fclose(fp); +} +