0

So I have this program, which is not complete yet. My images will be either 8 or 16bits. How do I assign whatever value coming out of buf to buffer array? Right now, the printf right after buf doesn't work cos it says buf is of type void*... I have no idea how to deal with that.

void read_tiff(image_file_name,buffer)
      char   image_file_name[];
      short **buffer;
{
    int i,j;
    tsize_t scanline;
    tdata_t buf;
uint32 width;
uint32 height;
TIFF *tif = TIFFOpen(image_file_name,"r");

if(tif){
TIFFGetField(tif,TIFFTAG_IMAGEWIDTH, &width);
TIFFGetField(tif,TIFFTAG_IMAGELENGTH, &height);

buf = _TIFFmalloc(TIFFScanlineSize(tif));


printf("width height %d %d\n",width,height);
for(i=0;i<height;i++){
    TIFFReadScanline(tif,buf,i);
    printf("%d ",buf[j]);
}   

_TIFFfree(buf);
TIFFClose(tif);
}
else{
    printf("ERROR- cannot open image %s\n",image_file_name);
}
} 
nineties
  • 423
  • 1
  • 7
  • 17

1 Answers1

1

You cannot dereference a void *, you need to cast it before.

For example, if you cast it to a byte:

printf("%d ", ((unsigned char *) buf)[j]);
ouah
  • 142,963
  • 15
  • 272
  • 331