title: How do I do high quality scaling of a image?
body: <p>I'm writing some code to scale a 32 bit RGBA image in C/C++. I have written a few attempts that have been somewhat successful, but they're slow and most importantly the quality of the sized image is not acceptable. </p>
  
  <p>I compared the same image scaled by OpenGL (i.e. my video card) and my routine and it's miles apart in quality. I've Google Code Searched, scoured source trees of anything I thought would shed some light (SDL, Allegro, wxWidgets, CxImage, GD, ImageMagick, etc.) but usually their code is either convoluted and scattered all over the place or riddled with assembler and little or no comments. I've also read multiple articles on Wikipedia and elsewhere, and I'm just not finding a clear explanation of what I need. I understand the basic concepts of interpolation and sampling, but I'm struggling to get the algorithm right. I do NOT want to rely on an external library for one routine and have to convert to their image format and back. Besides, I'd like to know how to do it myself anyway. :)</p>
  
  <p>I have seen a similar question asked on stack overflow before, but it wasn't really answered in this way, but I'm hoping there's someone out there who can help nudge me in the right direction. Maybe point me to some articles or pseudo code... anything to help me learn and do.</p>
  
  <p>Here's what I'm looking for:</p>
  
  <ol>
  <li>No assembler (I'm writing very portable code for multiple processor types).</li>
  <li>No dependencies on external libraries.</li>
  <li>I am primarily concerned with scaling DOWN, but will also need to write a scale up routine later.</li>
  <li>Quality of the result and clarity of the algorithm is most important (I can optimize it later).</li>
  </ol>
  
  <p>My routine essentially takes the following form:</p>
  
  <pre><code>DrawScaled(uint32 *src, uint32 *dst, 
        src_x, src_y, src_w, src_h, 
        dst_x, dst_y, dst_w, dst_h );
  </code></pre>
  
  <p>Thanks!</p>
  
  <p><strong>UPDATE:</strong> To clarify, I need something more advanced than a box resample for downscaling which blurs the image too much. I suspect what I want is some kind of bicubic (or other) filter that is somewhat the reverse to a bicubic upscaling algorithm (i.e. each destination pixel is computed from all contributing source pixels combined with a weighting algorithm that keeps things sharp.</p>
  
  <h2>Example</h2>
  
  <p>Here's an example of what I'm getting from  the wxWidgets BoxResample algorithm vs. what I want on a 256x256 bitmap scaled to 55x55.</p>
  
  <ul>
  <li>www.free_image_hosting.net/uploads/1a25434e0b.png</li>
  </ul>
  
  <p>And finally: </p>
  
  <ul>
  <li>www.free_image_hosting.net/uploads/eec3065e2f.png</li>
  </ul>
  
  <p>the original 256x256 image</p>