Source

watches / lunar / image.c

Full commit
#include "image.h"

/** We need enough memory to buffer a screen row.
 * \todo Determine how much slower image drawing is if
 * we read a pixel at a time
 */
static uint8_t image_row[SCREEN_WIDTH*3];

#if 0
/** Draw a single row from an image at the given offset */
static void
image_draw_row(
	uint32_t x,
	uint32_t y,
	uint32_t offset
)
{
	spiflash_read(offset, image_row, sizeof(image_row));
	pulse_set_draw_window(
		x,
		y,
		x + DIGIT_WIDTH - 1,
		y
	);

	for (unsigned j = 0 ; j < DIGIT_WIDTH ; j++)
	{
		uint8_t * pixel = image_row[j];
		color24_t c = { pixel[0], pixel[1], pixel[2] };
		pulse_draw_point24(c);
	}
}
#endif


void
image_draw_gray(
	PulseResource id,
	int32_t x,
	int32_t y
)
{
	image_resource_t resource;
	image_resource(id, &resource);
	
	uint32_t offset = resource.offset;
	const uint32_t width = 3 * resource.width;

	for (unsigned row = 0 ; row < resource.height ; row++)
	{
		spiflash_read(offset, image_row, width);
		offset += width;

		pulse_set_draw_window(
			x,
			y + row,
			x + width - 1,
			y + row
		);

		for (unsigned col = 0 ; col < width ; col++)
		{
			uint8_t lum = image_row[col];
			color24_t color = { lum, lum, lum };
			pulse_draw_point24(color);
		}
	}
}