Guido van Rossum | e4bddea | 1991-10-30 11:52:48 +0000 | [diff] [blame^] | 1 | #include <stdio.h> |
| 2 | #include <gl/image.h> |
| 3 | |
| 4 | long bm[1280]; |
| 5 | short rb[1280], gb[1280], bb[1280]; |
| 6 | long h, w; |
| 7 | |
| 8 | #define R(comp) ((comp) & 0xff) |
| 9 | #define G(comp) (((comp)>>8) & 0xff) |
| 10 | #define B(comp) (((comp)>>16) & 0xff) |
| 11 | |
| 12 | main(argc, argv) |
| 13 | char **argv; |
| 14 | { |
| 15 | char lbuf[100]; |
| 16 | int x, y; |
| 17 | int i; |
| 18 | IMAGE * of; |
| 19 | int pmask; |
| 20 | |
| 21 | if( argc != 3 && argc != 4) { |
| 22 | fprintf(stderr, "Usage: v2i videofile imgfile [planemask]\n"); |
| 23 | exit(1); |
| 24 | } |
| 25 | if ( argc == 4) |
| 26 | pmask = atoi(argv[3]); |
| 27 | else |
| 28 | pmask = 7; |
| 29 | if ( freopen(argv[1], "r", stdin) == NULL ) { |
| 30 | perror(argv[1]); |
| 31 | exit(1); |
| 32 | } |
| 33 | gets(lbuf); |
| 34 | if ( sscanf(lbuf, "(%d,%d)", &w, &h) != 2) { |
| 35 | fprintf(stderr, "%s: bad size spec: %s\n", argv[0], lbuf); |
| 36 | exit(1); |
| 37 | } |
| 38 | gets(lbuf); /* Skip time info */ |
| 39 | if ( w > 1280 ) { |
| 40 | fprintf(stderr, "%s: Sorry, too wide\n", argv[0]); |
| 41 | exit(1); |
| 42 | } |
| 43 | if ( (of=iopen(argv[2], "w", RLE(1), 3, w, h, 3)) == 0) { |
| 44 | perror(argv[2]); |
| 45 | exit(1); |
| 46 | } |
| 47 | for( y=0; y<h; y++) { |
| 48 | if( fread(bm, sizeof(long), w, stdin) != w) { |
| 49 | fprintf(stderr, "%s: short read\n", argv[0]); |
| 50 | exit(1); |
| 51 | } |
| 52 | for( x=0; x<w; x++) { |
| 53 | if ( pmask & 1) rb[x] = R(bm[x]); |
| 54 | if ( pmask & 2) gb[x] = G(bm[x]); |
| 55 | if ( pmask & 4) bb[x] = B(bm[x]); |
| 56 | } |
| 57 | putrow(of, rb, y, 0); |
| 58 | putrow(of, gb, y, 1); |
| 59 | putrow(of, bb, y, 2); |
| 60 | } |
| 61 | iclose(of); |
| 62 | exit(0); |
| 63 | } |