@@ -1971,12 +1971,14 @@ are for previous pixels
19711971* `options.ydiff` (default 1) is the y difference used when averaging rows above and below
19721972* `options.y1` (default 0) is the min row to start updating
19731973* `options.y2` (default 319) is the max row to start updating
1974+ * `options.x` (default 0) is the start column to update
1975+ * `options.w` (default 480) is number of columns to update
19741976*/
19751977
19761978void jswrap_pb_blitScreen (JsVar * image , JsVar * options ) {
19771979 uint32_t filter = 0x00010123 ;
19781980 int yoffset = 0 , ydiff = 1 ;
1979- int y1 = 0 , y2 = 319 ;
1981+ int xoffset = 0 , y1 = 0 , y2 = 319 , w = 0 ;
19801982 if (jsvIsObject (options )) {
19811983 uint32_t v = (uint32_t )jsvGetIntegerAndUnLock (jsvObjectGetChildIfExists (options , "filter" ));
19821984 if (v ) filter = v ;
@@ -1988,21 +1990,25 @@ void jswrap_pb_blitScreen(JsVar *image, JsVar *options) {
19881990 y1 = jsvGetIntegerAndUnLock (jsvObjectGetChildIfExists (options , "y1" ));
19891991 v = jsvGetIntegerAndUnLock (jsvObjectGetChildIfExists (options , "y2" ));
19901992 if (v ) y2 = v ;
1993+ xoffset = jsvGetIntegerAndUnLock (jsvObjectGetChildIfExists (options , "x" ));
1994+ w = jsvGetIntegerAndUnLock (jsvObjectGetChildIfExists (options , "w" ));
19911995 }
19921996 if (y1 < 0 ) y1 = 0 ;
19931997 if (y1 >=319 ) y1 = 319 ;
19941998 if (y2 >=319 ) y2 = 319 ;
19951999 if (y2 < y1 ) y2 = y1 ;
2000+ if (w <=0 ) w = 480 ;
2001+ if (w & 3 ) return jsExceptionHere (JSET_ERROR , "Width must be multiple of 4" );
19962002 scanlinePos = ((long long )(jshGetMillisecondsFromTime (jshGetSystemTime ())* (480 /4000.0 )) % 640LL ) - 110 ;
19972003
19982004 JsGraphics * gfx = & graphicsInternal ;
19992005 GfxDrawImageInfo img ;
20002006 if (!_jswrap_graphics_parseImage (gfx , image , 0 , & img ))
20012007 return ;
20022008
2003- if (img .width != 480 || img .height != 320 || img .bpp != 2 ) {
2009+ if (img .width != w || img .height != 320 || img .bpp != 2 ) {
20042010 _jswrap_graphics_freeImageInfo (& img );
2005- return jsExceptionHere (JSET_ERROR , "Image must be 480x320x2bpp" );
2011+ return jsExceptionHere (JSET_ERROR , "Image must be %dx320x2bpp" , w );
20062012 }
20072013 JSV_GET_AS_CHAR_ARRAY_NO_ERROR ( imgPtr , imgLen , img .buffer );
20082014 if (!imgPtr ) {
@@ -2021,19 +2027,20 @@ void jswrap_pb_blitScreen(JsVar *image, JsVar *options) {
20212027 }
20222028
20232029 uint16_t palette [16 ];
2030+ int w4 = w >>2 ; // 480 pixels, 2bpp = 120 bytes per row
20242031 const uint8_t * row1 = & imgPtr [0 ], * row2 , * row3 ;
20252032 yoffset += 320 ; // to avoid negative values
2026- lcdFSMC_blitStart (gfx , 0 ,y1 , 480 ,y2 + 1 - y1 );
2033+ lcdFSMC_blitStart (gfx , xoffset ,y1 , w ,y2 + 1 - y1 );
20272034 for (int y = y1 ;y <=y2 ;y ++ ) {
20282035 // work out row pointers
2029- row1 = & imgPtr [((y + yoffset - ydiff )%320 )* 120 ]; // 480 pixels, 2bpp = 120 bytes per row
2030- row2 = & imgPtr [((y + yoffset )%320 )* 120 ]; // 480 pixels, 2bpp = 120 bytes per row
2031- row3 = & imgPtr [((y + yoffset + ydiff )%320 )* 120 ]; // 480 pixels, 2bpp = 120 bytes per row
2036+ row1 = & imgPtr [((y + yoffset - ydiff )%320 )* w4 ];
2037+ row2 = & imgPtr [((y + yoffset )%320 )* w4 ];
2038+ row3 = & imgPtr [((y + yoffset + ydiff )%320 )* w4 ];
20322039 getPaletteForLine4bpp (y , palette );
20332040
20342041 uint32_t pixels = 0 ;
20352042 uint8_t pixelUp , pixelDn ;
2036- for (int x = 0 ;x < 120 ;x ++ ) {
2043+ for (int x = 0 ;x < w4 ;x ++ ) {
20372044 uint8_t p4up = * (row1 ++ );
20382045 uint8_t p4 = * (row2 ++ );
20392046 uint8_t p4dn = * (row3 ++ );
0 commit comments