mirror of https://github.com/FreeRDP/FreeRDP
libwinpr-utils: centralize bitmap utils
This commit is contained in:
parent
1491c5a7f9
commit
320b1d35ed
|
@ -1,35 +0,0 @@
|
||||||
/**
|
|
||||||
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
||||||
* Bitmap File Format Utils
|
|
||||||
*
|
|
||||||
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
||||||
*
|
|
||||||
* 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 FREERDP_UTILS_BITMAP_H
|
|
||||||
#define FREERDP_UTILS_BITMAP_H
|
|
||||||
|
|
||||||
#include <freerdp/api.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
FREERDP_API void freerdp_bitmap_write(char* filename, void* data, int width, int height, int bpp);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* FREERDP_UTILS_BITMAP_H */
|
|
|
@ -26,11 +26,11 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <winpr/crt.h>
|
#include <winpr/crt.h>
|
||||||
|
#include <winpr/image.h>
|
||||||
|
|
||||||
#include <freerdp/api.h>
|
#include <freerdp/api.h>
|
||||||
#include <freerdp/freerdp.h>
|
#include <freerdp/freerdp.h>
|
||||||
#include <freerdp/constants.h>
|
#include <freerdp/constants.h>
|
||||||
#include <freerdp/utils/bitmap.h>
|
|
||||||
#include <freerdp/codec/color.h>
|
#include <freerdp/codec/color.h>
|
||||||
#include <freerdp/codec/bitmap.h>
|
#include <freerdp/codec/bitmap.h>
|
||||||
#include <freerdp/codec/rfx.h>
|
#include <freerdp/codec/rfx.h>
|
||||||
|
@ -828,7 +828,7 @@ void gdi_surface_bits(rdpContext* context, SURFACE_BITS_COMMAND* surface_bits_co
|
||||||
|
|
||||||
#ifdef DUMP_REMOTEFX_TILES
|
#ifdef DUMP_REMOTEFX_TILES
|
||||||
sprintf(tile_bitmap, "/tmp/rfx/tile_%d.bmp", tilenum++);
|
sprintf(tile_bitmap, "/tmp/rfx/tile_%d.bmp", tilenum++);
|
||||||
freerdp_bitmap_write(tile_bitmap, gdi->tile->bitmap->data, 64, 64, 32);
|
winpr_bitmap_write(tile_bitmap, gdi->tile->bitmap->data, 64, 64, 32);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@ set(MODULE_PREFIX "FREERDP_UTILS")
|
||||||
|
|
||||||
set(${MODULE_PREFIX}_SRCS
|
set(${MODULE_PREFIX}_SRCS
|
||||||
event.c
|
event.c
|
||||||
bitmap.c
|
|
||||||
passphrase.c
|
passphrase.c
|
||||||
pcap.c
|
pcap.c
|
||||||
profiler.c
|
profiler.c
|
||||||
|
|
|
@ -1,110 +0,0 @@
|
||||||
/**
|
|
||||||
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
||||||
* Bitmap File Format Utils
|
|
||||||
*
|
|
||||||
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
|
||||||
#include "config.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include <freerdp/types.h>
|
|
||||||
|
|
||||||
#include <freerdp/utils/debug.h>
|
|
||||||
#include <freerdp/utils/bitmap.h>
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
BYTE magic[2];
|
|
||||||
} BITMAP_MAGIC;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
UINT32 filesz;
|
|
||||||
UINT16 creator1;
|
|
||||||
UINT16 creator2;
|
|
||||||
UINT32 bmp_offset;
|
|
||||||
} BITMAP_CORE_HEADER;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
UINT32 header_sz;
|
|
||||||
INT32 width;
|
|
||||||
INT32 height;
|
|
||||||
UINT16 nplanes;
|
|
||||||
UINT16 bitspp;
|
|
||||||
UINT32 compress_type;
|
|
||||||
UINT32 bmp_bytesz;
|
|
||||||
INT32 hres;
|
|
||||||
INT32 vres;
|
|
||||||
UINT32 ncolors;
|
|
||||||
UINT32 nimpcolors;
|
|
||||||
} BITMAP_INFO_HEADER;
|
|
||||||
|
|
||||||
void freerdp_bitmap_write(char* filename, void* data, int width, int height, int bpp)
|
|
||||||
{
|
|
||||||
FILE* fp;
|
|
||||||
BITMAP_MAGIC magic;
|
|
||||||
BITMAP_CORE_HEADER header;
|
|
||||||
BITMAP_INFO_HEADER info_header;
|
|
||||||
|
|
||||||
fp = fopen(filename, "w+b");
|
|
||||||
|
|
||||||
if (fp == NULL)
|
|
||||||
{
|
|
||||||
DEBUG_WARN( "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(BITMAP_MAGIC) +
|
|
||||||
sizeof(BITMAP_CORE_HEADER) +
|
|
||||||
sizeof(BITMAP_INFO_HEADER);
|
|
||||||
|
|
||||||
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(BITMAP_INFO_HEADER);
|
|
||||||
|
|
||||||
fwrite((void*) &magic, sizeof(BITMAP_MAGIC), 1, fp);
|
|
||||||
fwrite((void*) &header, sizeof(BITMAP_CORE_HEADER), 1, fp);
|
|
||||||
fwrite((void*) &info_header, sizeof(BITMAP_INFO_HEADER), 1, fp);
|
|
||||||
fwrite((void*) data, info_header.bmp_bytesz, 1, fp);
|
|
||||||
|
|
||||||
fclose(fp);
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
/**
|
||||||
|
* WinPR: Windows Portable Runtime
|
||||||
|
* Image Utils
|
||||||
|
*
|
||||||
|
* Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||||
|
*
|
||||||
|
* 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 WINPR_IMAGE_H
|
||||||
|
#define WINPR_IMAGE_H
|
||||||
|
|
||||||
|
#include <winpr/winpr.h>
|
||||||
|
#include <winpr/wtypes.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Bitmap data structures
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct _WINPR_BITMAP_MAGIC
|
||||||
|
{
|
||||||
|
BYTE magic[2];
|
||||||
|
};
|
||||||
|
typedef struct _WINPR_BITMAP_MAGIC WINPR_BITMAP_MAGIC;
|
||||||
|
|
||||||
|
struct _WINPR_BITMAP_CORE_HEADER
|
||||||
|
{
|
||||||
|
UINT32 filesz;
|
||||||
|
UINT16 creator1;
|
||||||
|
UINT16 creator2;
|
||||||
|
UINT32 bmp_offset;
|
||||||
|
};
|
||||||
|
typedef struct _WINPR_BITMAP_CORE_HEADER WINPR_BITMAP_CORE_HEADER;
|
||||||
|
|
||||||
|
struct _WINPR_BITMAP_INFO_HEADER
|
||||||
|
{
|
||||||
|
UINT32 header_sz;
|
||||||
|
INT32 width;
|
||||||
|
INT32 height;
|
||||||
|
UINT16 nplanes;
|
||||||
|
UINT16 bitspp;
|
||||||
|
UINT32 compress_type;
|
||||||
|
UINT32 bmp_bytesz;
|
||||||
|
INT32 hres;
|
||||||
|
INT32 vres;
|
||||||
|
UINT32 ncolors;
|
||||||
|
UINT32 nimpcolors;
|
||||||
|
};
|
||||||
|
typedef struct _WINPR_BITMAP_INFO_HEADER WINPR_BITMAP_INFO_HEADER;
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
WINPR_API int winpr_bitmap_write(char* filename, BYTE* data, int width, int height, int bpp);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* WINPR_IMAGE_H */
|
|
@ -75,6 +75,7 @@ set(${MODULE_PREFIX}_SRCS
|
||||||
ini.c
|
ini.c
|
||||||
sam.c
|
sam.c
|
||||||
ntlm.c
|
ntlm.c
|
||||||
|
image.c
|
||||||
print.c
|
print.c
|
||||||
stream.c
|
stream.c
|
||||||
debug.c
|
debug.c
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
/**
|
||||||
|
* WinPR: Windows Portable Runtime
|
||||||
|
* Image Utils
|
||||||
|
*
|
||||||
|
* Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <winpr/crt.h>
|
||||||
|
|
||||||
|
#include <winpr/image.h>
|
||||||
|
|
||||||
|
int winpr_bitmap_write(char* filename, BYTE* data, int width, int height, int bpp)
|
||||||
|
{
|
||||||
|
FILE* fp;
|
||||||
|
WINPR_BITMAP_MAGIC magic;
|
||||||
|
WINPR_BITMAP_CORE_HEADER header;
|
||||||
|
WINPR_BITMAP_INFO_HEADER info_header;
|
||||||
|
|
||||||
|
fp = fopen(filename, "w+b");
|
||||||
|
|
||||||
|
if (!fp)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "failed to open file %s\n", filename);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
magic.magic[0] = 'B';
|
||||||
|
magic.magic[1] = 'M';
|
||||||
|
|
||||||
|
header.creator1 = 0;
|
||||||
|
header.creator2 = 0;
|
||||||
|
|
||||||
|
header.bmp_offset = sizeof(WINPR_BITMAP_MAGIC) +
|
||||||
|
sizeof(WINPR_BITMAP_CORE_HEADER) +
|
||||||
|
sizeof(WINPR_BITMAP_INFO_HEADER);
|
||||||
|
|
||||||
|
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(WINPR_BITMAP_INFO_HEADER);
|
||||||
|
|
||||||
|
fwrite((void*) &magic, sizeof(WINPR_BITMAP_MAGIC), 1, fp);
|
||||||
|
fwrite((void*) &header, sizeof(WINPR_BITMAP_CORE_HEADER), 1, fp);
|
||||||
|
fwrite((void*) &info_header, sizeof(WINPR_BITMAP_INFO_HEADER), 1, fp);
|
||||||
|
fwrite((void*) data, info_header.bmp_bytesz, 1, fp);
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
|
@ -23,88 +23,18 @@
|
||||||
|
|
||||||
#include <winpr/wlog.h>
|
#include <winpr/wlog.h>
|
||||||
|
|
||||||
|
#include <winpr/image.h>
|
||||||
|
|
||||||
#include "wlog/ImageMessage.h"
|
#include "wlog/ImageMessage.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
BYTE magic[2];
|
|
||||||
} BITMAP_MAGIC;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
UINT32 filesz;
|
|
||||||
UINT16 creator1;
|
|
||||||
UINT16 creator2;
|
|
||||||
UINT32 bmp_offset;
|
|
||||||
} BITMAP_CORE_HEADER;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
UINT32 header_sz;
|
|
||||||
INT32 width;
|
|
||||||
INT32 height;
|
|
||||||
UINT16 nplanes;
|
|
||||||
UINT16 bitspp;
|
|
||||||
UINT32 compress_type;
|
|
||||||
UINT32 bmp_bytesz;
|
|
||||||
INT32 hres;
|
|
||||||
INT32 vres;
|
|
||||||
UINT32 ncolors;
|
|
||||||
UINT32 nimpcolors;
|
|
||||||
} BITMAP_INFO_HEADER;
|
|
||||||
|
|
||||||
int WLog_ImageMessage_Write(char* filename, void* data, int width, int height, int bpp)
|
int WLog_ImageMessage_Write(char* filename, void* data, int width, int height, int bpp)
|
||||||
{
|
{
|
||||||
FILE* fp;
|
int status;
|
||||||
BITMAP_MAGIC magic;
|
|
||||||
BITMAP_CORE_HEADER header;
|
|
||||||
BITMAP_INFO_HEADER info_header;
|
|
||||||
|
|
||||||
fp = fopen(filename, "w+b");
|
status = winpr_bitmap_write(filename, data, width, height, bpp);
|
||||||
|
|
||||||
if (!fp)
|
if (status < 0)
|
||||||
{
|
|
||||||
fprintf(stderr, "failed to open file %s\n", filename);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
magic.magic[0] = 'B';
|
return 1;
|
||||||
magic.magic[1] = 'M';
|
|
||||||
|
|
||||||
header.creator1 = 0;
|
|
||||||
header.creator2 = 0;
|
|
||||||
|
|
||||||
header.bmp_offset =
|
|
||||||
sizeof(BITMAP_MAGIC) +
|
|
||||||
sizeof(BITMAP_CORE_HEADER) +
|
|
||||||
sizeof(BITMAP_INFO_HEADER);
|
|
||||||
|
|
||||||
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(BITMAP_INFO_HEADER);
|
|
||||||
|
|
||||||
fwrite((void*) &magic, sizeof(BITMAP_MAGIC), 1, fp);
|
|
||||||
fwrite((void*) &header, sizeof(BITMAP_CORE_HEADER), 1, fp);
|
|
||||||
fwrite((void*) &info_header, sizeof(BITMAP_INFO_HEADER), 1, fp);
|
|
||||||
fwrite((void*) data, info_header.bmp_bytesz, 1, fp);
|
|
||||||
|
|
||||||
fclose(fp);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue