Example #1
0
BMP_FILE bmp_init (void)
{
	BMP_FILE p = NULL;

	p = (BMP_FILE)malloc(sizeof(*p));
	if (p) {
		memset ((void*)p, 0, sizeof(*p));
		p->header = bmp_header_init();
		p->info = bmp_info_init();
	}

	return p;
}
Example #2
0
int cavan_font_save_bmp(struct cavan_font *font, const char *pathname, int bit_count)
{
	int fd;
	int ret;
	size_t size;
	size_t color_table_size;
	struct bmp_header *header;

	color_table_size = bmp_get_color_table_size(bit_count);
	size = sizeof(*header) + font->width * font->height * bit_count / 8;
	size += color_table_size * sizeof(struct bmp_color_table_entry);
	fd = file_mmap(pathname, (void **) &header, &size, O_RDWR | O_CREAT | O_TRUNC);
	if (fd < 0)
	{
		pr_red_info("file_mmap");
		return fd;
	}

	bmp_header_init(header, font->width, font->height, bit_count);

	switch (bit_count)
	{
	case 8:
		{
			u8 *pixel;
			const byte *body;
			struct bmp_color_table_entry *colors = (struct bmp_color_table_entry *) (header + 1);

			colors[0].red = colors[0].green = colors[0].blue = 0x00;
			colors[1].red = colors[1].green = colors[1].blue = 0xFF;
			colors[0].reserved = colors[1].reserved = 0x00;

			pixel = (u8 *) (colors + color_table_size);

			for (body = font->body + font->width * (font->height - 1); body >= font->body; body -= font->width * 2)
			{
				const byte *body_end;

				for (body_end = body + font->width; body < body_end; body++, pixel++)
				{
					*pixel = (*body) == 0 ? 0 : 1;
				}
			}
		}
		break;

	case 16:
		{
			u16 *pixel = (u16 *) (header + 1);
			const byte *body;

			for (body = font->body + font->width * (font->height - 1); body >= font->body; body -= font->width * 2)
			{
				const byte *body_end;

				for (body_end = body + font->width; body < body_end; body++, pixel++)
				{
					*pixel = (*body) == 0 ? 0x0000 : 0xFFFF;
				}
			}
		}
		break;

	case 24:
		{
			byte *pixel = (byte *) (header + 1);
			const byte *body;

			for (body = font->body + font->width * (font->height - 1); body >= font->body; body -= font->width * 2)
			{
				const byte *body_end;

				for (body_end = body + font->width; body < body_end; body++, pixel += 3)
				{
					pixel[0] = pixel[1] = pixel[2] = (*body) == 0 ? 0x00 : 0xFF;
				}
			}
		}
		break;

	case 32:
		{
			u32 *pixel = (u32 *) (header + 1);
			const byte *body;

			for (body = font->body + font->width * (font->height - 1); body >= font->body; body -= font->width * 2)
			{
				const byte *body_end;

				for (body_end = body + font->width; body < body_end; body++, pixel++)
				{
					*pixel = (*body) == 0 ? 0x00000000 : 0xFFFFFFFF;
				}
			}
		}
		break;

	default:
		pr_red_info("unknown bit_count = %d", bit_count);
		ret = -EINVAL;
		goto out_file_unmap;
	}

	ret = 0;
out_file_unmap:
	file_unmap(fd, header, size);
	return ret;
}