Question

I need to save a multipage TIFF from my program, but it seems Qt doesn't support multipage TIFF. Still, I need to do it. What would be the best way to go about doing it from my program?

So far, I'm thinking about using ImageMagick's command line utility to create the multipage TIFF from many JPEG files I create, or adding libtiff to my project and trying to use it, or using GDI+ (on Windows at least) to generate the TIFF.

Any other ideas I might have missed?

I'd like to avoid using external EXEs or DLLs if possible, i.e. if I can add a library directly to my project's source code it would be best.

Also, if you know of a project where it's already done, please post a link to it, I'd rather not reinvent the wheel.

Was it helpful?

Solution 2

Qt uses libtiff to read and write TIFF. So I would use the same library, just less headache. Secondly: look at http://qt.gitorious.org/qt/qt/blobs/4.8/src/gui/image/qtiffhandler.cpp to get a clue of how Qt writes one QImage. To support multiple pages I think you need to use TIFFSetField() (see here, TIFFTAG_PAGENAME and TIFFTAG_PAGENUMBER). I would start to either expand the write() function or write something similar, where you:

  • TIFFClientOpen();
  • iterate over a list of QImages
    • set the page per QImage
    • do the things QTiffHandler::write() does
  • TIFFClose();

see also: http://code.google.com/p/multiphoton/source/browse/MatroxImagingLibrary.cpp?#1628

OTHER TIPS

Just wanted to add my info on a similar topic. I ended up just building libTiff from the latest (4.0.3) source. My project is all in x64, but it was pretty easy:

  1. Download and unzip libTIFF source
  2. Open the VS2010 (or whatever) for x64 (or x32) cmd
  3. cd to your unzipped folder from step 1
  4. type: nmake /f makefile.vc
  5. Fetch the files from /libtiff folder and add to your project

Here's an example of reading 16-bit TIFF data:

    TIFF *MultiPageTiff = TIFFOpen("C:\\MultiPageTiff.tif", "r");

std::vector<unsigned short*> SimulatedQueue;

//Read First TIFF to setup the Buffers and init
//everything
int Width, Height;
//Bit depth, in bits
unsigned short depth;

TIFFGetField(MultiPageTiff, TIFFTAG_IMAGEWIDTH, &Width);
TIFFGetField(MultiPageTiff, TIFFTAG_IMAGELENGTH, &Height);
TIFFGetField(MultiPageTiff, TIFFTAG_BITSPERSAMPLE, &depth); 

//This should be Width*(depth / sizeof(char))
tsize_t ScanlineSizeBytes = TIFFScanlineSize(MultiPageTiff);

if(MultiPageTiff){
    int dircount = 0;
    do{
        dircount++;

        //I'm going to be QQueue'ing these up, so a buffer needs to be
        //allocated per new TIFF page
        unsigned short *Buffer = new unsigned short[Width*Height];

        //Copy all the scan lines
        for(int Row = 0; Row < Height; Row++){
            TIFFReadScanline(MultiPageTiff, &Buffer[Row*Width], Row, 0);
        }

        SimulatedQueue.push_back(Buffer);

    }while(TIFFReadDirectory(MultiPageTiff));

    TIFFClose(MultiPageTiff);
}

Sources: Building libTIFF from VS - http://www.remotesensing.org/libtiff/build.html#PC

Example MultiPage TIFF - http://www.remotesensing.org/libtiff/libtiff.html

Misc. Tiff Manuals - http://www.remotesensing.org/libtiff/man/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top