2006.06.04 06:35 "[Tiff] Segfault", by Alex Ryu

2006.06.04 06:35 "[Tiff] Segfault", by Alex Ryu

Hi, I'm new to image processing and pretty new to C, so please excuse me if I ask any dumb questions.

I keep getting a segmentation fault when I run this code:

[code]
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <tiffio.h>

int main()
{
    FILE *fp;
    fp = fopen("c:\\output.txt", "w");
    TIFF *tif;
    int i, j;
    uint32 w, h, npixels;
    uint32 *raster;
    TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
    TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h); /*length = height*/
    tif = TIFFOpen("c:\\image1.tif", "r");
    npixels = w * h;
    raster = (uint32*) _TIFFmalloc(npixels * sizeof(uint32));
    TIFFReadRGBAImage(tif, w, h, raster, 0);
    for (i = 0; i < h; i++)
    {
        for (j = 0; j < w; j++)
        {
            if ((i*w + j)%h == 0) printf("\n");
            fprintf(fp,"%d ", raster[i*w + j]);
        }
    }

    return 0;
}
[/code]

For the life of me it looks like I'm overstepping the array bounds, but I've doublechecked it several times. I'm on WinXP. Thanks for your help Alex