ER ev3_image_load()

in ev3-api/src/ev3api_lcd.c [51:80]


ER ev3_image_load(const memfile_t *p_memfile, image_t *p_image) {
	ER ercd;

	CHECK_COND(p_memfile != NULL && p_memfile->buffer != NULL, E_PAR);
	CHECK_COND(p_image != NULL, E_PAR);

	bitmap_t bitmap;
	ercd = bmpfile_read_header(p_memfile->buffer, p_memfile->filesz, &bitmap.width, &bitmap.height);
	if (ercd != E_OK) goto error_exit;

	bitmap.pixels = malloc(BITMAP_PIXELS_SIZE(bitmap.width, bitmap.height));
	CHECK_COND(bitmap.pixels != NULL, E_NOMEM);

	ercd = bmpfile_to_bitmap(p_memfile->buffer, p_memfile->filesz, &bitmap);
	if (ercd != E_OK) goto error_exit;

	p_image->height = bitmap.height;
	p_image->width = bitmap.width;
	p_image->data = bitmap.pixels;

	ercd = E_OK;

error_exit:
	if (ercd != E_OK) {
		p_image->height = 0;
		p_image->width = 0;
		p_image->data = NULL;
	}
	return ercd;
}