Use built-in gfx draw function - save a few bytes on Pixl.js

This commit is contained in:
Gordon Williams 2024-11-15 16:07:10 +00:00
parent aec1e1e87c
commit 957e3f99f4
3 changed files with 5 additions and 19 deletions

View File

@ -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;y<y1+height;y++) {
for (x=x1;x<x1+width;x++) {
if (pixel&128) graphicsSetPixelDevice(gfx, x, y, gfx->data.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

View File

@ -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);

View File

@ -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{