title: Optimize a nearest neighbor resizing algorithm for speed
body: <p>I'm using the next algorithm to perform nearest neighbor resizing. Is there anyway to optimize it's speed? Input and Output buffers are in ARGB format, though images are known to be always opaque. Thank you.</p>
  
  <pre><code>void resizeNearestNeighbor(const uint8_t* input, uint8_t* output, int sourceWidth, int sourceHeight, int targetWidth, int targetHeight)
  {
      const int x_ratio = (int)((sourceWidth &lt;&lt; 16) / targetWidth);
      const int y_ratio = (int)((sourceHeight &lt;&lt; 16) / targetHeight) ;
      const int colors = 4;
  
      for (int y = 0; y &lt; targetHeight; y++)
      {
          int y2_xsource = ((y * y_ratio) &gt;&gt; 16) * sourceWidth;
          int i_xdest = y * targetWidth;
  
          for (int x = 0; x &lt; targetWidth; x++)
          {
              int x2 = ((x * x_ratio) &gt;&gt; 16) ;
              int y2_x2_colors = (y2_xsource + x2) * colors;
              int i_x_colors = (i_xdest + x) * colors;
  
              output[i_x_colors]     = input[y2_x2_colors];
              output[i_x_colors + 1] = input[y2_x2_colors + 1];
              output[i_x_colors + 2] = input[y2_x2_colors + 2];
              output[i_x_colors + 3] = input[y2_x2_colors + 3];
          }
      }
  }
  </code></pre>