[Spice-devel] [PATCH 04/10] server: move dump_bitmap to separate file
Yonit Halperin
yhalperi at redhat.com
Mon Aug 12 06:11:05 PDT 2013
Hi,
Just a nitpick (below)
On 08/12/2013 08:49 AM, Alon Levy wrote:
> ---
> server/Makefile.am | 2 +
> server/red_worker.c | 157 ++------------------------------------------
> server/spice_bitmap_utils.c | 152 ++++++++++++++++++++++++++++++++++++++++++
> server/spice_bitmap_utils.h | 6 ++
> 4 files changed, 164 insertions(+), 153 deletions(-)
> create mode 100644 server/spice_bitmap_utils.c
> create mode 100644 server/spice_bitmap_utils.h
>
> diff --git a/server/Makefile.am b/server/Makefile.am
> index d351dae..e5392ba 100644
> --- a/server/Makefile.am
> +++ b/server/Makefile.am
> @@ -97,6 +97,8 @@ libspice_server_la_SOURCES = \
> spice_timer_queue.h \
> zlib_encoder.c \
> zlib_encoder.h \
> + spice_bitmap_utils.h \
> + spice_bitmap_utils.c \
> $(NULL)
>
> if SUPPORT_TUNNEL
> diff --git a/server/red_worker.c b/server/red_worker.c
> index 0674174..0704279 100644
> --- a/server/red_worker.c
> +++ b/server/red_worker.c
> @@ -93,6 +93,10 @@
> //#define ACYCLIC_SURFACE_DEBUG
> //#define DEBUG_CURSORS
>
> +#ifdef DUMP_BITMAP
> +#include "spice_bitmap_utils.h"
> +#endif
> +
> //#define UPDATE_AREA_BY_TREE
>
> #define CMD_RING_POLL_TIMEOUT 10 //milli
> @@ -1101,10 +1105,6 @@ static void cursor_channel_client_release_item_after_push(CursorChannelClient *c
> PipeItem *item);
> static void red_wait_pipe_item_sent(RedChannelClient *rcc, PipeItem *item);
>
> -#ifdef DUMP_BITMAP
> -static void dump_bitmap(RedWorker *worker, SpiceBitmap *bitmap, uint32_t group_id);
> -#endif
> -
> static void red_push_monitors_config(DisplayChannelClient *dcc);
> static inline uint64_t red_now(void);
>
> @@ -12292,152 +12292,3 @@ SPICE_GNUC_NORETURN void *red_worker_main(void *arg)
> }
> abort();
> }
> -
> -#ifdef DUMP_BITMAP
> -#include <stdio.h>
> -static void dump_palette(FILE *f, SpicePalette* plt)
> -{
> - int i;
> - for (i = 0; i < plt->num_ents; i++) {
> - fwrite(plt->ents + i, sizeof(uint32_t), 1, f);
> - }
> -}
> -
> -static void dump_line(FILE *f, uint8_t* line, uint16_t n_pixel_bits, int width, int row_size)
> -{
> - int i;
> - int copy_bytes_size = SPICE_ALIGN(n_pixel_bits * width, 8) / 8;
> -
> - fwrite(line, 1, copy_bytes_size, f);
> - if (row_size > copy_bytes_size) {
> - // each line should be 4 bytes aligned
> - for (i = copy_bytes_size; i < row_size; i++) {
> - fprintf(f, "%c", 0);
> - }
> - }
> -}
> -
> -#define RAM_PATH "/tmp/tmpfs"
> -
> -static void dump_bitmap(RedWorker *worker, SpiceBitmap *bitmap, uint32_t group_id)
> -{
> - static uint32_t file_id = 0;
> -
> - char file_str[200];
> - int rgb = TRUE;
> - uint16_t n_pixel_bits;
> - SpicePalette *plt = NULL;
> - uint32_t id;
> - int row_size;
> - uint32_t file_size;
> - int alpha = 0;
> - uint32_t header_size = 14 + 40;
> - uint32_t bitmap_data_offset;
> - uint32_t tmp_u32;
> - int32_t tmp_32;
> - uint16_t tmp_u16;
> - FILE *f;
> - int i;
> -
> - switch (bitmap->format) {
> - case SPICE_BITMAP_FMT_1BIT_BE:
> - case SPICE_BITMAP_FMT_1BIT_LE:
> - rgb = FALSE;
> - n_pixel_bits = 1;
> - break;
> - case SPICE_BITMAP_FMT_4BIT_BE:
> - case SPICE_BITMAP_FMT_4BIT_LE:
> - rgb = FALSE;
> - n_pixel_bits = 4;
> - break;
> - case SPICE_BITMAP_FMT_8BIT:
> - rgb = FALSE;
> - n_pixel_bits = 8;
> - break;
> - case SPICE_BITMAP_FMT_16BIT:
> - n_pixel_bits = 16;
> - break;
> - case SPICE_BITMAP_FMT_24BIT:
> - n_pixel_bits = 24;
> - break;
> - case SPICE_BITMAP_FMT_32BIT:
> - n_pixel_bits = 32;
> - break;
> - case SPICE_BITMAP_FMT_RGBA:
> - n_pixel_bits = 32;
> - alpha = 1;
> - break;
> - default:
> - spice_error("invalid bitmap format %u", bitmap->format);
> - }
> -
> - if (!rgb) {
> - if (!bitmap->palette) {
> - return; // dont dump masks.
> - }
> - plt = bitmap->palette;
> - }
> - row_size = (((bitmap->x * 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);
> -
> - id = ++file_id;
> - sprintf(file_str, "%s/%u.bmp", RAM_PATH, id);
> -
> - f = fopen(file_str, "wb");
> - if (!f) {
> - spice_error("Error creating bmp");
> - return;
> - }
> -
> - /* writing the bmp v3 header */
> - fprintf(f, "BM");
> - fwrite(&file_size, sizeof(file_size), 1, f);
> - tmp_u16 = 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);
> - fwrite(&bitmap_data_offset, sizeof(bitmap_data_offset), 1, f);
> - tmp_u32 = header_size - 14;
> - fwrite(&tmp_u32, sizeof(tmp_u32), 1, f); // sub header size
> - tmp_32 = bitmap->x;
> - fwrite(&tmp_32, sizeof(tmp_32), 1, f);
> - tmp_32 = bitmap->y;
> - fwrite(&tmp_32, sizeof(tmp_32), 1, f);
> -
> - tmp_u16 = 1;
> - fwrite(&tmp_u16, sizeof(tmp_u16), 1, f); // color plane
> - fwrite(&n_pixel_bits, sizeof(n_pixel_bits), 1, f); // pixel depth
> -
> - tmp_u32 = 0;
> - fwrite(&tmp_u32, sizeof(tmp_u32), 1, f); // compression method
> -
> - tmp_u32 = 0; //file_size - bitmap_data_offset;
> - fwrite(&tmp_u32, sizeof(tmp_u32), 1, f); // image size
> - 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
> - fwrite(&tmp_u32, sizeof(tmp_u32), 1, f);
> - tmp_u32 = 0;
> - fwrite(&tmp_u32, sizeof(tmp_u32), 1, f);
> -
> - if (plt) {
> - dump_palette(f, plt);
> - }
> - /* writing the data */
> - for (i = 0; i < bitmap->data->num_chunks; i++) {
> - SpiceChunk *chunk = &bitmap->data->chunk[i];
> - int num_lines = chunk->len / bitmap->stride;
> - for (i = 0; i < num_lines; i++) {
> - dump_line(f, chunk->data + (i * bitmap->stride), n_pixel_bits, bitmap->x, row_size);
> - }
> - }
> - fclose(f);
> -}
> -
> -#endif
> diff --git a/server/spice_bitmap_utils.c b/server/spice_bitmap_utils.c
> new file mode 100644
> index 0000000..1fbd7de
> --- /dev/null
> +++ b/server/spice_bitmap_utils.c
> @@ -0,0 +1,152 @@
> +#include <stdio.h>
> +
> +#include "common/log.h"
> +#include "common/draw.h"
> +
> +#include "spice_bitmap_utils.h"
> +
> +#define RAM_PATH "/tmp/tmpfs"
> +
> +static void dump_palette(FILE *f, SpicePalette* plt)
> +{
> + int i;
> + for (i = 0; i < plt->num_ents; i++) {
> + fwrite(plt->ents + i, sizeof(uint32_t), 1, f);
> + }
> +}
> +
> +static void dump_line(FILE *f, uint8_t* line, uint16_t n_pixel_bits, int width, int row_size)
> +{
> + int i;
> + int copy_bytes_size = SPICE_ALIGN(n_pixel_bits * width, 8) / 8;
> +
> + fwrite(line, 1, copy_bytes_size, f);
> + if (row_size > copy_bytes_size) {
> + // each line should be 4 bytes aligned
> + for (i = copy_bytes_size; i < row_size; i++) {
> + fprintf(f, "%c", 0);
> + }
> + }
> +}
> +void dump_bitmap(SpiceBitmap *bitmap)
> +{
> + static uint32_t file_id = 0;
> +
> + char file_str[200];
> + int rgb = TRUE;
> + uint16_t n_pixel_bits;
> + SpicePalette *plt = NULL;
> + uint32_t id;
> + int row_size;
> + uint32_t file_size;
> + int alpha = 0;
> + uint32_t header_size = 14 + 40;
> + uint32_t bitmap_data_offset;
> + uint32_t tmp_u32;
> + int32_t tmp_32;
> + uint16_t tmp_u16;
> + FILE *f;
> + int i;
> +
> + switch (bitmap->format) {
> + case SPICE_BITMAP_FMT_1BIT_BE:
> + case SPICE_BITMAP_FMT_1BIT_LE:
> + rgb = FALSE;
> + n_pixel_bits = 1;
> + break;
> + case SPICE_BITMAP_FMT_4BIT_BE:
> + case SPICE_BITMAP_FMT_4BIT_LE:
> + rgb = FALSE;
> + n_pixel_bits = 4;
> + break;
> + case SPICE_BITMAP_FMT_8BIT:
> + rgb = FALSE;
> + n_pixel_bits = 8;
> + break;
> + case SPICE_BITMAP_FMT_16BIT:
> + n_pixel_bits = 16;
> + break;
> + case SPICE_BITMAP_FMT_24BIT:
> + n_pixel_bits = 24;
> + break;
> + case SPICE_BITMAP_FMT_32BIT:
> + n_pixel_bits = 32;
> + break;
> + case SPICE_BITMAP_FMT_RGBA:
> + n_pixel_bits = 32;
> + alpha = 1;
> + break;
> + default:
> + spice_error("invalid bitmap format %u", bitmap->format);
> + }
> +
> + if (!rgb) {
> + if (!bitmap->palette) {
> + return; // dont dump masks.
> + }
> + plt = bitmap->palette;
> + }
> + row_size = (((bitmap->x * 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);
> +
> + id = ++file_id;
> + sprintf(file_str, "%s/%u.bmp", RAM_PATH, id);
> +
> + f = fopen(file_str, "wb");
> + if (!f) {
> + spice_error("Error creating bmp");
> + return;
> + }
> +
> + /* writing the bmp v3 header */
> + fprintf(f, "BM");
> + fwrite(&file_size, sizeof(file_size), 1, f);
> + tmp_u16 = 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);
> + fwrite(&bitmap_data_offset, sizeof(bitmap_data_offset), 1, f);
> + tmp_u32 = header_size - 14;
> + fwrite(&tmp_u32, sizeof(tmp_u32), 1, f); // sub header size
> + tmp_32 = bitmap->x;
> + fwrite(&tmp_32, sizeof(tmp_32), 1, f);
> + tmp_32 = bitmap->y;
> + fwrite(&tmp_32, sizeof(tmp_32), 1, f);
> +
> + tmp_u16 = 1;
> + fwrite(&tmp_u16, sizeof(tmp_u16), 1, f); // color plane
> + fwrite(&n_pixel_bits, sizeof(n_pixel_bits), 1, f); // pixel depth
> +
> + tmp_u32 = 0;
> + fwrite(&tmp_u32, sizeof(tmp_u32), 1, f); // compression method
> +
> + tmp_u32 = 0; //file_size - bitmap_data_offset;
> + fwrite(&tmp_u32, sizeof(tmp_u32), 1, f); // image size
> + 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
> + fwrite(&tmp_u32, sizeof(tmp_u32), 1, f);
> + tmp_u32 = 0;
> + fwrite(&tmp_u32, sizeof(tmp_u32), 1, f);
> +
> + if (plt) {
> + dump_palette(f, plt);
> + }
> + /* writing the data */
> + for (i = 0; i < bitmap->data->num_chunks; i++) {
> + SpiceChunk *chunk = &bitmap->data->chunk[i];
> + int num_lines = chunk->len / bitmap->stride;
> + for (i = 0; i < num_lines; i++) {
> + dump_line(f, chunk->data + (i * bitmap->stride), n_pixel_bits, bitmap->x, row_size);
> + }
> + }
> + fclose(f);
> +}
> +
> +
redundant end of line.
> diff --git a/server/spice_bitmap_utils.h b/server/spice_bitmap_utils.h
> new file mode 100644
> index 0000000..ae4939f
> --- /dev/null
> +++ b/server/spice_bitmap_utils.h
> @@ -0,0 +1,6 @@
> +#ifndef H_SPICE_BITMAP_UTILS
> +#define H_SPICE_BITMAP_UTILS
> +
> +void dump_bitmap(SpiceBitmap *bitmap);
> +
> +#endif
>
More information about the Spice-devel
mailing list