Graphics: Improve fillPolyAA for horizontalish lines, remove antialiased vector fonts (as won't work well on platforms without readback)

This commit is contained in:
Gordon Williams 2021-02-09 13:09:21 +00:00
parent 6fe8454c4b
commit 61af3b9135
5 changed files with 23 additions and 28 deletions

View File

@ -47,6 +47,7 @@
nRF52: Upon rebooting, reset time to 1970 if time looks corrupt
nRF52840: Don't use SPI3 unless ESPR_USE_SPI3 is defined (errata 195 means it draws an extra 1mA unless disabled!)
Bangle.js: apply g.drawImage fast path even if image goes to the edge of the screen
Graphics: Improve fillPolyAA for horizontalish lines, remove antialiased vector fonts (as won't work well on platforms without readback)
2v08 : nRF52: Added option to build in I2C slave support
Fix Tensorflow aiGesture regression from 2v07 (re-add opcodes) (fix #1936)

View File

@ -607,7 +607,7 @@ void graphicsDrawLineAA(JsGraphics *gfx, int ix1, int iy1, int ix2, int iy2) {
#endif
// Fill poly - each member of vertices is 1/16th pixel
void graphicsFillPoly(JsGraphics *gfx, int points, short *vertices, bool antiAlias) {
void graphicsFillPoly(JsGraphics *gfx, int points, short *vertices) {
typedef struct {
short x,y;
} VertXY;
@ -679,30 +679,9 @@ void graphicsFillPoly(JsGraphics *gfx, int points, short *vertices, bool antiAli
if (s==0) x=cross[i];
if (slopes[i]) s++; else s--;
if (!s || i==crosscnt-1) {
#ifdef GRAPHICS_ANTIALIAS
if (!antiAlias) {
#endif
int x1 = (x+15)>>4;
int x2 = (cross[i]+15)>>4;
if (x2>x1) graphicsFillRectDevice(gfx,x1,yl,x2-1,yl,gfx->data.fgColor);
#ifdef GRAPHICS_ANTIALIAS
} else {
int x1 = x;
int x2 = cross[i];
if (x2>x1) {
int x1i = x1>>4;
int x2i = x2>>4;
if (x2i==x1i) {
graphicsSetPixelDeviceBlended(gfx, x1i, yl, 16*(1+x2-x1));
} else if (x2i>x1i) {
graphicsSetPixelDeviceBlended(gfx, x1i, yl, 16*(15-(x1&15)));
if (x2i>x1i+1)
graphicsFillRectDevice(gfx,x1i+1,yl,x2i-1,yl,gfx->data.fgColor);
graphicsSetPixelDeviceBlended(gfx, x2i, yl, 16*(x2&15));
}
}
}
#endif
int x1 = (x+15)>>4;
int x2 = (cross[i]+15)>>4;
if (x2>x1) graphicsFillRectDevice(gfx,x1,yl,x2-1,yl,gfx->data.fgColor);
}
if (jspIsInterrupted()) break;
}

View File

@ -160,7 +160,7 @@ void graphicsDrawEllipse(JsGraphics *gfx, int x, int y, int x2, int y2);
void graphicsFillEllipse(JsGraphics *gfx, int x, int y, int x2, int y2);
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 graphicsFillPoly(JsGraphics *gfx, int points, short *vertices, bool antiAlias); ///< each pixel is 1/16th a pixel may overwrite vertices...
void graphicsFillPoly(JsGraphics *gfx, int points, short *vertices); ///< each pixel is 1/16th a pixel may overwrite vertices...
#ifndef NO_VECTOR_FONT
unsigned int graphicsFillVectorChar(JsGraphics *gfx, int x1, int y1, int size, char ch); ///< prints character, returns width
unsigned int graphicsVectorCharWidth(JsGraphics *gfx, unsigned int size, char ch); ///< returns the width of a character

View File

@ -1825,7 +1825,22 @@ JsVar *jswrap_graphics_fillPoly_X(JsVar *parent, JsVar *poly, bool antiAlias) {
if (jsvIteratorHasElement(&it))
jsExceptionHere(JSET_ERROR, "Maximum number of points (%d) exceeded for fillPoly", maxVerts/2);
jsvIteratorFree(&it);
graphicsFillPoly(&gfx, idx/2, verts, antiAlias);
#ifdef GRAPHICS_ANTIALIAS
if (antiAlias) {
// ... if lines are wide (not high) then draw AA line first
int lx = verts[idx-2];
int ly = verts[idx-1];
for (int i=0;i<idx;i+=2) {
// convert into device coordinates...
int vx = verts[i];
int vy = verts[i+1];
graphicsDrawLineAA(&gfx, vx,vy,lx,ly);
lx = vx;
ly = vy;
}
}
#endif
graphicsFillPoly(&gfx, idx/2, verts);
graphicsSetVar(&gfx); // gfx data changed because modified area
return jsvLockAgain(parent);

View File

@ -456,7 +456,7 @@ unsigned int vfDrawCharPtr(JsGraphics *gfx, int x1, int y1, int size, const uint
poly[j*2 ] = (short)(x1 + vx*size*16/VF_SCALE);
poly[j*2+1] = (short)(y1 + (vy+VF_OFFSET_Y)*size*16/VF_SCALE);
}
graphicsFillPoly(gfx, polyLen, poly, true/*antialias if available*/);
graphicsFillPoly(gfx, polyLen, poly);
}
return (unsigned int)(((w+1+VF_CHAR_SPACING)*size*16/VF_SCALE+7)>>4);
}