Skip to content

Commit 16e9271

Browse files
committed
Merge branch 'STM32F4LCD' into HEAD - with speed improvements for vertical blur and ability to set width
2 parents 1730c31 + 7f2d85d commit 16e9271

1 file changed

Lines changed: 38 additions & 31 deletions

File tree

libs/pipboy/jswrap_pipboy.c

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,12 +1973,14 @@ are for previous pixels
19731973
* `options.ydiff` (default 1) is the y difference used when averaging rows above and below
19741974
* `options.y1` (default 0) is the min row to start updating
19751975
* `options.y2` (default 319) is the max row to start updating
1976+
* `options.x` (default 0) is the start column to update
1977+
* `options.w` (default 480) is number of columns to update
19761978
*/
19771979

19781980
void jswrap_pb_blitScreen(JsVar *image, JsVar *options) {
19791981
uint32_t filter = 0x00010123;
19801982
int yoffset = 0, ydiff = 1;
1981-
int y1 = 0, y2 = 319;
1983+
int xoffset = 0, y1 = 0, y2 = 319, w = 0;
19821984
if (jsvIsObject(options)) {
19831985
uint32_t v = (uint32_t)jsvGetIntegerAndUnLock(jsvObjectGetChildIfExists(options, "filter"));
19841986
if (v) filter = v;
@@ -1990,21 +1992,25 @@ void jswrap_pb_blitScreen(JsVar *image, JsVar *options) {
19901992
y1 = jsvGetIntegerAndUnLock(jsvObjectGetChildIfExists(options, "y1"));
19911993
v = jsvGetIntegerAndUnLock(jsvObjectGetChildIfExists(options, "y2"));
19921994
if (v) y2=v;
1995+
xoffset = jsvGetIntegerAndUnLock(jsvObjectGetChildIfExists(options, "x"));
1996+
w = jsvGetIntegerAndUnLock(jsvObjectGetChildIfExists(options, "w"));
19931997
}
19941998
if (y1<0) y1=0;
19951999
if (y1>=319) y1=319;
19962000
if (y2>=319) y2=319;
19972001
if (y2<y1) y2=y1;
2002+
if (w<=0) w=480;
2003+
if (w&3) return jsExceptionHere(JSET_ERROR, "Width must be multiple of 4");
19982004
scanlinePos = ((long long)(jshGetMillisecondsFromTime(jshGetSystemTime())*(480/4000.0)) % 640LL) - 110;
19992005

20002006
JsGraphics *gfx = &graphicsInternal;
20012007
GfxDrawImageInfo img;
20022008
if (!_jswrap_graphics_parseImage(gfx, image, 0, &img))
20032009
return;
20042010

2005-
if (img.width!=480 || img.height!=320 || img.bpp!=2) {
2011+
if (img.width!=w || img.height!=320 || img.bpp!=2) {
20062012
_jswrap_graphics_freeImageInfo(&img);
2007-
return jsExceptionHere(JSET_ERROR, "Image must be 480x320x2bpp");
2013+
return jsExceptionHere(JSET_ERROR, "Image must be %dx320x2bpp", w);
20082014
}
20092015
JSV_GET_AS_CHAR_ARRAY_NO_ERROR( imgPtr, imgLen, img.buffer );
20102016
if (!imgPtr) {
@@ -2023,48 +2029,49 @@ void jswrap_pb_blitScreen(JsVar *image, JsVar *options) {
20232029
}
20242030

20252031
uint16_t palette[16];
2032+
int w4 = w>>2; // 480 pixels, 2bpp = 120 bytes per row
20262033
const uint8_t *row1 = &imgPtr[0], *row2, *row3;
20272034
yoffset += 320; // to avoid negative values
2028-
lcdFSMC_blitStart(gfx, 0,y1, 480,y2+1-y1);
2035+
lcdFSMC_blitStart(gfx, xoffset,y1, w,y2+1-y1);
20292036
for (int y=y1;y<=y2;y++) {
20302037
uint16_t *rowBuf = (y & 1) ? blitRowB : blitRowA; // double buffer selection
20312038

20322039
// work out row pointers
2033-
row1 = &imgPtr[((y+yoffset-ydiff)%320)*120]; // 480 pixels, 2bpp = 120 bytes per row
2034-
row2 = &imgPtr[((y+yoffset)%320)*120]; // 480 pixels, 2bpp = 120 bytes per row
2035-
row3 = &imgPtr[((y+yoffset+ydiff)%320)*120]; // 480 pixels, 2bpp = 120 bytes per row
2040+
row1 = &imgPtr[((y+yoffset-ydiff)%320)*w4];
2041+
row2 = &imgPtr[((y+yoffset)%320)*w4];
2042+
row3 = &imgPtr[((y+yoffset+ydiff)%320)*w4];
20362043
getPaletteForLine4bpp(y, palette);
20372044

20382045
uint32_t pixels = 0;
2039-
uint8_t pixelUp, pixelDn;
20402046
int p = 0; // index into DMA row buffer
2041-
#define BLITPIXEL \
2042-
filterResult32 = (pixels&mulx1) + ((pixels&mulx2)<<1); /* Apply 8x 2bit filter */ \
2043-
filterResult32 = (filterResult32&0x0F0F0F0F) + ((filterResult32>>4)&0x0F0F0F0F) ; /* Merge each nibble, now we have 8 bits to play with */ \
2044-
filterResult32 = filterResult32 + (filterResult32>>8); \
2045-
filterResult32 = (filterResult32 + (filterResult32>>16)) & 255; \
2046-
filterResult32 = ((((pixelUp+pixelDn)<<1) + filterResult32)*3)>>3; /* blur upper and lower lines */ \
2047-
if (filterResult32>15) filterResult32=15; \
2048-
rowBuf[p++] = palette[filterResult32];
2049-
for (int x=0;x<120;x++) {
2050-
uint8_t p4up = *(row1++);
2051-
uint8_t p4 = *(row2++);
2052-
uint8_t p4dn = *(row3++);
2047+
for (int x=0;x<w4;x++) {
2048+
uint16_t p4up = *(row1++); // line above for blurring
2049+
uint8_t p4 = *(row2++); // actual line
2050+
uint16_t p4dn = *(row3++); // line below for blurring
2051+
// Adding upper and lower lines. Spread 2bpp out so we can do 4 adds in one go.
2052+
p4up = (p4up | (p4up << 6)) & 0x3333; // 0bAABBCCDD -> 0b00AA00CC 00BB00DD
2053+
p4dn = (p4dn | (p4dn << 6)) & 0x3333;
2054+
uint16_t p4sum = p4up + p4dn; // Now 0b0AAA0CCC 0BBB0DDD
20532055
uint32_t filterResult32;
2054-
pixelUp = (p4up>>5);
2055-
pixelDn = (p4dn>>5);
2056+
uint8_t pixelSum;
2057+
#define BLITPIXEL \
2058+
filterResult32 = (pixels&mulx1) + ((pixels&mulx2)<<1); /* Apply 8x 2bit filter */ \
2059+
filterResult32 = (filterResult32&0x0F0F0F0F) + ((filterResult32>>4)&0x0F0F0F0F) ; /* Merge each nibble, now we have 8 bits to play with */ \
2060+
filterResult32 = filterResult32 + (filterResult32>>8); \
2061+
filterResult32 = (filterResult32 + (filterResult32>>16)) & 255; \
2062+
filterResult32 = ((pixelSum + filterResult32)*3)>>3; /* blur upper and lower lines */ \
2063+
if (filterResult32>15) filterResult32=15; \
2064+
rowBuf[p++] = palette[filterResult32];
2065+
pixelSum = (p4sum>>11)&14;
20562066
pixels = (pixels<<4) | (p4>>6);
20572067
BLITPIXEL
2058-
pixelUp = (p4up>>3)&6;
2059-
pixelDn = (p4dn>>3)&6;
2068+
pixelSum = (p4sum>>3)&14;
20602069
pixels = (pixels<<4) | ((p4>>4)&3);
20612070
BLITPIXEL
2062-
pixelUp = (p4up>>1)&6;
2063-
pixelDn = (p4dn>>1)&6;
2071+
pixelSum = (p4sum>>7)&14;
20642072
pixels = (pixels<<4) | ((p4>>2)&3);
20652073
BLITPIXEL
2066-
pixelUp = (p4up&3)<<1;
2067-
pixelDn = (p4dn&3)<<1;
2074+
pixelSum = (p4sum<<1)&14;
20682075
pixels = (pixels<<4) | (p4&3);
20692076
BLITPIXEL
20702077
#undef BLITPIXEL
@@ -2423,12 +2430,12 @@ void jswrap_pb_init() {
24232430
#endif
24242431
bool hasBootCode = jsfFindFile(jsfNameFromString(".bootcde"), NULL) ;
24252432
if (
2426-
#ifndef LINUX
2427-
upgradeInProgress ||
2433+
#ifndef LINUX
2434+
upgradeInProgress ||
24282435
#endif
24292436
res || !hasBootCode) {
24302437
JsVar *msg;
2431-
#ifndef LINUX
2438+
#ifndef LINUX
24322439
if (upgradeInProgress) msg = jsvNewFromString("UPGRADE IN PROGRESS");
24332440
else
24342441
#endif

0 commit comments

Comments
 (0)