Last active
November 23, 2022 01:48
-
-
Save Dewb/6c33c28d798eaa5d50ee421e02315a45 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/matron/src/hardware/screen.c b/matron/src/hardware/screen.c | |
index 221ca9b4..0ad9aefc 100644 | |
--- a/matron/src/hardware/screen.c | |
+++ b/matron/src/hardware/screen.c | |
@@ -88,8 +88,14 @@ static double text_xy[2]; | |
void screen_init(void) { | |
ssd1322_init(); | |
ssd1322_set_refresh_rate(120); | |
+ | |
+ int w = 128, h = 64; | |
+ cairo_format_t format = CAIRO_FORMAT_A8; | |
+ uint8_t* buffer = calloc(w * h * 1.5, sizeof(uint8_t)); | |
+ // create chroma plane | |
+ memset(buffer + w * h, 0x88, w*h/2); | |
- surface = cairo_image_surface_create(CAIRO_FORMAT_A8, 128, 64); | |
+ surface = cairo_image_surface_create_for_data(buffer, format, w, h, cairo_format_stride_for_width(format, w)); | |
+ | |
cr = cr_primary = cairo_create(surface); | |
status = FT_Init_FreeType(&value); | |
@@ -216,6 +222,7 @@ void screen_init(void) { | |
void screen_deinit(void) { | |
ssd1322_deinit(); | |
+ free(cairo_image_surface_get_data(surface)); | |
CHECK_CR | |
cairo_destroy(cr); | |
@@ -633,8 +640,12 @@ void screen_set_operator(int i) { | |
screen_surface_t *screen_surface_new(double width, double height) { | |
int w = (int)floor(width); | |
int h = (int)floor(height); | |
+ | |
+ uint8_t* buffer = calloc(w * h * 1.5, sizeof(uint8_t)); | |
+ // create chroma plane | |
+ memset(buffer + w * h, 0x88, w*h/2); | |
+ | |
cairo_format_t format = CAIRO_FORMAT_A8; | |
- cairo_surface_t *image = cairo_image_surface_create(format, w, h); | |
+ cairo_surface_t *image = cairo_image_surface_create_for_data(buffer, format, w, h, cairo_format_stride_for_width(format, w)); | |
cairo_status_t status = cairo_surface_status(image); | |
if (status == CAIRO_STATUS_SUCCESS) { | |
return (screen_surface_t *)image; | |
@@ -656,6 +667,7 @@ screen_surface_t *screen_surface_load_png(const char *filename) { | |
void screen_surface_free(screen_surface_t *s) { | |
CHECK_CR | |
// fprintf(stderr, "screen_surface_free(%p)\n", s); | |
+ free(cairo_image_surface_get_data((cairo_surface_t *)s)); | |
cairo_surface_destroy((cairo_surface_t *)s); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment