Skip to content
 

Fast image scaling with multiplier between 1-2

I made a simple scaling function for gpsp4symbian to stretch the frames into full screen. The algorithm seems to be working quite well with scaling factors between 1-2. Thanks to AnotherGuest for tips.
In this example 1.3 scaling factor is used for vertical scaling and 1.5 for horizontal scaling.
Fist let’s make the scaling tables.

void symb_create_interpolate_table()
  {
  TReal j = 1.33; //horizontal
  TReal loop = 0;
  TReal real_temp;
  for( TInt i=0; i<240; i++)
    {
    real_temp = i*j + 0.5;
    interptable_w[i] = real_temp;
    }
  j= 1.5; //vertical
  for( TInt i=0; i<160; i++)
    {
    real_temp = i*j + 0.5;
    interptable_h[i] = real_temp;
    }
  }

Then we can use the pre-calculated tables to determinate if we have to interpolate a pixel or a line or not. There are all kinds of nice interpolation algorithms for images, but in this example I just reproduced the pixels for the speed. In theory we should also do some filtering after the interpolation, but that’s also abandoned for the speed.

u16 *screenlarge_ptr = large_ptr;
u16 *screengba_ptr = small_ptr;
u8 i=0;
u8 j =0;
u16 t1;
u16 t2;
u16 stop;
for(j=0; j<160;j++)
 {
 for( i=0; i<240; i++)
   {
   *screenlarge_ptr = *screengba_ptr;
   if( interptable_w[i] != (interptable_w[i+1] -1) )
     {
     //interpolate, or reproduce the pixel
     screenlarge_ptr++;
     *screenlarge_ptr = *screengba_ptr;
      }
   screengba_ptr++;
   screenlarge_ptr++;
   }
 if( interptable_h[j] != (interptable_h[j+1] -1))
   {
   //copy whole previous line
   screen_temp = screenlarge_ptr - 320;
   memcpy(screenlarge_ptr, screen_temp, 320*2);
   screenlarge_ptr +=  320;
   }
 }

5 Comments

  1. Gaba says:

    Pease make a option to keep the aspect ratio.
    Tanks

  2. Fenrir says:

    Good to see you are going ahead with this project!
    It has always been a pity that vampent’s emulator was left incomplete.

  3. Fenrir says:

    A question: are you going to try and implement direct screen access on this one?

Leave a Reply

(required)