#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <tiffio.h>
extern "C" {
int from_tif_ (char *path,char IN[2048*2048*2],int *NBPP,int *PNGX, int *PNGY) {
int i, j;
// char sig_buf [SIG_CHECK_SIZE];
TIFF *image;
tsize_t stripSize;
int bit_depth, color_type, interlace_type,rowbytes;
unsigned char **row_pointers;
char *path_tmp;
uint16 bps,nsamples;
uint width,length;
int stripMax,stripCount;
unsigned long imageOffset,result,bufferSize;
char *buffer;
uint32* raster;
unsigned long cpt,r,g,b,a;
uint16 *array;
path_tmp=strtok(path,"\\");
// Open the TIFF image
if((image = TIFFOpen(path_tmp, "r")) == NULL){
fprintf(stderr, "Could not open incoming image\n");
exit(42);
}
else
printf("opened %s\n",path_tmp);
if((TIFFGetField(image, TIFFTAG_BITSPERSAMPLE, &bps) == 0)){
fprintf(stderr, "Either undefined or unsupported number of bits per sample %d\n",bps);
exit(42);
}
else
printf("bit per pixel: %d\n",bps);
TIFFGetField(image, TIFFTAG_SAMPLESPERPIXEL, &nsamples);
printf("samplesperpixels %d\n",nsamples);
*NBPP=bps;
if(TIFFGetField(image, TIFFTAG_IMAGEWIDTH, &width) == 0){
fprintf(stderr, "Image does not define its width\n");
exit(42);
}
if(TIFFGetField(image, TIFFTAG_IMAGELENGTH, &length) == 0){
fprintf(stderr, "Image does not define its length\n");
exit(42);
}
*PNGX=width;
*PNGY=length;
printf("image size %d x %d x %d\n",*PNGX,*PNGY,*NBPP);
uint32 linesize = TIFFScanlineSize(image);
printf("linesize is %d\n",linesize);
//char *buf = (char*)malloc(linesize * length);
for (i = 0; i < length; i++)
TIFFReadScanline(image, &IN[i * linesize], i, 0);
TIFFClose(image);
uint32 total,totalTMP;
uint32 cpt2=0;
uint16 min;
uint16 max;
min=65000;
max=0;
total=0;
totalTMP=0;
uint16 cur;
for(i=0;i<length;i++)
{
for(j=0;j<width;j++)
{cur=((uint16 *)IN)[j+i*width];
if(cur>max)
max=cur;
if(cur<min)
min=cur;
total+=cur;
}
totalTMP+=total/width;
total=0;
}
printf(" %d %d %f \n",min,max,(float)totalTMP/length);
}
}