2013.10.08 10:01 "[Tiff] Problem with reading tiff exported from GDAL in C", by Josef Olah

2013.10.08 10:01 "[Tiff] Problem with reading tiff exported from GDAL in C", by Josef Olah

Hello,

I'm using libtiff library in my diploma thesis, but I encountered a problem, when I wanted to read image data in C language.

I have tiff image exported from GDAL:

https://www.dropbox.com/s/r6p1j06gg7a1vh2/BK4_10_rad_Export_line_2.tif

(histogram stretch is needed for good view (e.g. using QGIS))

which is composed of three channels (RGB). Original GDAL data file was composed of 65 channels, but I GDALRasterIO-ed it into RGB.

Now I'd like to read this tiff file using methods from libtiff webpage (http://www.remotesensing.org/libtiff/libtiff.html#tiffrgbaimage),

but when I'm using either the first or the second method (i.e. TIFFReadRGBAImage or TIFFRGBAImageBegin/TIFFRGBAImageGet/TIFFRGBAImageEnd)

I'm still facing the same problem during debugging in VS2012

(Unhandled exception at 0x6FDB01C0 (libtiff3.dll) in ConsoleApplication1.exe: 0xC0000005: Access violation reading location 0x0105C001.).

Here is part of my C code:

TIFF* tif_load;

uint32 w, h;

size_t npixels;

uint32* raster;

tif_load = TIFFOpen("C:/./BK4_10_rad_Export_line_2.tif", "r");

TIFFGetField(tif_load, TIFFTAG_IMAGEWIDTH, &w);

TIFFGetField(tif_load, TIFFTAG_IMAGELENGTH, &h);

npixels = w * h;

raster = (uint32*) _TIFFmalloc(npixels*sizeof(uint32));

TIFFReadRGBAImage(tif_load, w, h, raster, 0);

//working with raster

_TIFFfree(raster);

TIFFClose(tif_load);

I really don't know where is that issue, so I hope someone will help me.

Thank you in advance and sorry for my English.

Best regards, Josef Olah