Picture zoom in/out, enlarge/reduce

I had a recent application that required displaying 25% and 50% scaled “thumbnails” of larger images. To save memory I wanted to do this scaling on the Nextion itself rather than including scaled versions of each picture.
The operation is fairly quick. With a 200x120 picture displaying a 25% scale thumbmail takes about half a second, and displaying a 50% scale (“zoom out”) takes about 2 seconds.

Here is the code: (supply H,W,Scale in sys0/1/2)

//Thumbnail / Scale 25% (sys0=4) (runtime 200x120 image: ~0.6 second)
//Zoom Out / Scale 50% (sys0=2) (runtime 200x120 image: ~2.3 second)
//Reduces picture ID:0 from 200x120 to 100x60 or 50x30, displays at 0,0
// DEFINE W,H,Scale
sys0=4      // scale size (2=1/2,50% , 4=1/4,25%)
sys1=200    // picture width
sys2=120    // picture height
///////////////
thc=sys2/sys0
sys2=sys1/sys0
pwm7=sys0>>1
for(sya0=0;sya0<thc;sya0++)
{
  sya1=sya0<<pwm7
  for(sys0=0;sys0<sys2;sys0++)
  {
    sys1=sys0<<pwm7
    xpic sys0,sya0,1,1,sys1,sya1,0
  }
}

I also needed to implement double-tap to zoom-in functionality. This routine allows displaying a quick. low resolution 200% scaled version of a picture asset (sys0=0) which on a 200x120 image takes approximately 3 seconds (fullscreen image). Setting sys0=1 adds an additional pass that will 4X sharpen the low resolution scaled image and takes an additional 7 seconds on a 200x120 picture asset (fullscreen)

Set the picture asset height, width and scaling resolution using sys0/1/2

//Zoom In / Enlarge (200%)
// Enlarges picture ID:0 from 200x120 to 400x240 (fullscreen), displays at 0,0
// Low Resolution, Quick Zoom (4x4 pixels) (runtime @ 200x120: 3 seconds)
// Normal Resolution, Sharpen (2x2 pixels) (runtime @ 200x120: 10 seconds)
// DEFINE W,H,Resolution
sys0=0      // Resolution (0 = Low, 1 = High)
sys1=200  // picture width
sys2=120  // picture height
//////////////
thc=sys1
pwm6=8
pwm5=sys0
for(pwm7=0;pwm7<=pwm5;pwm7++)
{
  pwm6=pwm6>>1
  for(sya0=pwm7;sya0<sys2;sya0=sya0+2)
  {
    sya1=sya0<<1
    for(sys0=0;sys0<thc;sys0++)
    {
      sys1=sys0<<1
      xpic sys1,sya1,2,pwm6,sys0,sya0,0
    }
  }
}

I’m using the ‘sysX’, ‘syaX’, ‘pwmX’ and ‘thc’ system variables instead of global/local user defined variables in order to increase the speed of the routines. Operations with ‘sys0/1/2’ and ‘sya0/1’ are about 41% faster than using local/global defined variables (eg. ‘x.val’). Operations with ‘pwm4/5/6/7’ are 37% faster and operations with ‘thc’ are 35% faster. (*Benchmarking on Nextion 3.2 Enhanced)

Examples