#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#define HEIGHT	2160
#define WIDTH	4320

main (int argc, char *argv[]) {
	int x,y;
	char *file1,*file2,*output_file;
	FILE *f,*g,*out;
	short fline[WIDTH],gline[WIDTH],difference[WIDTH];
	short *pf,*pg,*pd;
	char scratch [2*WIDTH];

	if (argc < 3) {
		fprintf (stderr,"Usage: %s file1 file2\n",argv[0]);
		exit (0);
		}
	file1 = argv[1];
	file2 = argv[2];
	if (argc > 3) output_file = argv[3];
	else output_file = NULL;

	f = fopen (file1,"rb");
	g = fopen (file2,"rb");
	if (output_file) out = fopen (output_file,"wb");
	else out = stdout;

	for (y=0; y < HEIGHT; y++) {
		fread (scratch,sizeof(short),WIDTH,f);
		swab (scratch,(char *)fline,WIDTH*sizeof(short));

		fread (scratch,sizeof(short),WIDTH,g);
		swab (scratch,(char *)gline,WIDTH*sizeof(short));

		pf = fline;
		pg = gline;
		pd = (short *) scratch;

		for (x=0; x < WIDTH; x++) *pd++ = *pf++ - *pg++;

		swab (scratch,(char *)difference,WIDTH*sizeof(short));
		fwrite (difference,sizeof(short),WIDTH,out);
		}
	}
