#include #include #include #include #define TRUE 1 #define FALSE 0 #define WHITE 220 #define BLACK 158 #define WmB 35 #define BOTH 3 #define VISIBLE 2 #define INFRARED 1 #define NOISELEVEL 90 static int syncing = TRUE; static int messages = TRUE; static int band = VISIBLE; /*****************************************************************************/ static int noisedetect (unsigned char *buf, int len) { int i, nc=0, average=0, av=0; average=buf[0]; for (nc=0, i=1; i10 && nc>len/4) return 1; return 0; } /*****************************************************************************/ /* static int syncpicIR (unsigned char *buf, int len) { int i; for (i=40; iBLACK || (buf[i-36]-buf[i-39])BLACK || (buf[i-30]-buf[i-34])BLACK || (buf[i-25]-buf[i-27])BLACK || (buf[i-20]-buf[i-23])BLACK || (buf[i-13]-buf[i-17])BLACK || (buf[i- 8]-buf[i-10])BLACK || (buf[i- 3]-buf[i- 6])BLACK || (buf[i- 3]-buf[i- 0])=16384) return 16384; if (messages) {fprintf (stderr,"Pokus o sync\n");} y = syncpicIR(&buf[y],16384-x); if (y<2800 || y>2960) return 16384; if (messages) {fprintf (stderr, "Synced x=%1i, y=%1i\n",x,y);} syncing=FALSE; return x+y; } /*****************************************************************************/ static void usage (void) { fprintf (stderr,"Usage:\n" " -k - invert picture (satellite pass South -> North)\n" " -r ROWS - number of rows (default taken from picture)\n" " -v|-i|-b - visible infrared or both bands (default visible)\n" " -n - noise detect off\n" " -s - syncing off\n" " -q - messages off\n"); exit (1); } /*****************************************************************************/ static void FlushPicture (unsigned char *picture, int cols, int rows, int invert) { int row, col; int cols2=cols+cols; unsigned char *picpos=picture; printf ("P5 %1i %1i 255\n",cols,rows); if (messages) {fprintf (stderr,"Picture %1ix%1i\n",cols,rows);} if (invert && band!=BOTH) { unsigned char b[1440]; picpos+=cols2*rows-1; if (band==VISIBLE) {picpos+=cols;} for (col=0; picpos>=picture; picpos--) { if (col=cols2) { fwrite (b,cols,1,stdout); col=0; } } } if (invert && band==BOTH) { unsigned char b[1440]; col=0; for (picpos+=cols*rows-1; picpos>=picture; picpos--) { b[col]=*picpos; if (++col>=cols) { fwrite (b,cols,1,stdout); col=0; } } } if (!invert && band!=BOTH) { if (band==INFRARED) {picpos+=cols;} for (row=0; row10) { return 1; } } if (++cline > 20) { cline=0; nline=0; } return 0; } /*****************************************************************************/ int main (int argc, char **argv) { int COLS = 1440; int COLS_HALF = COLS/2; int ROWS = 1800; int invert = FALSE; int ndetect = TRUE; int x=0, i=0, col=0, row=0, u=0, p; unsigned char *picture, *picpos, *bufpos; unsigned char buf[16384]; while ( (i=getopt (argc, argv, "r:vbinskq")) != EOF) { switch (i) { case 'r': ROWS=atol(optarg); break; case 'v': band=VISIBLE; break; case 'i': band=INFRARED; break; case 'b': band=BOTH; COLS_HALF=COLS; break; case 'n': ndetect=FALSE; break; case 's': syncing=FALSE; break; case 'k': invert=TRUE; break; case 'q': messages=FALSE; break; default: usage(); break; } } picture = (unsigned char *) malloc (COLS*(ROWS+1)); picpos = picture; /***********************/ while ( 0 < (p=read (0, buf, 2880)) ) { u+=2800; row++; if (!noisedetect(buf,p)) break; } if (p<=0) { fprintf (stderr,"There is no signal in the data!\n"); return 1; } if (messages) {fprintf (stderr,"Signal appeared, row=%1i (offset=%1i).\n",u/2801,u);} /***********************/ u=0, row=0; while ( 0 < (p=read (0, buf, 16384)) ) { for (i=syncpic(buf), bufpos=buf+i; i128) {i++; bufpos++;} if (i<13500 && row>200 && ndetect && noisedetectinpic(bufpos,720)) { if (messages) {fprintf (stderr,"Noise detected. Row=%1i\n",row);} goto TheEnd; } } if (row>=ROWS) { goto TheEnd; } } } } /***********************/ if (messages) {fprintf (stderr,"\nUnexpected end of file. Row=%1i\n",row);} TheEnd: FlushPicture (picture, COLS_HALF, row, invert); free (picture); return 0; }