Re: TIFF files

James Cloos <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <[email protected]>
>>>>> "NA" == Nadeem Afana <[email protected]> writes:

NA> How can I generate TIFF files using Cairo and C/C++ in Linux?

LibTiff.

Libtiff is well documented (start with >>man libtiff<<.  Each of the
functions listed under LIST OF ROUTINES has its own man page) and comes
with some example apps which help document the api.

As an example, I added this to a test app to write out said app's
internal CIELAB+Alpha buffer (if cairo had support for colour spaces I
would have used it to write a pdf...):

    if (labtif) {
	TIFFDefaultStripSize (labtif, height);
        TIFFSetField (labtif, TIFFTAG_IMAGEWIDTH, width);
        TIFFSetField (labtif, TIFFTAG_IMAGELENGTH, height);
        TIFFSetField (labtif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
        TIFFSetField (labtif, TIFFTAG_SAMPLESPERPIXEL, 4);
        TIFFSetField (labtif, TIFFTAG_BITSPERSAMPLE, TIFFDataWidth(TIFF_DOUBLE) * 8);
        TIFFSetField (labtif, TIFFTAG_FILLORDER, FILLORDER_LSB2MSB);
        TIFFSetField (labtif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
        TIFFSetField (labtif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_CIELAB);
	TIFFSetField (labtif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_IEEEFP);
	TIFFSetField (labtif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
	TIFFSetField (labtif, TIFFTAG_ROWSPERSTRIP, height );
	if (dpi > 0.) {
		TIFFSetField (labtif, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
		TIFFSetField (labtif, TIFFTAG_XRESOLUTION, dpi );
		TIFFSetField (labtif, TIFFTAG_YRESOLUTION, dpi );
	}
	TIFFWriteRawStrip (labtif, 0, labbuf, len * 4 * sizeof(double));
	TIFFClose (labtif);
    }

(labtiff is opened with:

	labtif = TIFFOpen(optarg, "w");

inside of a getopt_long(3) block)

For a more portable app you'd want either to base fillorder on the
hosts's endianness or ensure the buffer has matching order.  You also
may want to use some form of compression, etc.

There are a bunch of fields to set, but the api is straitforward.

-JimC
-- 
James Cloos <[email protected]>         OpenPGP: 1024D/ED7DAEA6
--
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.