The Liquid Rescale library is written in C, but can be used into C++ programs without
any modification.
It has an object-oriented design, so that the terminology is borrowed
from C++. The central class of the library is called LqrCarver
.
Carver objects can generate and store multi-size images, or load
them, and read them out at the desired size.
Internally, multi-size images are stored simply as plain images with the addition of a visibility map. Each pixel in the image has its own visibility level. We decide whether to display a pixel or not simply by comparing each pixel's visibility with a given global visibility level. In this way, we can read out images of different sizes, simply by setting properly a global visibility level.
Once the visibility map has been computed, it allows effortless, real-time scaling. However, visibility maps also necessarily have an orientation, either horizontal or vertical. If we want to resize on the other direction, the visibility map has to be computed afresh, and the previous visibility map becomes useless, because the two maps are not consistent one with the other.
This also implies that the resizing order affects the final result: rescaling horizontally first, then vertically, does not yield the same result as following the reverse order. Moreover, one could choose an intermediate way, e.g. by rescaling by one pixel in one direction, one in the other, then iterating as needed to reach the final size.
The default behaviour of the library is to rescale horizontally first, then vertically, but this order can be reversed.
Visibility maps can be stored in objects of type LqrVMap
.
When a LqrCarver
object is created from an input image, the
visibility of each pixel is uninitialized. At this point, one could either
import a previously computed LqrVMap
, or activate the LqrCarver
so
that it creates one afresh when asked.
In either case, there's a single method to call, specifiying the new desired size; all the rest will automatically be computed as necessary. By default, the visibility maps are only computed up to the extent to which they are needed for resizing.