common: merge from a8

This commit is contained in:
Jay Sorg 2014-11-07 22:10:59 -08:00
parent cf5c5e6210
commit 6b0bbbeefa
3 changed files with 166 additions and 3 deletions

View File

@ -126,8 +126,12 @@ g_mk_temp_dir(const char *app_name)
{
if (!g_create_dir("/tmp/.xrdp"))
{
printf("g_mk_temp_dir: g_create_dir failed\n");
return 1;
/* if failed, still check if it got created by someone else */
if (!g_directory_exist("/tmp/.xrdp"))
{
printf("g_mk_temp_dir: g_create_dir failed\n");
return 1;
}
}
g_chmod_hex("/tmp/.xrdp", 0x1777);
@ -3172,6 +3176,158 @@ g_time3(void)
#endif
}
/******************************************************************************/
/******************************************************************************/
struct bmp_magic
{
char magic[2];
};
struct bmp_hdr
{
unsigned int size; /* file size in bytes */
unsigned short reserved1;
unsigned short reserved2;
unsigned int offset; /* offset to image data, in bytes */
};
struct dib_hdr
{
unsigned int hdr_size;
int width;
int height;
unsigned short nplanes;
unsigned short bpp;
unsigned int compress_type;
unsigned int image_size;
int hres;
int vres;
unsigned int ncolors;
unsigned int nimpcolors;
};
/******************************************************************************/
int APP_CC
g_save_to_bmp(const char* filename, char* data, int stride_bytes,
int width, int height, int depth, int bits_per_pixel)
{
struct bmp_magic bm;
struct bmp_hdr bh;
struct dib_hdr dh;
int bytes;
int fd;
int index;
int i1;
int pixel;
int extra;
int file_stride_bytes;
char* line;
char* line_ptr;
if ((depth == 24) && (bits_per_pixel == 32))
{
}
else if ((depth == 32) && (bits_per_pixel == 32))
{
}
else
{
g_writeln("g_save_to_bpp: unimp");
return 1;
}
bm.magic[0] = 'B';
bm.magic[1] = 'M';
/* scan lines are 32 bit aligned, bottom 2 bits must be zero */
file_stride_bytes = width * ((depth + 7) / 8);
extra = file_stride_bytes;
extra = extra & 3;
extra = (4 - extra) & 3;
file_stride_bytes += extra;
bh.size = sizeof(bm) + sizeof(bh) + sizeof(dh) + height * file_stride_bytes;
bh.reserved1 = 0;
bh.reserved2 = 0;
bh.offset = sizeof(bm) + sizeof(bh) + sizeof(dh);
dh.hdr_size = sizeof(dh);
dh.width = width;
dh.height = height;
dh.nplanes = 1;
dh.bpp = depth;
dh.compress_type = 0;
dh.image_size = height * file_stride_bytes;
dh.hres = 0xb13;
dh.vres = 0xb13;
dh.ncolors = 0;
dh.nimpcolors = 0;
fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (fd == -1)
{
g_writeln("g_save_to_bpp: open error");
return 1;
}
bytes = write(fd, &bm, sizeof(bm));
if (bytes != sizeof(bm))
{
g_writeln("g_save_to_bpp: write error");
}
bytes = write(fd, &bh, sizeof(bh));
if (bytes != sizeof(bh))
{
g_writeln("g_save_to_bpp: write error");
}
bytes = write(fd, &dh, sizeof(dh));
if (bytes != sizeof(dh))
{
g_writeln("g_save_to_bpp: write error");
}
data += stride_bytes * height;
data -= stride_bytes;
if ((depth == 24) && (bits_per_pixel == 32))
{
line = malloc(file_stride_bytes);
memset(line, 0, file_stride_bytes);
for (index = 0; index < height; index++)
{
line_ptr = line;
for (i1 = 0; i1 < width; i1++)
{
pixel = ((int*)data)[i1];
*(line_ptr++) = (pixel >> 0) & 0xff;
*(line_ptr++) = (pixel >> 8) & 0xff;
*(line_ptr++) = (pixel >> 16) & 0xff;
}
bytes = write(fd, line, file_stride_bytes);
if (bytes != file_stride_bytes)
{
g_writeln("g_save_to_bpp: write error");
}
data -= stride_bytes;
}
free(line);
}
else if (depth == bits_per_pixel)
{
for (index = 0; index < height; index++)
{
bytes = write(fd, data, width * (bits_per_pixel / 8));
if (bytes != width * (bits_per_pixel / 8))
{
g_writeln("g_save_to_bpp: write error");
}
data -= stride_bytes;
}
}
else
{
g_writeln("g_save_to_bpp: unimp");
}
close(fd);
return 0;
}
/*****************************************************************************/
/* returns boolean */
int APP_CC

View File

@ -161,6 +161,8 @@ int APP_CC g_check_user_in_group(const char* username, int gid, int* ok);
int APP_CC g_time1(void);
int APP_CC g_time2(void);
int APP_CC g_time3(void);
int APP_CC g_save_to_bmp(const char* filename, char* data, int stride_bytes,
int width, int height, int depth, int bits_per_pixel);
int APP_CC g_text2bool(const char *s);
void * APP_CC g_shmat(int shmid);
int APP_CC g_shmdt(const void *shmaddr);

View File

@ -457,6 +457,7 @@
Extended order support flags. */
#define XR_ORDERFLAGS_EX_CACHE_BITMAP_REV3_SUPPORT 0x0002
#define XR_ORDERFLAGS_EX_ALTSEC_FRAME_MARKER_SUPPORT 0x0004
#define XR_ORDERFLAGS_EX_OFFSCREEN_COMPOSITE_SUPPORT 0x0100
/* drawable types */
#define WND_TYPE_BITMAP 0
@ -548,10 +549,14 @@
#define XR_CODEC_GUID_REMOTEFX \
"\x12\x2F\x77\x76\x72\xBD\x63\x44\xAF\xB3\xB7\x3C\x9C\x6F\x78\x86"
/* CODEC_GUID_JPEG 0x430C9EED1BAF4CE6869ACB8B37B66237*/
/* CODEC_GUID_JPEG 0x1BAF4CE6 9EED 430C 869ACB8B37B66237 */
#define XR_CODEC_GUID_JPEG \
"\xE6\x4C\xAF\x1B\xED\x9E\x0C\x43\x86\x9A\xCB\x8B\x37\xB6\x62\x37"
/* CODEC_GUID_PNG 0xOE0C858D 28E0 45DB ADAA0F83E57CC560 */
#define XR_CODEC_GUID_PNG \
"\x8D\x85\x0C\x0E\xE0\x28\xDB\x45\xAD\xAA\x0F\x83\xE5\x7C\xC5\x60"
#define RDP_CAPSET_SURFCMDS 0x1c
#define RDP_CAPLEN_SURFCMDS 0x0c
#define RDP_CAPSET_BMPCODECS 0x1d