home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / makelogo.zip / maklog2b.zip / makelog2.c < prev    next >
C/C++ Source or Header  |  1995-05-13  |  6KB  |  145 lines

  1. /*
  2.  *      MAKELOG2
  3.  *
  4.  *      by Marcus Gröber April/May '95
  5.  *
  6.  *      Converts VRAMx.DAT output files from BMP2LOGO to Warp boot logo.
  7.  *
  8.  *      Compile: gcc -Wl,-S -Zomf -Zsys -o makelog2.exe makelog2.c
  9.  *
  10.  *        -Wl,-S        strips debugging info, reducing EXE file size by 8K
  11.  *        -Zomf -Zsys   creates a standalone OS/2 EXE not requiring emx.dll.
  12.  */
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16.  
  17. int main(void)
  18. {
  19.         struct {
  20.           long ofs;
  21.           long size;
  22.         } logo_header[4];
  23.         FILE *fout,*fin;
  24.         char fname[]="VRAMx.DAT";
  25.         int plane,i,j,b,by,cnt,bufc,line[16],buf[64];
  26.         long adr;
  27.  
  28.         puts("\nMAKELOG2 -=- by Marcus Gröber May '95\n"
  29.                "Converts VRAMx.DAT output files from BMP2LOGO to Warp boot logo.\n");
  30.         fout = fopen("VRAM.DAT","wb");  /* open target file */
  31.         if(!fout) {
  32.           puts("Error opening output file VRAM.DAT.");
  33.           return 1;
  34.         }
  35.         fwrite(logo_header,sizeof(logo_header),1,fout);
  36.                                         /* skip over header */
  37.         for(plane=0; plane<4; plane++) {/* process four bitplanes */
  38.           logo_header[plane].ofs=ftell(fout);
  39.                                         /* starting offset of bitplane */
  40.           fname[4]=plane+'0';
  41.           printf("%s...\n",fname);
  42.           fin=fopen(fname,"rb");
  43.           if(!fin) {
  44.             puts("Error opening input file.");
  45.             fclose(fout);
  46.             return 2;
  47.           }
  48.           by=-1;
  49.           cnt=0;
  50.           bufc=0;
  51.           for(i=0;i<640*480/2/4;i++)
  52.           {
  53.             if((i%16)==0)
  54.               fscanf(fin,"%%%%%08lx %02x%02x %02x%02x %02x%02x %02x%02x "
  55.                          "%02x%02x %02x%02x %02x%02x %02x%02x\n",
  56.               &adr,&line[1],&line[0],&line[3], &line[2], &line[5], &line[4], &line[7], &line[6],
  57.                    &line[9],&line[8],&line[11],&line[10],&line[13],&line[12],&line[15],&line[14]);
  58.  
  59.             if(i<640*400/2/4)
  60.               b=line[i%16];             /* current byte */
  61.             else
  62.               b=0;                      /* zero out lines beyond 400 */
  63.  
  64.             /*
  65.              * The following code compresses the "stream" of bytes in b
  66.              * using an RLE based compression method. Coding is basically
  67.              * as follows:
  68.              *
  69.              *   - A 00h byte indicates a run of repeated bytes; it is
  70.              *     followed by two bytes giving the number of repetions and
  71.              *     the byte to be repeated.
  72.              *   - Any other value announces a group of bytes to be copied
  73.              *     "as is". If the two low-order bits of this value are 0,
  74.              *     the six high order bits give the number of bytes to be
  75.              *     copied. I don't know what the meaning of other
  76.              *     combinations of bit 0/1 could be...
  77.              *   - The end of the data is marked by a sequence of two 00h
  78.              *     bytes.
  79.              */
  80.             if(b==by && cnt<255)
  81.               cnt++;                    /* count up to 255 identical bytes */
  82.             else {
  83.               if(cnt>3 || bufc+cnt>63)  /* end sequence of unrepeated bytes? */
  84.               {                         
  85.                 if(cnt<=3)              /* will not generate repeat... */
  86.                   for(j=0;cnt && bufc<63;j++,cnt--)
  87.                                         /* stuff as many as possible... */
  88.                     buf[bufc++]=by;     /* ...to end of current sequence */
  89.                 if(bufc)                /* flush unrepeated data */
  90.                 {
  91.                   fputc(bufc*4,fout);
  92.                   for(j=0; j<bufc; j++)
  93.                     fputc(buf[j],fout);
  94.                   bufc=0;               /* buffer has been flushed */
  95.                 }
  96.               }
  97.               if(cnt>3)
  98.               {
  99.                 fputc(0x00,fout);       /* code "true" repetition */
  100.                 fputc(cnt,fout);
  101.                 fputc(by,fout);
  102.               }
  103.               else
  104.               {
  105.                 for(j=0; cnt; j++,cnt--)/* only few repeated bytes:... */
  106.                   buf[bufc++]=by;       /* ...add to current sequence */
  107.               }
  108.               by=b;                     /* another byte */
  109.               cnt=1;                    /* first occurance */
  110.             }
  111.  
  112.           }
  113.  
  114.           if(cnt<3 && bufc+cnt<=63)
  115.           {
  116.             for(j=0; j<cnt; j++)        /* only few repeated bytes:... */
  117.               buf[bufc++]=by;           /* ...add to current sequence */
  118.             cnt=0;
  119.           }
  120.           if(bufc)                      /* flush unrepeated data */
  121.           {
  122.             fputc(bufc,fout);
  123.             for(j=0; j<bufc; j++)
  124.               fputc(buf[j],fout);
  125.           }
  126.           if(cnt) {                     /* still repeated bytes left? */
  127.             fputc(0x00,fout);           /* flush one-char buffer */
  128.             fputc(cnt,fout);
  129.             fputc(by,fout);
  130.           }
  131.           fputc(0x00,fout);             /* end of file */
  132.           fputc(0x00,fout);
  133.           fclose(fin);
  134.           logo_header[plane].size=ftell(fout)-logo_header[plane].ofs;
  135.                                         /* size of bitplane */
  136.         }
  137.  
  138.         fseek(fout,0,SEEK_SET);         /* seek to beginning of file */
  139.         fwrite(logo_header,sizeof(logo_header),1,fout);
  140.                                         /* finalize header */
  141.         fclose(fout);
  142.         puts("Created VRAM.DAT - replace \\OS2LOGO to change boot logo.");
  143.         return 0;                       /* no errors were detected */
  144. }
  145.