Next: , Previous: , Up: Simple Image Processing   [Contents][Index]


37.7.6 Scaling

An image can be scaled to any desired size with or without subpixel sampling. Without subpixel sampling simple pixel replication is used, otherwise a box average algorithm is employed that yields an anti-aliased image with much less artifacts. A special option is available that scales the image to the desired size but keeps the aspect ratio of the image the same by filling the part of the image that would otherwise be empty.

The main entry point to the scaling function is

int flimage_scale(FL_IMAGE *im, int newwidth, int newheight,
                  int option);

where the parameters newwidth and newheight specify the desired image size. Parameter optionq can be one of the following constants or the bitwise OR of them:

FLIMAGE_NOSUBPIXEL

scale the image with no subpixel sampling

FLIMAGE_SUBPIXEL

scale the image with subpixel sampling

FLIMAGE_ASPECT

scale the image with no aspect ratio change

FLIMAGE_CENTER

center the scaled image if aspect

FLIMAGE_NOCENTER

do not center the scaled image

For example, FLIMAGE_ASPECT|FLIMAGE_SUBPIXEL requests fitting the image to the new size with subpixel sampling. FLIMAGE_ASPECT specifies a scaling that results in an image of the requested size (even if the scales are different for width and height) without changing the aspect ratio of the original image by filling in the stretched regions with the fill color image->fill_color, a packed RGB color:

im->fill_color = FL_PACK(255,0,0);
flimage_scale(im, im->w+2, im->h, FLIMAGE_SUBPIXEL|FLIMAGE_ASPECT);

This code generates an image that is two pixels wider than the original image but with the same aspect ratio. The two additional pixel columns on each side of the image are filled with the fill color (red), yielding a red border. The fitting can be useful in turning a series of images of unequal sizes into images of equal sizes with no perceptible change in image quality.

Depending on what the application requires, simple scaling (zooming) with no subpixel sampling is much faster than box averaging or blending, but subpixel sampling tends to yield smoother images with less scaling artifacts.


Next: , Previous: , Up: Simple Image Processing   [Contents][Index]