Image Chaining

Image Chain Basics

In PixelLive SDK, an image is processed by a chain of the Image instances. The following code does several operations to the input image:
Rect rcCrop(10, 10, 50, 50);
AutoPtr<Image> processed = ToSRGB(Scale(Crop(inputImage, rcCrop), 200, 200));
The code does the following operations in this order:

And then, if you want to export it as a JPEG file, the code below just do it:

AutoPtr<DiskStorageWithRollback> storage = DiskStorageWithRollback::create("test.jpg", accessWrite);
exportAsJPEG(storage, processed);
storage->commit();

Setting Image Parameters

The image chain created by the code above initializes some Image specific parameters on the function parameter. For example, Scale function receives the parameter that instruct it to scale the input image up to 200x200.
You can also modify these parameters by Image::setParam function. There are numbers of Image specific parameters and they are listed on Image Parameter Structures. Anyway, if you want to rescale the image to 300x400, then do like the following code:
ScaleParam param(300x400);
processed->setParam(&param);

The parameter is passed from an Image instance to another successively and Image instances which can understand the parameter of the structure process it. This process is illustrated by the following figure:

dataflow-1.png

If an Image determined to stop the relay, it can block the parameter and Image instances below the instance could not receive it.

dataflow-2.png

Multiple Head Problem

Some Image instances may have their own status and they may be changed by the parameters passed by Image::setParam function. See the figure below, it illustrates the multiple heads problem. In this figure, Image Source means some image of files such as MrSID or VFZ which can optimize the output to the specified dimensions. Firstly, Scale1 set the QualityHintParam of 1024x1024 to optimize the input image to 1024x1024. At the time, Image Source is optimized to 1024x1024 and of course, the Scale1 can suppose the input image is optimized to 1024x1024. And after that, Scale2 set the QualityHintParam of 256x256 to optimize the input image to 256x256 for its purpose. With this parameter, the Image Source is optimized for 256x256. And then, if Output1 requires some image data from the Scale1. Although the Scale1 assumes the Image Source is optimized for 1024x1024, the Image Source is just optimized for 256x256 and the scaling process ends with unexpected result.

twoheads.png

To prevent the problem, you should use Image::duplicate function or any other tricks. The Image::duplicate function duplicate the image chains (as illustrated below) and then independent two chains never conflicts each other. Please note that Image::duplicate consumes some memory for duplicating each Image instance.

duplicated.png

This document is automatically generated using doxygen 1.5.4 at Fri Jun 27 18:22:54 2008.