Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bac4572

Browse files
committed
Fixed to understand new file format; and cosmetics.
1 parent 5d731fc commit bac4572

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

Demo/sgi/video/v2i.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
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+
*/
5+
16
#include <stdio.h>
27
#include <gl/image.h>
38

49
long bm[1280];
510
short rb[1280], gb[1280], bb[1280];
6-
long h, w;
11+
long w, h, pf;
712

813
#define R(comp) ((comp) & 0xff)
914
#define G(comp) (((comp)>>8) & 0xff)
@@ -20,7 +25,7 @@ main(argc, argv)
2025

2126
if( argc != 3 && argc != 4) {
2227
fprintf(stderr, "Usage: v2i videofile imgfile [planemask]\n");
23-
exit(1);
28+
exit(2);
2429
}
2530
if ( argc == 4)
2631
pmask = atoi(argv[3]);
@@ -30,12 +35,23 @@ main(argc, argv)
3035
perror(argv[1]);
3136
exit(1);
3237
}
33-
gets(lbuf);
34-
if ( sscanf(lbuf, "(%d,%d)", &w, &h) != 2) {
38+
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) {
3551
fprintf(stderr, "%s: bad size spec: %s\n", argv[0], lbuf);
3652
exit(1);
3753
}
38-
gets(lbuf); /* Skip time info */
54+
fgets(lbuf, sizeof lbuf, stdin); /* Skip time info */
3955
if ( w > 1280 ) {
4056
fprintf(stderr, "%s: Sorry, too wide\n", argv[0]);
4157
exit(1);

0 commit comments

Comments
 (0)