-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgetvab.c
98 lines (83 loc) · 1.64 KB
/
getvab.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/time.h>
typedef unsigned short ui16;
int vflag;
void
usage (void)
{
fprintf (stderr, "usage: getvab filename\n");
exit (1);
}
int
PCX_D (void *src_raw,void *dest_raw,unsigned src_size)
{
char *src = src_raw;
char *dest = dest_raw;
char num;
char *orig_dest = dest;
do {
if ((*src&0xc0)==0xc0) {
num=*(src++)&0x3f; src_size--;
while ((num--)>0) {*(dest++)=*src;}
src++;src_size--;
} else {
(*dest++)=*(src++);src_size--;
};
} while(src_size);
return (dest - orig_dest);
}
unsigned char cbuf[1000 * 1000];
unsigned char pixels [1000 * 1000];
int
main (int argc, char **argv)
{
int c;
char *filename;
FILE *f;
FILE *outf;
int i;
int pixel;
unsigned char *up;
int plr;
char outname[1000];
while ((c = getopt (argc, argv, "")) != EOF) {
switch (c) {
default:
usage ();
}
}
if (argc - optind != 1)
usage ();
filename = argv[optind];
if ((f = fopen (filename, "rb")) == NULL) {
fprintf (stderr, "can't open %s\n", filename);
exit (1);
}
struct bImg {
unsigned char pal[768];
ui16 fSize;
} M;
for (plr = 0; plr < 2; plr++) {
fread (&M, 1, sizeof M, f);
fread (&cbuf, M.fSize, 1, f);
PCX_D (cbuf, pixels, M.fSize);
sprintf (outname, "vab%d.ppm", plr);
outf = fopen (outname, "wb");
fprintf (outf, "P6\n320 200\n255\n");
for (i = 0; i < 320*200; i++) {
pixel = pixels[i];
up = &M.pal[pixel * 3];
putc (*up++*4, outf);
putc (*up++*4, outf);
putc (*up++*4, outf);
}
fclose (outf);
}
return (0);
}