Don't reference removed files in Makefile
[python/dscho.git] / Demo / sgi / video / v2i.c
blob5f8f3b5dec3c25f8338a607259eca3593c833e01
1 /* Convert the first image of a CMIF video movie file to SGI .rgb format.
2 usage: v2i videofile imagefile [planemask]
3 link with -limage
4 */
6 #include <stdio.h>
7 #include <gl/image.h>
9 long bm[1280];
10 short rb[1280], gb[1280], bb[1280];
11 long w, h, pf;
13 #define R(comp) ((comp) & 0xff)
14 #define G(comp) (((comp)>>8) & 0xff)
15 #define B(comp) (((comp)>>16) & 0xff)
17 main(argc, argv)
18 char **argv;
20 char lbuf[100];
21 int x, y;
22 int i;
23 IMAGE * of;
24 int pmask;
26 if( argc != 3 && argc != 4) {
27 fprintf(stderr, "Usage: v2i videofile imgfile [planemask]\n");
28 exit(2);
30 if ( argc == 4)
31 pmask = atoi(argv[3]);
32 else
33 pmask = 7;
34 if ( freopen(argv[1], "r", stdin) == NULL ) {
35 perror(argv[1]);
36 exit(1);
38 if (fgets(lbuf, sizeof lbuf, stdin) == NULL) {
39 fprintf(stderr, "Immediate EOF\n");
40 exit(1);
42 if (strncmp(lbuf, "CMIF", 4) == 0) {
43 /* Skip optional header line */
44 if (fgets(lbuf, sizeof lbuf, stdin) == NULL) {
45 fprintf(stderr, "Immediate EOF after header\n");
46 exit(1);
49 pf = 2; /* Default */
50 if ( sscanf(lbuf, "(%d,%d,%d)", &w, &h, &pf) < 2) {
51 fprintf(stderr, "%s: bad size spec: %s\n", argv[0], lbuf);
52 exit(1);
54 fgets(lbuf, sizeof lbuf, stdin); /* Skip time info */
55 if ( w > 1280 ) {
56 fprintf(stderr, "%s: Sorry, too wide\n", argv[0]);
57 exit(1);
59 if ( (of=iopen(argv[2], "w", RLE(1), 3, w, h, 3)) == 0) {
60 perror(argv[2]);
61 exit(1);
63 for( y=0; y<h; y++) {
64 if( fread(bm, sizeof(long), w, stdin) != w) {
65 fprintf(stderr, "%s: short read\n", argv[0]);
66 exit(1);
68 for( x=0; x<w; x++) {
69 if ( pmask & 1) rb[x] = R(bm[x]);
70 if ( pmask & 2) gb[x] = G(bm[x]);
71 if ( pmask & 4) bb[x] = B(bm[x]);
73 putrow(of, rb, y, 0);
74 putrow(of, gb, y, 1);
75 putrow(of, bb, y, 2);
77 iclose(of);
78 exit(0);