Skip to content
Snippets Groups Projects
Select Git revision
  • 65efd6bc70c9ff705209a8a537e6ec4d39fa76f0
  • master default protected
  • Stormwind
  • patch-1
  • schneider/bsec
  • dx/meh-bdf-to-stm
  • dx/somewhat-more-dynamic-config
  • rahix/proper-sleep
  • dx/flatten-config-module
  • genofire/ble-follow-py
  • schneider/ble-stability
  • schneider/ble-stability-new-phy
  • add_menu_vibration
  • plaetzchen/ios-workaround
  • blinkisync-as-preload
  • schneider/max30001-pycardium
  • schneider/max30001-epicaridum
  • schneider/max30001
  • schneider/stream-locks
  • schneider/fundamental-test
  • schneider/ble-buffers
  • v1.12
  • v1.11
  • v1.10
  • v1.9
  • v1.8
  • v1.7
  • v1.6
  • v1.5
  • v1.4
  • v1.3
  • v1.2
  • v1.1
  • v1.0
  • release-1
  • bootloader-v1
  • v0.0
37 results

framebuffer.c

Blame
  • Forked from card10 / firmware
    1219 commits behind the upstream repository.
    Mateusz Zalega's avatar
    Mateusz Zalega authored and Rahix committed
    This commit substitutes the vendor gfx library with a completely
    new implementation.  It also adds a text-buffer mode.
    
    Signed-off-by: default avatarMateusz Zalega <mateusz@appliedsourcery.com>
    a26664be
    History
    framebuffer.c 2.01 KiB
    #include "framebuffer.h"
    
    void fb_clear_to_color(struct framebuffer *fb, Color c)
    {
    	for (int y = 0; y < fb->height; y++) {
    		for (int x = 0; x < fb->width; x++)
    			fb_setpixel(fb, x, y, c);
    	}
    }
    
    void fb_clear(struct framebuffer *fb)
    {
    	Color c = fb->encode_color_rgb(fb, 0, 0, 0);
    	fb_clear_to_color(fb, c);
    }
    
    Color fb_encode_color_rgb(struct framebuffer *fb, int r, int g, int b)
    {
    	return fb->encode_color_rgb(fb, r, g, b);
    }
    
    Color fb_encode_color_rgb_f(struct framebuffer *fb, float r, float g, float b)
    {
    	float r8 = r > 1.0f ? 1.0f : (uint8_t)(r * 255.0f);
    	float g8 = g > 1.0f ? 1.0f : (uint8_t)(g * 255.0f);
    	float b8 = b > 1.0f ? 1.0f : (uint8_t)(b * 255.0f);
    
    	r8 = r8 < .0f ? .0f : r8;
    	g8 = g8 < .0f ? .0f : g8;
    	b8 = b8 < .0f ? .0f : b8;
    
    	return fb->encode_color_rgb(fb, r8, g8, b8);
    }
    
    void fb_copy_raw(struct framebuffer *fb, const void *data, size_t size)
    {
    	size_t to_copy = size < fb->stride ? size : fb->stride;
    	memcpy(fb->data, data, to_copy);
    }
    
    void fb_update(struct framebuffer *fb)
    {
    	fb->update(fb);
    }
    
    size_t fb_bytes_per_pixel(const struct framebuffer *fb)
    {
    	const int pixels = fb->height * fb->width;
    	return fb->stride / pixels;
    }
    
    void *fb_pixel(struct framebuffer *fb, int x, int y)
    {
    	int xo;
    	int yo;
    
    	switch (fb->orientation) {
    	case FB_O_0:
    		xo = x;
    		yo = y;
    		break;
    	case FB_O_90:
    		xo = fb->width - y - 1;
    		yo = x;
    		break;
    	case FB_O_180:
    		xo = fb->width - x - 1;
    		yo = fb->height - y - 1;
    		break;
    	case FB_O_270:
    		xo = y;
    		yo = fb->height - x - 1;
    		break;
    	default:
    		return NULL;
    	}
    
    	if (xo < 0 || yo < 0)
    		return NULL;
    	if (xo >= fb->width || yo >= fb->height)
    		return NULL;
    
    	const size_t bpp = fb_bytes_per_pixel(fb);
    	return (void *)(fb->data) + yo * fb->width * bpp + xo * bpp;
    }
    
    void fb_setpixel(struct framebuffer *fb, int x, int y, Color c)
    {
    	uint8_t *pixel = fb_pixel(fb, x, y);
    	if (pixel == NULL)
    		return;
    
    	const uint8_t *color = (const uint8_t *)(&c);
    	const size_t bpp     = fb_bytes_per_pixel(fb);
    	switch (bpp) {
    	default:
    	case 2:
    		pixel[1] = color[0];
    		pixel[0] = color[1];
    	}
    }