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

2006.06.04 06:46 "RE: [Tiff] Segfault", by Venkatasalapathy D - TLS, Chennai


Thanks for your reply

We need for 48 bit color TIFF read and write sample code.

Note: For 48 bit, every pixel data stored in 6 byte (48 bit). But your data type 'raster' (uint32) is 4 byte.

Please help me and give sample code for 48 bit color read and write.

Thanks & Regards,

Venkat D


From: tiff-bounces@lists.maptools.org [mailto:tiff-bounces@lists.maptools.org] On Behalf Of 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:

#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;

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

The contents of this e-mail and any attachment(s) are confidential and intended for the

named recipient(s) only. It shall not attach any liability on the originator or HCL or its

affiliates. Any views or opinions presented in this email are solely those of the author and

may not necessarily reflect the opinions of HCL or its affiliates. Any form of reproduction,

dissemination, copying, disclosure, modification, distribution and / or publication of this

message without the prior written consent of the author of this e-mail is strictly

prohibited. If you have received this email in error please delete it and notify the sender

immediately. Before opening any mail and attachments please check them for viruses and