PDA

View Full Version : Trouble using a type def from tifflib library



jstippey
18th January 2011, 14:40
I am using tifflib library in my QT code. I have linked the library into my project file and am able to call up methods from the library. However, the tifflib library defines a typedef void* tdata_t
to promote portability. When I read a line from the tiff file it creates a buffer of tdata_t data. This corresponds to the actual pixel data that I want to retrieve from the image. The problem I am having is that I have been unable to cast this data as uint16 (the picture is a 16bit image).
Right now I am trying to hardcode a specific image file to get it to work



void Form1::loadImageFiles()
{
TIFF * tif = TIFFOpen("myimagefile", "r");

if(tif)
{
uint32 imagelength;
tdata_t buf;
uint32 row;

TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &imagelength);
buf = _TIFFmalloc(TIFFScanlineSize(tif));
row = 0;
TIFFReadScanline(tif, buf, row);
}


now here is where I have tried a couple of approaches.

1)I have tried casting as a QVariant and then converting to a Uint

2) created a pointer to the address of the buffer and then tried to casting to Uint, then I created a QVariant of the address and tried casting to uint16

3)Tried to create a QPTRList <tdata_t> that contained uint16

without success. I wanted to ask how you guys would handle this?

Thank you for your help,

high_flyer
18th January 2011, 15:08
Does this work?:


unsigned short *pBuff = (unsigned short*)buf;

jstippey
18th January 2011, 16:05
Thank you, I believe that works.