Image Scaling Algorithms

Printer-friendly versionSend to friend

While working on a game I came across the need to scale bitmaps to draw them on the screen. Scaling an image in real time takes up a lot of time and there is a need to write a fast algorithm, but that also may result in poor quality. Hence a balance between performance and quality is required.

The most common principle in scaling is Interpolation. It's a mathematical concept of approximating an intermediate value given a certain set of values. Bilinear interpolation is one method where the average of two values is taken to find the middle value.

The following image scaling algorithm is based on bilinear interpolation and divide and conquer method.

Suppose we have to scale a 32x32 bitmap image to 44x44.
Firstly the image is scaled horizontally to 44 pixels and then vertically. To scale horizontally each row has to be expanded from 32 to 44 pixels, so we have to use interpolation to approximate the middle values.
Using a divide and conquer approach the row is split into two parts, now 16 pixels have to expanded to 22 pixels. By repeating this using a recursive function we'll ultimately land up on expanding 1 pixel to some number of pixels, which can be done by copying over the pixels. In case the number of pixels that the row has to be expanded into is odd, then the colour of the middle pixel can be determined by averaging two middle pixels of the non-expanded row.

In this manner the scaled image is generated. For proper C code visit this page:
http://code.google.com/p/ltanks/source/browse/trunk/scale.c

Syndicate content