Supporting Multiple Images in a File

In PixelLive SDK, the Doc instance that is directly created by PixelLiveSystem::load or DocFactory::load is usually just the first image in the file. For the files that can store multiple images in a file, you can get Doc instances that corresponds to other images in the file by Doc::getChild and/or Doc::getNext.

Multiple Pages

For multiple page images, you can get the pages by Doc::getNext functions. The next code stores all the pages to an array:
    void getArrayOfPages(Doc *inFirstPage, SimpleArray< AutoPtr<Doc> >& outPages)
    {
        outPages.clear();
        Doc *page = inFirstPage;
        while(page)
        {
            outPages.push_back(page);
            page = page->getNext();
        }
    }
Please note that each page may have its reduced version images and it can be got by Doc::getChild function.

Reduced Resolution Versions

For reduced resolution versions (some of them are sometimes called thumbnail) of an image, usually we can get them using Doc::getChild and Doc::getChildCount functions.

The following code tries to find a reduced version that can be used to create a thumbnail of 256x256:

int eval(Doc *inDoc, size_t inSize)
{
    // We don't know how this evaluation is nice for your purpose...
    int w = (int)inDoc->getWidth();
    int h = (int)inDoc->getHeight();
    return (inSize - w) * (inSize - w) + (inSize - h) * (inSize - h);
}

AutoPtr<Image> extractThumbnail(Doc *inDoc, size_t inSize)
{
    AutoPtr<Doc> thumbCandidate = inDoc;
    size_t count = inDoc->getChildCount();
    for(size_t i = 0; i < count; i++)
    {
        AutoPtr<Doc> doc = inDoc->getChild(i);
        if(eval(doc, inSize) < eval(thumbCandidate, inSize))
            thumbCandidate = doc;
    }

    // calculate aspect ratio
    size_t w = inSize, h = inSize;
    if(thumbCandidate->getWidth() > thumbCandidate->getHeight())
        h = inSize * thumbCandidate->getHeight() / thumbCandidate->getWidth();
    else
        w = inSize * thumbCandidate->getWidth() / thumbCandidate->getHeight();

    if(w == 0) w = 1;
    if(h == 0) h = 1;
    return ImageUtils::Scale(thumbCandidate->createImage(), w, h);
}

Since TIFF file format has very long history and many variations, with some TIFF files, we can not get their reduced versions by Doc::getChild function. PixelLive SDK is rely on SubfileType (255), NewSubfileType (254) and SubIFDs (330) to recognize the reduced versions. If these tags are not found, we could not determine whether an image is a reduced version or not. And in such case, we are only to reduce the resolution by Scale function. Anyway, the code sample above also works in such cases.

See also:
Doc, Supported TIFF Tags

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