2011-09-02 07:00:07 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-09-02 07:00:07 +04:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:09:01 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2011-09-02 07:00:07 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <freerdp/types.h>
|
|
|
|
|
|
|
|
#include <freerdp/utils/bitmap.h>
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE magic[2];
|
2012-09-19 05:07:47 +04:00
|
|
|
} BITMAP_MAGIC;
|
2011-09-02 07:00:07 +04:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 filesz;
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 creator1;
|
|
|
|
UINT16 creator2;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 bmp_offset;
|
2012-09-19 05:07:47 +04:00
|
|
|
} BITMAP_CORE_HEADER;
|
2011-09-02 07:00:07 +04:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 header_sz;
|
|
|
|
INT32 width;
|
|
|
|
INT32 height;
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 nplanes;
|
|
|
|
UINT16 bitspp;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 compress_type;
|
|
|
|
UINT32 bmp_bytesz;
|
|
|
|
INT32 hres;
|
|
|
|
INT32 vres;
|
|
|
|
UINT32 ncolors;
|
|
|
|
UINT32 nimpcolors;
|
2012-09-19 05:07:47 +04:00
|
|
|
} BITMAP_INFO_HEADER;
|
2011-09-02 07:00:07 +04:00
|
|
|
|
|
|
|
void freerdp_bitmap_write(char* filename, void* data, int width, int height, int bpp)
|
|
|
|
{
|
|
|
|
FILE* fp;
|
2012-09-19 05:07:47 +04:00
|
|
|
BITMAP_MAGIC magic;
|
|
|
|
BITMAP_CORE_HEADER header;
|
|
|
|
BITMAP_INFO_HEADER info_header;
|
2011-09-02 07:00:07 +04:00
|
|
|
|
|
|
|
fp = fopen(filename, "w+b");
|
|
|
|
|
|
|
|
if (fp == NULL)
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "failed to open file %s\n", filename);
|
2011-09-02 07:00:07 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
magic.magic[0] = 'B';
|
|
|
|
magic.magic[1] = 'M';
|
|
|
|
|
|
|
|
header.creator1 = 0;
|
|
|
|
header.creator2 = 0;
|
|
|
|
|
|
|
|
header.bmp_offset =
|
2012-09-19 05:07:47 +04:00
|
|
|
sizeof(BITMAP_MAGIC) +
|
|
|
|
sizeof(BITMAP_CORE_HEADER) +
|
|
|
|
sizeof(BITMAP_INFO_HEADER);
|
2011-09-02 07:00:07 +04:00
|
|
|
|
|
|
|
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;
|
2012-09-19 05:09:59 +04:00
|
|
|
info_header.header_sz = sizeof(BITMAP_INFO_HEADER);
|
2011-09-02 07:00:07 +04:00
|
|
|
|
2012-09-19 05:07:47 +04:00
|
|
|
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);
|
2011-09-02 07:00:07 +04:00
|
|
|
fwrite((void*) data, info_header.bmp_bytesz, 1, fp);
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|