Added ref to Misc/NEWS file; added hint to run regen script on Linux.
[python/dscho.git] / Demo / sgi / video / i2v.c
blob21dfabe2b2d615b4160c2d9f905e5aeeee8b973a
1 /*
2 * i2v -- image-to-video.
3 * Convert an SGI image file to a format that is immediately usable
4 * by lrectwrite.
5 * The header of the file contains a description (in ASCII)
6 * padded to 8196 byte for fast access of the rest of the file.
8 * Based upon "showimg.c" by Paul Haeberli.
9 * --Guido van Rossum, CWI, Amsterdam
11 #include <stdio.h>
12 #include <gl/gl.h>
13 #include <gl/device.h>
14 #include <gl/image.h>
16 unsigned short rs[8192];
17 unsigned short gs[8192];
18 unsigned short bs[8192];
20 IMAGE *image;
21 int xsize, ysize, zsize;
22 FILE *fp;
24 char header[100];
25 char *progname = "i2v";
27 main(argc,argv)
28 int argc;
29 char **argv;
31 int y;
32 if (argc > 0) progname = argv[0];
33 if( argc != 3 ) {
34 fprintf(stderr, "usage: %s infile outfile\n", progname);
35 exit(2);
37 if( (image=iopen(argv[1],"r")) == NULL ) {
38 fprintf(stderr, "%s: can't open input file %s\n",progname, argv[1]);
39 exit(1);
41 xsize = image->xsize;
42 ysize = image->ysize;
43 zsize = image->zsize;
44 if ((fp = fopen(argv[2], "w")) == NULL) {
45 fprintf(stderr,"%s: can't open output file %s\n", progname, argv[2]);
46 exit(1);
48 fprintf(fp, "CMIF video 1.0\n");
49 fprintf(fp, "(%d, %d, %d)\n", xsize, ysize, 0);
50 fprintf(fp, "0, %ld\n", (long)xsize * (long)ysize * sizeof(long));
51 fflush(fp);
52 for(y = 0; y < ysize; y++) {
53 if(zsize<3) {
54 getrow(image, rs, y, 0);
55 writepacked(xsize, rs, rs, rs);
56 } else {
57 getrow(image, rs, y, 0);
58 getrow(image, gs, y, 1);
59 getrow(image, bs, y, 2);
60 writepacked(xsize, rs, gs, bs);
63 exit(0);
66 writepacked(n, rsptr, gsptr, bsptr)
67 int n;
68 short *rsptr, *gsptr, *bsptr;
70 long parray[8192];
71 long *pptr = parray;
72 int i = n;
73 while (--i >= 0) {
74 *pptr++ = *rsptr++ | (*gsptr++<<8) | (*bsptr++<<16);
76 if (fwrite((char *) parray, sizeof(long), n, fp) != n) {
77 perror("fwrite");
78 exit(1);