forked from Triften/hp4600
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_BGR_150.c
67 lines (59 loc) · 1.71 KB
/
get_BGR_150.c
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
//trying to get detailed calibration values the whole rotated scan is divided into 1-pixel vertical lines
//the calculations come from previous code for RGB values, so the B and R variables are interchanged !!!
//this is corrected only in the output !!!!!
//for each line the average RGB values are calculated, this gives 3x1274 values
//the description below is there only to describe the scan properties
//file size is 1274 x 1760 pixels, 3822+2 bytes per line
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char **argv){
FILE * infile;
unsigned char inbuf[3824];
float rval[1274];
float gval[1274];
float bval[1274];
int x, i, j, m;
unsigned int rsum[1274];
unsigned int gsum[1274];
unsigned int bsum[1274];
for(x = 0; x < 1274; x++){
rval[x] = 0.0;
gval[x] = 0.0;
bval[x] = 0.0;
rsum[x] = 0;
gsum[x] = 0;
bsum[x] = 0;
}
int linenum = 0;
if (argc!=2) {
printf("\n Usage: %s inputfile\n\n", argv[0]);
exit(1);
}
if (!(infile = fopen(argv[1], "r")))
{
printf("\nerror in the command line\nsource file does not exist\n\n");
exit(1);
}
//reversed lines counting
for(linenum = 5; linenum < 1755; linenum++){
fseek(infile, (linenum*3824+54), SEEK_SET);
fread(inbuf, 3824, 1, infile);
for(i = 0; i < 3822; i+=3){
x = i / 3;
rsum[x] += (unsigned int)inbuf[i];
gsum[x] += (unsigned int)inbuf[i+1];
bsum[x] += (unsigned int)inbuf[i+2];
}
}
for(j = 0; j < 1274; j++){
rval[j] = (float) rsum[j] / 1750;
gval[j] = (float) gsum[j] / 1750;
bval[j] = (float) bsum[j] / 1750;
}
printf(" line bval gval rval\n");
for(j = 0; j < 1274; j++){
printf("%5d %5.1f %5.1f %5.1f\n", j, rval[j], gval[j], bval[j]);
}
pclose(infile);
}