blob: 5f8f3b5dec3c25f8338a607259eca3593c833e01 [file] [log] [blame]
Guido van Rossumbac45721991-11-04 15:54:36 +00001/* 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*/
5
Guido van Rossume4bddea1991-10-30 11:52:48 +00006#include <stdio.h>
7#include <gl/image.h>
8
9long bm[1280];
10short rb[1280], gb[1280], bb[1280];
Guido van Rossumbac45721991-11-04 15:54:36 +000011long w, h, pf;
Guido van Rossume4bddea1991-10-30 11:52:48 +000012
13#define R(comp) ((comp) & 0xff)
14#define G(comp) (((comp)>>8) & 0xff)
15#define B(comp) (((comp)>>16) & 0xff)
16
17main(argc, argv)
18 char **argv;
19{
20 char lbuf[100];
21 int x, y;
22 int i;
23 IMAGE * of;
24 int pmask;
25
26 if( argc != 3 && argc != 4) {
27 fprintf(stderr, "Usage: v2i videofile imgfile [planemask]\n");
Guido van Rossumbac45721991-11-04 15:54:36 +000028 exit(2);
Guido van Rossume4bddea1991-10-30 11:52:48 +000029 }
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);
37 }
Guido van Rossumbac45721991-11-04 15:54:36 +000038 if (fgets(lbuf, sizeof lbuf, stdin) == NULL) {
39 fprintf(stderr, "Immediate EOF\n");
40 exit(1);
41 }
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);
47 }
48 }
49 pf = 2; /* Default */
50 if ( sscanf(lbuf, "(%d,%d,%d)", &w, &h, &pf) < 2) {
Guido van Rossume4bddea1991-10-30 11:52:48 +000051 fprintf(stderr, "%s: bad size spec: %s\n", argv[0], lbuf);
52 exit(1);
53 }
Guido van Rossumbac45721991-11-04 15:54:36 +000054 fgets(lbuf, sizeof lbuf, stdin); /* Skip time info */
Guido van Rossume4bddea1991-10-30 11:52:48 +000055 if ( w > 1280 ) {
56 fprintf(stderr, "%s: Sorry, too wide\n", argv[0]);
57 exit(1);
58 }
59 if ( (of=iopen(argv[2], "w", RLE(1), 3, w, h, 3)) == 0) {
60 perror(argv[2]);
61 exit(1);
62 }
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);
67 }
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]);
72 }
73 putrow(of, rb, y, 0);
74 putrow(of, gb, y, 1);
75 putrow(of, bb, y, 2);
76 }
77 iclose(of);
78 exit(0);
79}