title: Optimize Bilinear Resize Algorithm in C
body: <p>Can anyone spot any way to improve the speed in the next Bilinear resizing Algorithm? 
  I need to improve Speed as this is critical, keeping good image quality. Is expected to be used in mobile devices with low speed CPUs.
  The algorithm is used mainly for up-scale resizing. Any other faster Bilinear algorithm also would be appreciated. Thanks</p>
  
  <pre><code>void resize(int* input, int* output, int sourceWidth, int sourceHeight, int targetWidth, int targetHeight) 
  {    
      int a, b, c, d, x, y, index;
      float x_ratio = ((float)(sourceWidth - 1)) / targetWidth;
      float y_ratio = ((float)(sourceHeight - 1)) / targetHeight;
      float x_diff, y_diff, blue, red, green ;
      int offset = 0 ;
  
      for (int i = 0; i &lt; targetHeight; i++) 
      {
          for (int j = 0; j &lt; targetWidth; j++) 
          {
              x = (int)(x_ratio * j) ;
              y = (int)(y_ratio * i) ;
              x_diff = (x_ratio * j) - x ;
              y_diff = (y_ratio * i) - y ;
              index = (y * sourceWidth + x) ;                
              a = input[index] ;
              b = input[index + 1] ;
              c = input[index + sourceWidth] ;
              d = input[index + sourceWidth + 1] ;
  
              // blue element
              blue = (a&amp;0xff)*(1-x_diff)*(1-y_diff) + (b&amp;0xff)*(x_diff)*(1-y_diff) +
                     (c&amp;0xff)*(y_diff)*(1-x_diff)   + (d&amp;0xff)*(x_diff*y_diff);
  
              // green element
              green = ((a&gt;&gt;8)&amp;0xff)*(1-x_diff)*(1-y_diff) + ((b&gt;&gt;8)&amp;0xff)*(x_diff)*(1-y_diff) +
                      ((c&gt;&gt;8)&amp;0xff)*(y_diff)*(1-x_diff)   + ((d&gt;&gt;8)&amp;0xff)*(x_diff*y_diff);
  
              // red element
              red = ((a&gt;&gt;16)&amp;0xff)*(1-x_diff)*(1-y_diff) + ((b&gt;&gt;16)&amp;0xff)*(x_diff)*(1-y_diff) +
                    ((c&gt;&gt;16)&amp;0xff)*(y_diff)*(1-x_diff)   + ((d&gt;&gt;16)&amp;0xff)*(x_diff*y_diff);
  
              output [offset++] = 
                      0x000000ff | // alpha
                      ((((int)red)   &lt;&lt; 24)&amp;0xff0000) |
                      ((((int)green) &lt;&lt; 16)&amp;0xff00) |
                      ((((int)blue)  &lt;&lt; 8)&amp;0xff00);
          }
      }
  }
  </code></pre>