Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt multipage TIFF

Tags:

c++

qt

tiff

libtiff

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.

like image 709
sashoalm Avatar asked Nov 27 '12 08:11

sashoalm


1 Answers

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/

like image 118
Austin Avatar answered Sep 19 '22 01:09

Austin