getvab.c

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <unistd.h>
00004 #include <fcntl.h>
00005 #include <errno.h>
00006 #include <string.h>
00007 #include <sys/ioctl.h>
00008 #include <sys/time.h>
00009 
00010 typedef unsigned short ui16;
00011 
00012 int vflag;
00013 
00014 void
00015 usage (void)
00016 {
00017     fprintf (stderr, "usage: getvab filename\n");
00018     exit (1);
00019 }
00020 
00021 int
00022 PCX_D (void *src_raw,void *dest_raw,unsigned src_size)
00023 {
00024   char *src = src_raw;
00025   char *dest = dest_raw;
00026   char num;
00027   char *orig_dest = dest;
00028   do {
00029     if ((*src&0xc0)==0xc0) {
00030       num=*(src++)&0x3f; src_size--;
00031       while ((num--)>0) {*(dest++)=*src;}
00032       src++;src_size--;
00033     } else {
00034       (*dest++)=*(src++);src_size--;
00035     };
00036   }  while(src_size);
00037   return (dest - orig_dest);
00038 }
00039 
00040 unsigned char cbuf[1000 * 1000];
00041 unsigned char pixels [1000 * 1000];
00042 
00043 int
00044 main (int argc, char **argv)
00045 {
00046     int c;
00047     char *filename;
00048     FILE *f;
00049     FILE *outf;
00050     int i;
00051     int pixel;
00052     unsigned char *up;
00053     int plr;
00054     char outname[1000];
00055 
00056     while ((c = getopt (argc, argv, "")) != EOF) {
00057         switch (c) {
00058         default:
00059             usage ();
00060         }
00061     }
00062 
00063     if (argc - optind != 1)
00064         usage ();
00065 
00066     filename = argv[optind];
00067 
00068     if ((f = fopen (filename, "rb")) == NULL) {
00069         fprintf (stderr, "can't open %s\n", filename);
00070         exit (1);
00071     }
00072 
00073     struct bImg {
00074         unsigned char pal[768];
00075         ui16 fSize;
00076     } M;
00077     
00078     for (plr = 0; plr < 2; plr++) {
00079         fread (&M, 1, sizeof M, f);
00080         fread (&cbuf, M.fSize, 1, f);
00081         PCX_D (cbuf, pixels, M.fSize);
00082 
00083         sprintf (outname, "vab%d.ppm", plr);
00084         outf = fopen (outname, "wb");
00085         fprintf (outf, "P6\n320 200\n255\n");
00086         for (i = 0; i < 320*200; i++) {
00087             pixel = pixels[i];
00088             up = &M.pal[pixel * 3];
00089             putc (*up++*4, outf);
00090             putc (*up++*4, outf);
00091             putc (*up++*4, outf);
00092         }
00093         fclose (outf);
00094     }
00095 
00096     return (0);
00097 }
00098 

Generated on Fri Sep 28 00:35:45 2007 for raceintospace by  doxygen 1.5.3