From 957e3f99f492443d6b987b912e03dbc957d0f38c Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Fri, 15 Nov 2024 16:07:10 +0000 Subject: [PATCH] Use built-in gfx draw function - save a few bytes on Pixl.js --- libs/graphics/graphics.c | 13 ------------- libs/graphics/graphics.h | 2 -- libs/pixljs/jswrap_pixljs.c | 9 +++++---- 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/libs/graphics/graphics.c b/libs/graphics/graphics.c index 7939fa48db..4c13d7d7d1 100644 --- a/libs/graphics/graphics.c +++ b/libs/graphics/graphics.c @@ -867,19 +867,6 @@ void graphicsFillPoly(JsGraphics *gfx, int points, short *vertices) { } } -/// Draw a simple 1bpp image in foreground colour -void graphicsDrawImage1bpp(JsGraphics *gfx, int x1, int y1, int width, int height, const unsigned char *pixelData) { - int pixel = 256|*(pixelData++); - int x,y; - for (y=y1;ydata.fgColor); - pixel = pixel<<1; - if (pixel&65536) pixel = 256|*(pixelData++); - } - } -} - /// Scroll the graphics device (in user coords). X>0 = to right, Y >0 = down void graphicsScroll(JsGraphics *gfx, int xdir, int ydir) { // Ensure we flip coordinate system if needed diff --git a/libs/graphics/graphics.h b/libs/graphics/graphics.h index d4c773c2da..75c4fa3ae4 100644 --- a/libs/graphics/graphics.h +++ b/libs/graphics/graphics.h @@ -222,8 +222,6 @@ void graphicsDrawLine(JsGraphics *gfx, int x1, int y1, int x2, int y2); void graphicsDrawLineAA(JsGraphics *gfx, int ix1, int iy1, int ix2, int iy2); ///< antialiased drawline. each pixel is 1/16th void graphicsDrawCircleAA(JsGraphics *gfx, int x, int y, int r); void graphicsFillPoly(JsGraphics *gfx, int points, short *vertices); ///< each pixel is 1/16th a pixel may overwrite vertices... -/// Draw a simple 1bpp image in foreground colour -void graphicsDrawImage1bpp(JsGraphics *gfx, int x1, int y1, int width, int height, const unsigned char *pixelData); /// Scroll the graphics device (in user coords). X>0 = to right, Y >0 = down void graphicsScroll(JsGraphics *gfx, int xdir, int ydir); diff --git a/libs/pixljs/jswrap_pixljs.c b/libs/pixljs/jswrap_pixljs.c index a29d184692..5598965483 100644 --- a/libs/pixljs/jswrap_pixljs.c +++ b/libs/pixljs/jswrap_pixljs.c @@ -371,7 +371,7 @@ void jswrap_pixljs_init() { graphicsGetFromVar(&gfx, graphics); // Set initial image const unsigned char PIXLJS_IMG[] = { - 251, 239, 135, 192, 0, 0, 31, 0, 0, 0, 125, 247, 195, 224, 0, 0, 15, 128, 0, + 81,34,1, 251, 239, 135, 192, 0, 0, 31, 0, 0, 0, 125, 247, 195, 224, 0, 0, 15, 128, 0, 0, 62, 251, 225, 240, 0, 0, 7, 192, 0, 0, 31, 125, 240, 248, 0, 0, 3, 224, 0, 0, 15, 190, 248, 124, 0, 0, 1, 240, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 224, 62, 0, 15, 128, 248, 124, 0, 0, 1, 240, 31, 0, 7, 192, 124, 62, 0, 0, 0, @@ -389,6 +389,7 @@ void jswrap_pixljs_init() { 0, 0, 0, 0, 0, 0, 0, 0, 1, 224, 0, 0, 0, 0, 0, 0, 0, 0, 7, 224, 0, 0, 0, 0, 0, 0, 0, 0, 3, 240, 0, 0, 0, 0, 0, 0, 0, 0, 1, 240, 0, 63 }; + JsVar *img = jsvNewNativeString((char*)PIXLJS_IMG, sizeof(PIXLJS_IMG)); // Create 'flip' fn JsVar *fn; @@ -435,12 +436,12 @@ void jswrap_pixljs_init() { for (int i=128;i>24;i-=4) { lcd_flip_gfx(&gfx); graphicsClear(&gfx); - graphicsDrawImage1bpp(&gfx,i,15,81,34,PIXLJS_IMG); + jswrap_graphics_drawImage(graphics, img, i, 15, NULL); } } else { // if a standard reset, just display logo graphicsClear(&gfx); - graphicsDrawImage1bpp(&gfx,24,15,81,34,PIXLJS_IMG); + jswrap_graphics_drawImage(graphics, img, 24, 15, NULL); } jswrap_graphics_drawCString(&gfx,28,39,JS_VERSION); // Write MAC address in bottom right @@ -468,7 +469,7 @@ void jswrap_pixljs_init() { graphicsSetVar(&gfx); firstStart = false; - jsvUnLock(graphics); + jsvUnLock2(graphics,img); } /*JSON{