diff options
Diffstat (limited to 'common/os_calls.c')
| -rw-r--r-- | common/os_calls.c | 160 |
1 files changed, 158 insertions, 2 deletions
diff --git a/common/os_calls.c b/common/os_calls.c index ef057497..bfea9031 100644 --- a/common/os_calls.c +++ b/common/os_calls.c @@ -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 |
