Skip to content

Commit 7f2d85d

Browse files
committed
jswrap_pb_blitScreen improvements - 41ms for h.flip() down to 35ms
1 parent 82a753c commit 7f2d85d

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

libs/pipboy/jswrap_pipboy.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,34 +2039,34 @@ void jswrap_pb_blitScreen(JsVar *image, JsVar *options) {
20392039
getPaletteForLine4bpp(y, palette);
20402040

20412041
uint32_t pixels = 0;
2042-
uint8_t pixelUp, pixelDn;
20432042
for (int x=0;x<w4;x++) {
2044-
uint8_t p4up = *(row1++);
2045-
uint8_t p4 = *(row2++);
2046-
uint8_t p4dn = *(row3++);
2043+
uint16_t p4up = *(row1++); // line above for blurring
2044+
uint8_t p4 = *(row2++); // actual line
2045+
uint16_t p4dn = *(row3++); // line below for blurring
2046+
// Adding upper and lower lines. Spread 2bpp out so we can do 4 adds in one go.
2047+
p4up = (p4up | (p4up << 6)) & 0x3333; // 0bAABBCCDD -> 0b00AA00CC 00BB00DD
2048+
p4dn = (p4dn | (p4dn << 6)) & 0x3333;
2049+
uint16_t p4sum = p4up + p4dn; // Now 0b0AAA0CCC 0BBB0DDD
20472050
uint32_t filterResult32;
2051+
uint8_t pixelSum;
20482052
#define BLITPIXEL \
20492053
filterResult32 = (pixels&mulx1) + ((pixels&mulx2)<<1); /* Apply 8x 2bit filter */ \
20502054
filterResult32 = (filterResult32&0x0F0F0F0F) + ((filterResult32>>4)&0x0F0F0F0F) ; /* Merge each nibble, now we have 8 bits to play with */ \
20512055
filterResult32 = filterResult32 + (filterResult32>>8); \
20522056
filterResult32 = (filterResult32 + (filterResult32>>16)) & 255; \
2053-
filterResult32 = ((((pixelUp+pixelDn)<<1) + filterResult32)*3)>>3; /* blur upper and lower lines */ \
2057+
filterResult32 = ((pixelSum + filterResult32)*3)>>3; /* blur upper and lower lines */ \
20542058
if (filterResult32>15) filterResult32=15; \
20552059
lcdFSMC_blitPixel(palette[filterResult32]);
2056-
pixelUp = (p4up>>5);
2057-
pixelDn = (p4dn>>5);
2060+
pixelSum = (p4sum>>11)&14;
20582061
pixels = (pixels<<4) | (p4>>6);
20592062
BLITPIXEL
2060-
pixelUp = (p4up>>3)&6;
2061-
pixelDn = (p4dn>>3)&6;
2063+
pixelSum = (p4sum>>3)&14;
20622064
pixels = (pixels<<4) | ((p4>>4)&3);
20632065
BLITPIXEL
2064-
pixelUp = (p4up>>1)&6;
2065-
pixelDn = (p4dn>>1)&6;
2066+
pixelSum = (p4sum>>7)&14;
20662067
pixels = (pixels<<4) | ((p4>>2)&3);
20672068
BLITPIXEL
2068-
pixelUp = (p4up&3)<<1;
2069-
pixelDn = (p4dn&3)<<1;
2069+
pixelSum = (p4sum<<1)&14;
20702070
pixels = (pixels<<4) | (p4&3);
20712071
BLITPIXEL
20722072
#undef BLITPIXEL
@@ -2422,12 +2422,12 @@ void jswrap_pb_init() {
24222422
#endif
24232423
bool hasBootCode = jsfFindFile(jsfNameFromString(".bootcde"), NULL) ;
24242424
if (
2425-
#ifndef LINUX
2426-
upgradeInProgress ||
2425+
#ifndef LINUX
2426+
upgradeInProgress ||
24272427
#endif
24282428
res || !hasBootCode) {
24292429
JsVar *msg;
2430-
#ifndef LINUX
2430+
#ifndef LINUX
24312431
if (upgradeInProgress) msg = jsvNewFromString("UPGRADE IN PROGRESS");
24322432
else
24332433
#endif

0 commit comments

Comments
 (0)