static bool __encode_bitmap_file(const void *data, int width, int height, const char *file)
{
- struct {
- unsigned char magic[2];
- } bmpfile_magic = { {'B', 'M'} };
-
- struct {
- unsigned int filesz;
- unsigned short creator1;
- unsigned short creator2;
- unsigned int bmp_offset;
- } bmpfile_header = { 0, 0, 0, 0x36 };
-
- struct {
- unsigned int header_sz;
- unsigned int width;
- unsigned int height;
- unsigned short nplanes;
- unsigned short bitspp;
- unsigned int compress_type;
- unsigned int bmp_bytesz;
- unsigned int hres;
- unsigned int vres;
- unsigned int ncolors;
- unsigned int nimpcolors;
- } bmp_dib_v3_header_t = { 0x28, 0, 0, 1, 24, 0, 0, 0, 0, 0, 0 };
-
- struct stat file_info;
- if (0 != lstat(file, &file_info)) {
- MAPS_LOGE("lstat failed"); //LCOV_EXCL_LINE
- return false;
- }
- if (S_ISLNK(file_info.st_mode)) {
- MAPS_LOGE("symbolic linked file"); //LCOV_EXCL_LINE
- return false;
- }
-
- unsigned int *blocks;
- FILE *fp = fopen(file, "w+");
- int i;
-
- if (fp == NULL) {
- MAPS_LOGE("fopen fail"); //LCOV_EXCL_LINE
- return false;
- }
- bmpfile_header.filesz = sizeof(bmpfile_magic) + sizeof(bmpfile_header) + sizeof(bmp_dib_v3_header_t) + (width * height * 3);
- bmp_dib_v3_header_t.header_sz = sizeof(bmp_dib_v3_header_t);
- bmp_dib_v3_header_t.width = width;
- bmp_dib_v3_header_t.height = -height;
- bmp_dib_v3_header_t.bmp_bytesz = width * height * 3;
-
- fwrite(&bmpfile_magic, sizeof(bmpfile_magic), 1, fp);
- fwrite(&bmpfile_header, sizeof(bmpfile_header), 1, fp);
- fwrite(&bmp_dib_v3_header_t, sizeof(bmp_dib_v3_header_t), 1, fp);
- blocks = (unsigned int *)data;
-
- for (i = 0; i < height * width; i++) {
- fwrite(&blocks[i], 3, 1, fp);
- }
- fclose(fp);
- return true;
+ struct {
+ unsigned char magic[2];
+ } bmpfile_magic = { {'B', 'M'} };
+
+ struct {
+ unsigned int filesz;
+ unsigned short creator1;
+ unsigned short creator2;
+ unsigned int bmp_offset;
+ } bmpfile_header = { 0, 0, 0, 0x36 };
+
+ struct {
+ unsigned int header_sz;
+ unsigned int width;
+ unsigned int height;
+ unsigned short nplanes;
+ unsigned short bitspp;
+ unsigned int compress_type;
+ unsigned int bmp_bytesz;
+ unsigned int hres;
+ unsigned int vres;
+ unsigned int ncolors;
+ unsigned int nimpcolors;
+ } bmp_dib_v3_header_t = { 0x28, 0, 0, 1, 24, 0, 0, 0, 0, 0, 0 };
+
+ struct stat file_info;
+ if (0 != lstat(file, &file_info)) {
+ MAPS_LOGE("lstat failed"); //LCOV_EXCL_LINE
+ return false;
+ }
+ if (S_ISLNK(file_info.st_mode)) {
+ MAPS_LOGE("symbolic linked file"); //LCOV_EXCL_LINE
+ return false;
+ }
+
+ unsigned int *blocks;
+ FILE *fp = fopen(file, "w+");
+ int i;
+
+ if (fp == NULL) {
+ MAPS_LOGE("fopen fail"); //LCOV_EXCL_LINE
+ return false;
+ }
+ bmpfile_header.filesz = sizeof(bmpfile_magic) + sizeof(bmpfile_header) + sizeof(bmp_dib_v3_header_t) + (width * height * 3);
+ bmp_dib_v3_header_t.header_sz = sizeof(bmp_dib_v3_header_t);
+ bmp_dib_v3_header_t.width = width;
+ bmp_dib_v3_header_t.height = -height;
+ bmp_dib_v3_header_t.bmp_bytesz = width * height * 3;
+
+ fwrite(&bmpfile_magic, sizeof(bmpfile_magic), 1, fp);
+ fwrite(&bmpfile_header, sizeof(bmpfile_header), 1, fp);
+ fwrite(&bmp_dib_v3_header_t, sizeof(bmp_dib_v3_header_t), 1, fp);
+ blocks = (unsigned int *)data;
+
+ for (i = 0; i < height * width; i++)
+ fwrite(&blocks[i], 3, 1, fp);
+ fclose(fp);
+ return true;
}
static image_util_colorspace_e __convert_colorspace(maps_view_colorspace_type_e cs)