Skip to content

Commit 50bc878

Browse files
committed
EMCC: Emscripten version wip
- fix maPlot()
1 parent 5383bf4 commit 50bc878

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/platform/emcc/canvas.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@ EM_JS(void, draw_line, (int id, int x1, int y1, int x2, int y2, const char *colo
116116
EM_JS(void, draw_pixel, (int id, int x, int y, int r, int g, int b), {
117117
var canvas = document.getElementById(id == -1 ? "canvas" : "canvas_" + id);
118118
var ctx = canvas.getContext("2d");
119-
var pxId = ctx.createImageData(1, 1);
120-
var pxData = pxId.data;
121-
pxData[0] = r;
122-
pxData[1] = g;
123-
pxData[2] = b;
124-
pxData[3] = 255;
125-
ctx.putImageData(pxId, x, y);
119+
var pixel = new Uint8ClampedArray(4);
120+
pixel[0] = r;
121+
pixel[1] = g;
122+
pixel[2] = b;
123+
pixel[3] = 255;
124+
var imageData = new ImageData(pixel, 1, 1);
125+
ctx.putImageData(imageData, x, y);
126126
});
127127

128128
EM_JS(void, draw_rect_filled, (int id, int x, int y, int w, int h, const char *color), {
@@ -336,13 +336,13 @@ void maPlot(int posX, int posY) {
336336
int c = drawColor;
337337
if (c < 0) {
338338
c = -c;
339-
} else {
340-
c = colors_i[c > 15 ? 15 : c];
341339
}
342-
int r = (c & 0xff0000) >> 16;
343-
int g = (c & 0xff00) >> 8;
344-
int b = (c & 0xff);
345-
draw_pixel(drawTarget->_id, posX, posY, r, g, b);
340+
if (c >= 0 && c <= 15) {
341+
c = colors_i[c];
342+
}
343+
uint8_t sR, sG, sB;
344+
GET_RGB(c, sR, sG, sB);
345+
draw_pixel(drawTarget->_id, posX, posY, sR, sG, sB);
346346
}
347347
}
348348

0 commit comments

Comments
 (0)