2004.09.27 11:34 "[Tiff] Finding data in memory", by Bjoern Schorre

2004.09.28 05:09 "Re: [Tiff] Finding data in memory", by Andrey Kiselev

How can find my tiff-data in memory.

I passed the command *TIFFReadScanline* the TIFF-File, the buffer where to store the data, the row-number and the sample.

You need a sample only in the case of band interleaved images.

Now, I tried to access the data in the memory but I can't see anything.

Well, attached program should demonstarte how to read the image line by line and print out the pixel values.

The buffer is from type tdata_t (typedef void*). I cast the pointer to a DWORD and tried to print out the content of the memory the pointer signs to.

You shoul cast exactly to the data type, contained in image. To determine the data type you should read contents of the BitsPerSample and SampleFormat tags. If BitsPerSample is 8, you should cast to unsigned char (that will be most part of the images). If BitsPerSample is 32 you should take in account value of the SampleFormat tag: you may have float, uint32 or int32 values and cast the data appropriately.

Another question is: How are the data writen in the memory. Do i have to flip or switch the BYTEs or WORDs in the DWORD?

No additional swapping required, all data will be returned in host byte order.


Andrey V. Kiselev
Home phone: +7 812 5274898 ICQ# 26871517

#include <stdio.h>
#include <stdlib.h>
#include <tiffio.h>

int main (int argc, char **argv)
    TIFF *tif;
    uint16 spp, bpp, photo, planarconfig;
    uint32 image_width, image_height, scansize;
    uint32 line;
    unsigned char *buf;

    if(argc != 2)
        fprintf(stderr, "\nUSAGE: tiffprint infile.tif\n");
        return 1;

    tif = TIFFOpen(argv[1], "r");
    if (!tif)
        fprintf (stderr, "Can't open %s for reading.\n", argv[1]);
        return 2;
    if (bpp != 8)
        fprintf (stderr, "Sorry, we don't support bitdepth other tnan 8.\n");
        return 3;

    TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &planarconfig);
    if (planarconfig != PLANARCONFIG_CONTIG)
        fprintf (stderr, "Sorry, we don't support band interleaved images.\n");
        return 3;

    TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &image_width);
    TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &image_height);
    TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &photo);
    scansize = TIFFScanlineSize(tif);
    buf = _TIFFmalloc(scansize);
    for (line = 0; line < image_height; line++)
        int i;
        const char *sep = "";

        TIFFReadScanline(tif, buf, line, 0);
        fprintf(stdout, "%d:", line);
        for (i = 0; i < image_width; i++)
            int j;

            fprintf(stdout, "%s", sep);
            for (j = 0; j < spp; j++)
                fprintf(stdout, " %d", buf[i * spp + j]);
            sep = ",";
        fprintf(stdout, "\n");


    return 0;