void getArrayOfPages(Doc *inFirstPage, SimpleArray< AutoPtr<Doc> >& outPages) { outPages.clear(); Doc *page = inFirstPage; while(page) { outPages.push_back(page); page = page->getNext(); } }
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.