Skip to content

Commit

Permalink
Use built-in gfx draw function - save a few bytes on Pixl.js
Browse files Browse the repository at this point in the history
  • Loading branch information
gfwilliams committed Nov 15, 2024
1 parent aec1e1e commit 957e3f9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 19 deletions.
13 changes: 0 additions & 13 deletions libs/graphics/graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions libs/graphics/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
9 changes: 5 additions & 4 deletions libs/pixljs/jswrap_pixljs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -468,7 +469,7 @@ void jswrap_pixljs_init() {
graphicsSetVar(&gfx);

firstStart = false;
jsvUnLock(graphics);
jsvUnLock2(graphics,img);
}

/*JSON{
Expand Down

0 comments on commit 957e3f9

Please sign in to comment.