2006.08.11 19:49 "RE: [Tiff] Newbie RICHTIFFIPTC query -- code snippet (sample usage of TIFFTAG_RICHTIFFIPTC)", by

2006.08.11 19:49 "RE: [Tiff] Newbie RICHTIFFIPTC query -- code snippet (sample usage of TIFFTAG_RICHTIFFIPTC)", by

Dermot wrote:

>  uint16 count;                /* unit32 gives me no text at all */

Strange, as the count of a tag is supposed to be a 32-bit value.

Perhaps this snippet will help you (it's tested, but you may need to add some more headers):

        #include "tiffio.h"
        const uint16 imgWidth = 16;
        const uint16 imgHeight = 16;
        const int iptcBufSize = 128;
        char iptcBuf[iptcBufSize * sizeof(uint32)];
        memset(iptcBuf, 0, 128 * sizeof(uint32));
        strcpy(iptcBuf, "this is a test message.");
        TIFF * tif = TIFFOpen("test.tif", "w");
        TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE);
        TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, imgWidth);
        TIFFSetField(tif, TIFFTAG_IMAGELENGTH, imgHeight);
        TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1);
        TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
        TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
        TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
        TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, imgHeight);
        TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
        TIFFSetField(tif, TIFFTAG_GROUP4OPTIONS, 0);
        TIFFSetField(tif, TIFFTAG_MINSAMPLEVALUE, 0);
        TIFFSetField(tif, TIFFTAG_MAXSAMPLEVALUE, 1);
        TIFFSetField(tif, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);
        TIFFSetField(tif, TIFFTAG_XRESOLUTION, (float)300);
        TIFFSetField(tif, TIFFTAG_YRESOLUTION, (float)300);
        TIFFSetField(tif, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
        TIFFSetField(tif, TIFFTAG_SUBFILETYPE, 0);
        TIFFSetField(tif, TIFFTAG_RICHTIFFIPTC, iptcBufSize, iptcBuf);
        char * imgData = new char[imgWidth * imgHeight];
        memset(imgData, 0, imgWidth * imgHeight);
        for (int i = 0; i < imgHeight; ++i)

{

                int value = 255 * i / imgHeight;
                imgData[i * imgWidth + i] = 255 * (imgHeight - i) / imgHeight;

}
int checkCount = TIFFWriteRawStrip(tif, 0, imgData, imgWidth * imgHeight);
TIFFClose(tif);
// now, try to read back the buffer
tif = TIFFOpen("test.tif", "r");
uint32 count = 0;
char * data = NULL;
int result = TIFFGetField(tif, TIFFTAG_RICHTIFFIPTC, &count, &data);
TIFFClose(tif);

> Is that a tall order? If so sorry but the books I have are not

> really helping me understand how to deal with a void pointers.

Now about that void stuff. Typically, a type has a size (usually a multiple of octets). A pointer is just the smallest ordinal number that can address all available memory on the machine (in the case of 32-bit Windows, it's an unsigned long int (32 bit ordinal)). A pointer to a certain type tells the compiler that when it follows that pointer to get the actual value (that is, when it dereferences the pointer), it will try to fetch a number of bits, according to the type size.

'void' is a special, sizeless return type. Thus, a 'void *' points to something, but the compiler can't know how big that something is, so it complains to you, and you fix it by typecasting a void pointer to a specific type pointer.

(If you have any questions on C itself, no matter how trifling, email me directly (off-list), and ask away).