[go: up one dir, main page]

Menu

[r34]: / common / read-tif.cpp  Maximize  Restore  History

Download this file

97 lines (80 with data), 2.1 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#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);
}
}