AWARE [SYSTEMS] Imaging expertise for the Delphi developer
AWare Systems, Imaging expertise for the Delphi developer, Home TIFF and LibTiff Mailing List Archive

LibTiff Mailing List

TIFF and LibTiff Mailing List Archive
June 2006

Previous Thread
Next Thread

Previous by Thread
Next by Thread

Previous by Date
Next by Date

Contact

The TIFF Mailing List Homepage
This list is run by Frank Warmerdam
Archive maintained by AWare Systems



Valid HTML 4.01!



Thread

2006.06.04 06:35 "Segfault", by Alex Ryu
2006.06.04 14:41 "Re: Segfault", by Bob Friesenhahn

2006.06.04 06:35 "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